How to get before and after state from a IChange?
3 answers
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
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.
The other issue is you have to get the paths for both states but your code only uses the after state to get the path.
1 vote
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?
Comments
Jia Jia Li
Nov 13 '12, 9:20 a.m.Any progress for this question? S M, could you attach your solution?
Tim Mok
JAZZ DEVELOPER Nov 13 '12, 9:25 a.m.Have you tried John's suggestion below? The IChange provides the before and after states that can be fetched with IVersionableManager or IScmItemService.