It's all about the answers!

Ask a question

How to get before and after state from a IChange?

S M (8621923) | asked Aug 08 '12, 6:21 a.m.
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?

Jia Jia Li commented Nov 13 '12, 9:20 a.m.

 Any progress for this question? S M, could you attach your solution? 

Tim Mok commented 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.

3 answers

permanent link
Jia Jia Li (8057155192) | answered Nov 13 '12, 11:38 a.m.
 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());

permanent link
John Camelon (1.7k14) | answered Aug 10 '12, 6:30 a.m.
 Fetch using IVersionableManager or IScmItemService.  

permanent link
Jia Jia Li (8057155192) | answered Nov 13 '12, 9:40 a.m.
 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());

Tim Mok commented Nov 13 '12, 9:48 a.m.

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.

Jia Jia Li commented Nov 13 '12, 10:07 a.m.

Thanks Tim.

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?

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.