git-p4: add P4 jobs to git commit message

When migrating from Perforce to git the information about P4 jobs
associated with P4 changelists is lost.

Having these jobs listed on messages of related git commits enables smooth
migration for projects that take advantage of e.g. JIRA integration
(which uses jobs on Perforce side and parses commit messages on git side).

The jobs are added to the message in the same format as is expected when
migrating in the reverse direction.

Signed-off-by: Jan Durovec <jan.durovec@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jan Durovec
2016-04-19 19:49:41 +00:00
committed by Junio C Hamano
parent a98772c63f
commit 26e6a27d69
3 changed files with 120 additions and 0 deletions

View File

@ -2320,6 +2320,15 @@ class P4Sync(Command, P4UserMap):
fnum = fnum + 1
return files
def extractJobsFromCommit(self, commit):
jobs = []
jnum = 0
while commit.has_key("job%s" % jnum):
job = commit["job%s" % jnum]
jobs.append(job)
jnum = jnum + 1
return jobs
def stripRepoPath(self, path, prefixes):
"""When streaming files, this is called to map a p4 depot path
to where it should go in git. The prefixes are either
@ -2665,6 +2674,7 @@ class P4Sync(Command, P4UserMap):
def commit(self, details, files, branch, parent = ""):
epoch = details["time"]
author = details["user"]
jobs = self.extractJobsFromCommit(details)
if self.verbose:
print('commit into {0}'.format(branch))
@ -2692,6 +2702,8 @@ class P4Sync(Command, P4UserMap):
self.gitStream.write("data <<EOT\n")
self.gitStream.write(details["desc"])
if len(jobs) > 0:
self.gitStream.write("\nJobs: %s" % (' '.join(jobs)))
self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s" %
(','.join(self.branchPrefixes), details["change"]))
if len(details['options']) > 0: