Reverse the changeset through API
Accepted answer
One other answer
A new change set can be created using:
IChangeSetHandle cset = wsConn.createChangeSet(component, progress.newChild(25));
Then you can deliver this change set to the stream to reverse the changes (the other option is to discard the change set from the stream, although if changes are build on top of that one, it might not always be possible (or easy) to discard that one change set).
Comments
Hi Evan,David,A follow up question:
What you said is true. If you replace with the start/end states of a change set, you will be wiping out changes that came after that change set. Since a change set represents a transition between two states, to really 'reverse' something, you want to merge in the semantic changes, or delta, between the end and start states; similar to trying to merge patch 'hunks' into your workspace. This is equivalent to trying to accept a change set with a gap, except in that case we're trying to apply the delta between a start state and an end state of a change set (whereas in this case you want the reverse of that).
The IWorkspaceConnection.revert() method you were using is used to 'revert' a versionable to an older state (and not merge in a semantic reversal). In our UI the user can click on a change set and click "Reverse" which will create a patch in the Pending Changes view where the user may have to manually merge in the patch.
Unfortunately there would be no way write an algorithm to reliably automate this since in some cases ambiguity/conflicts can arise which would require human intervention.
(see the next comment for an example)
Here are 3 change sets:
CS1 = Add methodB()
Content of afterstate:
public void methodA() {...}
public void methodB() {...}
public void methodC() {...}
CS2 = Modify methodB()
Content of afterstate:
public void methodA() {...}
public void methodB() {...some changes...}
public void methodC() {...}
CS3 = Delete methodB
Content of afterstate:
public void methodA() {...}
public void methodC() {...}
Now if you want to reverse CS2, it means undoing the changes in methodB. But the final configuration in this example is at CS3, in which methodB does not even exist. An algorithm would not know how to merge in the 'undoing of the changes in methodB'. Due to this conflict, a user would manually have to decide what to do. (Perhaps methodB was renamed or moved somewhere else... in that case, a user might be able to track that down and correctly apply the reversal)
Thanks David for the confirmation,Will decide next course of actions based on this info to conclude RTC extention for change reverse
Comments
Evan Hughes
JAZZ DEVELOPER Feb 13 '15, 11:22 a.m.What error is preventing your solution from working? Could you provide the stack trace and error message?
suresh k
Feb 17 '15, 1:09 a.m.Am sorry for delay,Getting below error when tried revert() on afterchange.Am not sure how beforeState() and afterState() works as struggling to find documentation for API Change class.
com.ibm.team.scm.common.CompletedChangeSetException
: Changes can only be checked into a new change set or a change set that is active in a workspace.
at com.ibm.team.scm.service.internal.utils.ChangeSetUtils$2.createException(
ChangeSetUtils.java:73)
t com.ibm.team.scm.service.internal.utils.IExceptionFactory$AbstractExceptionFactory.createException(
IExceptionFactory.java:35)
at com.ibm.team.scm.service.internal.operations.commit.CommitChangeTracker.determineTargetChangeSets(
CommitChangeTracker.java:182)
at com.ibm.team.scm.service.internal.operations.commit.CommitOperation.run(
CommitOperation.java:351)
at com.ibm.team.scm.service.internal.ScmService$22.run(
ScmService.java:1215)
suresh k
Feb 17 '15, 1:18 a.m.my comments to the points you outlined.
suresh k
Feb 17 '15, 4:34 a.m.Thanks Evan The fourth assumption is relevant to my issue here,Could reverse the change if changeset is active(new changeset check into repo workspace,but not delivered to stream),but I wanted to reverse closed changesets and it would be helpful if you guide me how to reopen the closed changeset or other better ways.
suresh k
Feb 18 '15, 2:06 a.m.Thanks David and Evan,Am all set .It's working now