It's all about the answers!

Ask a question

Get last state history of an element

Fran Burgos (12311049) | asked Oct 26 '15, 10:55 a.m.
Iterating over a list of IChangeSets which have different IChanges. I would like to retrieve the last state of each element. For instance:

|- File.1 (Add)
|- File.2 (Add)

|- File.1 (Modify)
|- File.2 (Remove)

@return changes: [File.1 (from CS_2)]

for(IChangeSet changeSet : changeSets) {
    List<IChange> changes = (List<IChange>) changeSet.changes();
    for(IChange change : changes) {
// What else?

Accepted answer

permanent link
Chris McGee (50511117) | answered Oct 27 '15, 10:37 a.m.
Depending on where you get the change sets, it is possible for there to be more than one "latest" state. In your example above, it is pretty clear what the latest state is, however it gets more complicated if both change sets were created from the same state of the file. For example, if the change sets are retrieved from a work item then there is no guarantee that they build on each other.

Each IChange has a beforeState(), mergeStates() and afterState(). The afterState() will be the latest state in this context provided that all other IChanges for the versionable have afterState() that is in this IChange's beforeState() or in the mergeStates(). Otherwise, you don't know what that latest state is without additional information from a coherent history, such as from a stream or baseline.

I hope that this helps,
Fran Burgos selected this answer as the correct answer

Your answer

Register or to post your answer.