How to get before and after state from a IChange?
I have a IChange respectively a IChangeSetHandle object. Now I would like to see the file that is represented by this state, as well as the difference between the before and the after state.
But I don't know how to really get the file from a IChange object. Any hints? |
3 answers
Fetch using IVersionableManager or IScmItemService.
|
Hi, Tim
If some one rename the source file eg rename file1 to file2, there will be one "rename" change and shows file2 (moved from file1)
I want to get the file1 and file2 name to do some pre-condition, so I used the following code, but seems both change.beforeState() and change.afterState() return file2. Can you help to figure out?
IVersionableHandle versionableHandle = change.beforeState();
if (change.kind() == IChange.RENAME) {
versionableHandle = change.afterState();
}
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(
data.getDestWorkspace(), changeSet.getComponent());
IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);
IAncestorReport reports[] = scmService.configurationLocateAncestors(
configProvider, new IVersionableHandle[] {versionableHandle}, null, null);
String filename=toFullPath(item, reports[0].getNameItemPairs());
Comments 1
My guess is that you're using the destination workspace for the configuration provider. Since the change set hasn't been delivered yet, it won't have the renamed state. I don't know if this would be an issue but it looks like it could be a problem.
Jia Jia Li
commented Nov 13 '12, 10:07 a.m.
Thanks Tim.
So
1. I should use data.getSourceWorkspace, is that right?
2. It is sample code, I have tried afterState and beforeState to get path.
Is that what you mentioned IVersionableManager or IScmItemService?
|
Hi, Tim
You are right if I use data.getSourceWorkspace, the file name is the old file name. Thanks!
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(
data.getSourceWorkspace(), changeSet.getComponent());
|
Comments
Any progress for this question? S M, could you attach your solution?
Have you tried John's suggestion below? The IChange provides the before and after states that can be fetched with IVersionableManager or IScmItemService.