Jump to content


Find source changelist for a target changelist

Merge changelists

  • Please log in to reply
5 replies to this topic

#1 tanvirkazmi

tanvirkazmi

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 29 March 2017 - 09:29 AM

Hi,

I am doing a merge from one p4 branch to another. Suppose the source branch had 4 changelists outstanding to be merged to the destination branch, as shown by the p4 interchanges command between the branches.

Now, when I do the merge (p4 merge) and submit the merge, I get a new merged changelist. Using this changelist, I want to identify the exact set of source changelists which contributed towards creation of this destination changelist.

I am currently trying to do a
1. Do a "p4 describe -s" of the destination changelist to identify all impacted files,
2. Do a "p4 filelog" on each entry found in previous describe to locate the latest contributing branch file version (from source branch)
3. Finally, do a "p4 changes" on each file to get the source changelist number from the source stream

This is the one way I figured which can possibly work, but does not seem the most efficient, specially when dealing with post merge changelists which are very large.

Looking for better ways to achieve the same purpose. Thanks.

#2 P4Reg

P4Reg

    Advanced Member

  • Staff Moderators
  • 98 posts

Posted 29 March 2017 - 11:09 AM

You can use the -i flag when you run "p4 changes" on your destination change.

From the output of "p4 help changes":

"The -i flag also includes any changelists integrated into the specified files."

Does that give you what you want?

#3 tanvirkazmi

tanvirkazmi

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 29 March 2017 - 11:36 AM

I checked the -i option. It is giving me changelists which go beyond what was merged during the last merge. Taking the example below:

p4 changes -i //...@=4315

Change 4315 on 2017/03/29 by ... post merge CL
Change 4313 on 2017/03/29 by ... source branch CL
Change 4312 on 2017/03/29 by ... source branch CL
Change 4311 on 2017/03/29 by ... source branch CL
Change 4310 on 2017/03/29 by ... source branch CL
Change 4309 on 2017/03/29 by ... source branch CL
Change 4308 on 2017/03/29 by ... older change on files falling under @=4315
Change 4050 on 2017/02/08 by ... older change on files falling under @=4315
Change 4044 on 2017/02/08 by ... older change on files falling under @=4315
Change 684 on 2016/06/14 by ... older change on files falling under @=4315
Change 494 on 2016/04/26 by ... older change on files falling under @=4315
Change 493 on 2016/04/26 by ... older change on files falling under @=4315
Change 395 on 2016/04/24 by ... older change on files falling under @=4315

Before the merge, when I ran interchanges, I got the list of CLs 4309-4313 above. Which means, these are the exact CL's I need to identify post the merge. Running p4 changes -i goes back longer in time and seems to be basically giving me an CL which had impacted this file list, not necessarily the ones which contributed towards creation of the post-merge changelist.

#4 Robert Cowham

Robert Cowham

    Advanced Member

  • PCP
  • 269 posts
  • LocationLondon, UK

Posted 29 March 2017 - 12:35 PM

Yup - "changes -i" shows all changes anywhere in the history of any of the files (via integration records). Bit like following your DNA back through your ancestors to Adam and Eve :)

See https://www.perforce...ns-under-covers and the section "The history after the merge/integrate".

Perforce tracks merge history of individual files and individual revisions. Commands like interchanges are an approximation only of the history (e.g. consider case where you have only merged in 2 files from a changelist containing 10).

For each revision in the range shown you have to find the source changelist number (it is possible to integrate src#2,#5 into dest#3, meaning revisions 2,3,4,5 have been squashed into one revision on target. Each rev has a changelist obviously.

So your original algorithm is pretty close.

Regards
Robert
Co-Author of "Learning Perforce SCM", PACKT Publishing, 25 September 2013, ISBN 9781849687645

"It's wonderful to see a new book about Perforce, especially one written by Robert Cowham and Neal Firth. No one can teach Perforce better than these seasoned subject matter experts"
  • Laura Wingerd, author of Practical Perforce, former VP of Product Technology at Perforce

#5 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 764 posts

Posted 31 March 2017 - 07:38 AM

View Posttanvirkazmi, on 29 March 2017 - 09:29 AM, said:

1. Do a "p4 describe -s" of the destination changelist to identify all impacted files,
2. Do a "p4 filelog" on each entry found in previous describe to locate the latest contributing branch file version (from source branch)
3. Finally, do a "p4 changes" on each file to get the source changelist number from the source stream

I think you can pare the runtime down a good bit by starting with "p4 filelog @=CHANGE".  It might also be a little faster to do "files -a" on the ranges to get the change numbers rather than "p4 changes" (unless you need the other info that's in the changes output but not the files output).

#6 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 764 posts

Posted 31 March 2017 - 03:09 PM

Here we go, in one line:

p4 -F "[%how%@]%fromFile%%fromRev%" filelog @=CHANGE | sed "s/ignored@/from@/" | grep "from@" | sed "s/.*@//" | sed "s/^\([^#]*\)#\([^#]*\)$/\1#=\2/" | p4 -x - -F %change% files -a | sort | uniq

Hardest part is handling the fact that single-revision ranges get formatted as "#N" (which "p4 files" will then interpret as "#1,#N" rather than "#N,#N"), so there's some tricky sed munging in there to look for those and translate them to "#=N".





Also tagged with one or more of these keywords: Merge, changelists

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users