Compare a change-set file to current version in stream
![]()
I want to compare a file contained in a change-set with the current version in the stream.
If I do following: IVersionable version = verManager.fetchCompleteState(versionHandle, monitor); IVersionableHandle previousVersion = null; for (Object co : changeSet.changes()) { IChange change = (IChange) co; if (change.afterState() != null && change.afterState().getStateId().equals(version.getStateId())) { previousVersion = change.beforeState(); break; } } I am able to compare the change-set's file to the one from which a user checked-out to create the change-set. That means, in the diff viewer it shows me all the changes (and merges) since that file was checked-out. I need to have differences only that were made as part of that change-set (excluding others' changes). Do I need to find the history of that file, and then find a version? How to do that ? |
Accepted answer
3 other answers
![]()
Your terminology isn't quite right as SCM doesn't have the concept of a check-out. When you create a change and check it in, it is based on the configuration of the component at that time. When you compare the before and after states of a change in a change set, it will only show the changes added in relation to the before state.
If you want to compare that after state to the stream, you can retrieve the state of the file in the stream by getting the IConfiguration from the stream's IWorkspaceConnection. Then you can use #fetchCompleteItem on the IConfiguration to get the stream's state.
|
![]()
By check-out, I meant the version on which the change-set was created.
Implemented on the lines you suggested: IVersionableHandle versionHandle = (IVersionableHandle) IFileItem.ITEM_TYPE.createItemHandle(UUID.valueOf(fileUuid), UUID.valueOf(stateUuid)); List listOfComponents = workspaceConnection.getComponentsContainingVersionable(versionHandle, monitor); IConfiguration config = workspaceConnection.configuration((IComponentHandle) listOfComponents.get(0)); return config.fetchCompleteItem(versionHandle, monitor); This way I can get the latest version from the workspace, which shows no diff in the diff viewer if the workspace is loaded with the current change-set. But here, it doesn't return me a previous state, just the latest in workspace. Is there a way to find previous state from IConfiguration? Comments If you want the find previous states, use IConfiguration#determineAncestorsInHistory(..). Although, you mentioned you want to compare against the current version in stream and your code is retrieving the configuration from the workspace instead of the stream unless that's how you named your stream's IWorkspaceConnection. Keep in mind that since the configuration is retrieved from the workspace, everything will be in relation to it. If you have two outgoing change sets in the workspace that modify the same file, the previous state will be in the older change set. ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
If you want to compare against some arbitrary file, here is some code that does this (from a change set created from zip files) https://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/ .
The IConfiguration#determineAncestorsInHistory(..) returns a list of AncestorReportImpl elements, when I dig it down, it returned me data in terms of INameItemPair. This list of INameItemPair shows the hierarchy of the file and its folder hierarchy.
The item in the INameItemPair is the IVersionableHandle of the file in history. Each item in the list is an ancestor to the item you queried in the #determineAncestorsInHistory(..) call. You can see in your screenshot that the field above the name is your file item. Tried getting item on the ancestorHierarchy, but it always returns the versionable with the same UUID that I have in the workspace/changeset.
What do you mean by the UUID? Are you saying it returns the same state UUID or the same item UUID? The item UUID for a versionable never changes once it is assigned. Yes, I meant that it returns the same state UUID.
Sorry, I led you down the wrong path with the ancestors call. That is the call to determine the path of the file.
No issues.
showing 5 of 9
show 4 more comments
|
![]()
I used IChange#mergeStates() which returns a list of IVersionableHandle. Michael Valenta suggested this API, thanks to him.
Then I simply retrieved the last element of mergeStates, and it works fine ! Thanks Tim for your continued support. |