Created
June 14, 2012 23:34
-
-
Save dnozay/2933664 to your computer and use it in GitHub Desktop.
Renumber a perforce change via p4 python api.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# renumber a change. | |
# this will create a copy of the change form, without the files | |
# then reopen the files under the new change. | |
import argparse | |
import P4 | |
def renumber(changenum): | |
handle = P4.P4() | |
handle.connect() | |
try: | |
# copy the change spec and change attributes | |
newspec = handle.fetch_change(changenum) | |
files = newspec._files | |
newspec._change = 'new' | |
newspec._status = 'new' | |
newspec._files = [] | |
# get the text needed for input and create the change | |
newdesc = handle.format_change(newspec) | |
output = handle.save_change(newdesc) | |
newchangenum = output[0].split()[1] | |
print 'created changeset %(newchangenum)s from %(changenum)s.' % locals() | |
# reopen files in new change | |
handle.run_reopen('-c', newchangenum, *files) | |
print 'reopened files under changeset %(newchangenum)s.' % locals() | |
finally: | |
handle.disconnect() | |
def main(): | |
parser = argparse.ArgumentParser(description='create a new changelist and reopen associated files.') | |
parser.add_argument('changenum', help='the changelist number', type=int) | |
args = parser.parse_args() | |
renumber(args.changenum) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment