Source/ported changesets and determining newest version of a file
We have source code that takes a collection of IChangeSet objects (obtained by comparing one stream or workspace with another, basically getting the outgoing list of changes...but not necessarily ALL outgoing changes, sometimes only a subset of them, e.g. ones that are linked to a particular work item or list of work items) and tries to determine which version of a part is the newest in that set. To date, we've always used the changeset last-modified timestamp to determine which change to a part is newest.
However, we have discovered a wrinkle whereby the "real" changeset was sourced from another one (getSourceChangeSet() returns non-null), and in these cases can sometimes have a newer timestamp than others with older timestamps (but which technically contain newer versions of the part).
So if we alter our code to check if getOriginalChangeSet() returns non-null, and if so use that changeset instead for timestamp comparisons, we seem to get what we expect. This method is documented to return the changeset itself when it was not sourced, or the ultimate original changeset if it's sourced by a source by a source...
A question on the safety of using this new logic:
Can the "real" changeset ever contain additional changes beyond the one it's sourced from? I've only seen cases so far where the source might have additional changes, but that case is fine (we would process the source changeset separately if it was also part of the outgoing history). It would only be if the "real" one had more changes in it, in which case we would have to figure out how to use the "real" timestamp for the additional parts (instead of the source's timestamp).
One answer
I'd like to start by pointing out one thing; when a change set was created due to 'gaps', or if it has 'source change sets' (per the API you mentioned), this is usually an indication of 'parallel streams' or 'branches' if you will. So the whole talk about which is the 'real' change set, or the 'latest' change set doesn't really make sense, as the answer might be relative to which stream you are talking about.
Ex: I do a fix in CS1 the 'main stream', but realize I need to backport that change set to a 'maintenance' stream, so I try to accept/deliver that change set to the 'maintenance stream', but it says I cannot due to gaps (as normally expected), so I use the Gap editor and hand-craft what I would consider a 'semantically equivalent' change set CS1Prime that is applicable to the 'maintenance stream' context.
It is possible for the CS1 and CS1Prime to contain different files in the change sets; ex: CS1 could have more files, or CS1Prime could have more files, and this could happen because their 'fixes' were applied to different streams, which may have had slightly different 'requirements' for applying the same semantic fix. Also the actual files in CS1 and CS1Prime could be at different states/versions (which is normally the case actually), and even the 'fix content' (i.e. the file diff) for a specific file may differ (i.e. it may have been required to do something slightly different in the maintenance stream to apply the same semantic fix that the one in the 'main stream did).
Comments
Ernest Crvich
Feb 05 '18, 3:03 p.m.