开发者

Perforce: How to find the original number of a change list

In perforce changelists get renumbered on submission. So for e.g. when the changelist was created it would be numb开发者_运维问答ered 777 , but on submission of changelist it would get renumbered to say 790.

My question is how do I get the new CL number (790) , if I know the old CL number 777 , or vice versa ?


If you really want the original changelist number, that can be retrieved from Perforce without having to embed the original changelist number in the description. You can use the -ztag command line option to get at it. And you can only get at it through the 'changes' command (as far as I know):

d:\sandbox>p4 submit -c 24510
Submitting change 24510.
Locking 1 files ...
edit //depot/testfile.txt#2
Change 24510 renamed change 24512 and submitted.

d:\sandbox>p4 -ztag changes -m1 //depot/testfile.txt
... change 24512
... time 1294249178
... user test.user
... client client-test.user
... status submitted
... oldChange 24510
... desc <enter description here>
<saved

As pointed out, it's probably not that useful. However, I did want to note that it's possible to get at it.


The only way I can think of is adding the original changelist number as part of the changelist description field. First, you'll need a script to store the original changelist number:

#!/bin/env perl
$id = $ARGV[0];
open (CHANGE_IN, "p4 change -o $id|");
open (CHANGE_OUT, "|p4 change -i $id");
while (<CHANGE_IN>)
{
    if (/^Description:/ and not /ORIGID/)
    {
        s/(^Description:)(.*)$/$1 ORIGID $id. $2/;
    }
    print CHANGE_OUT $_;
}
close (CHANGE_IN);
close (CHANGE_OUT);

Save this as origid.pl on the Perforce server with the executable bit set. Then setup a trigger with p4 triggers.

Triggers:
    add_origid change-submit //depot/... /usr/bin/origid.pl %change%


Version 2012.1 of Perforce introduced the -O (capital oh) argument to p4 describe, which allows you to query a changelist by its original number (before being renumbered by p4 submit).

I find this very helpful, since I often find myself keeping notes about a changeset before it is submitted, then forgetting to note what it was renumbered to on submission.

So if I have a note talking about change 12300, I can now see what it refers to by typing:

p4 describe -s -O 12300

and having Perforce tell me:

Change 12345 by me@myhost on 2013/10/31 00:00:00

    Fix that thing I wrote that note about

Affected files ...

    ... //Proj/MAIN/foo.c

The ztag method mentioned earlier can be used to find the old changelist number of a submitted change:

> p4 -ztag describe -s 12345 | grep oldChange
... oldChange 12300


Adding to Eric Miller's reply, because I can't comment (not enough points):

to just emit the 1 number

p4 -ztag describe $ORIG | sed -e 's/^\.\.\. oldChange //;t-ok;d;:-ok'

e.g.

OLD=$(p4 -ztag describe $ORIG | sed -e 's/^\.\.\. oldChange //;t-ok;d;:-ok')

or if you want to look up many numbers, this will output a map of new old on each line (may be useful with the "join" command). If there is no old commit, then it re-emits the new commit.

p4 -ztag describe 782546 782547 ... | sed -e '${x;p};s/^\.\.\. change //;t-keep;b-next;:-keep;x;/./p;g;G;s/\n/ /;x;d;:-next;s/^\.\.\. oldChange //;t-ok;d;:-ok;H;x;s/ .*\n/ /;x;d;'

I tried to avoid using GNU extensions to sed.


Unless you do something like Tim suggests the old change list number will be lost on submission.

Change list numbers are only temporary until you actually submit. So if you create a new change list (777 say) and then decide to delete it, the next change list you create will be 778.


It can be a bit more elegant if you use the P4 Python module.

i.e.

import P4
p4 = P4.P4()
p4.connect() # having a valid p4 workspace/connection is on you :)

c = p4.run_describe('969696') # describe a Submitted, renumbered changelist, i.e. 969696

old_pending_cl_number = c['oldChange'] # print out prior/pending CL# if this exists.

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜