Skip to content

Commit

Permalink
git-p4: fix P4 label import for unprocessed commits
Browse files Browse the repository at this point in the history
With --detect-labels enabled, git-p4 will try to create tags
using git fast-import by writing a "tag" clause to the
fast-import stream.

If the commit that the tag references has not yet actually
been processed by fast-import, then the tag can't be created
and git-p4 fails to import the P4 label.

Teach git-p4 to use fast-import "marks" when creating tags
which reference commits created during the current run of the
program.

Commits created before the current run are still referenced
in the old way using a normal git commit.

Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Luke Diamand authored and Junio C Hamano committed Aug 28, 2015
1 parent 9ab1cfe commit b43702a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2322,8 +2322,11 @@ def make_email(self, userid):
else:
return "%s <a@b>" % userid

# Stream a p4 tag
def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
""" Stream a p4 tag.
commit is either a git commit, or a fast-import mark, ":<p4commit>"
"""

if verbose:
print "writing tag %s for commit %s" % (labelName, commit)
gitStream.write("tag %s\n" % labelName)
Expand Down Expand Up @@ -2374,7 +2377,7 @@ def commit(self, details, files, branch, parent = ""):
self.clientSpecDirs.update_client_spec_path_cache(files)

self.gitStream.write("commit %s\n" % branch)
# gitStream.write("mark :%s\n" % details["change"])
self.gitStream.write("mark :%s\n" % details["change"])
self.committedChanges.add(int(details["change"]))
committer = ""
if author not in self.users:
Expand Down Expand Up @@ -2493,13 +2496,19 @@ def importP4Labels(self, stream, p4Labels):
if change.has_key('change'):
# find the corresponding git commit; take the oldest commit
changelist = int(change['change'])
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
if len(gitCommit) == 0:
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
else:
gitCommit = gitCommit.strip()
if changelist in self.committedChanges:
gitCommit = ":%d" % changelist # use a fast-import mark
commitFound = True
else:
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
if len(gitCommit) == 0:
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
else:
commitFound = True
gitCommit = gitCommit.strip()

if commitFound:
# Convert from p4 time format
try:
tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")
Expand Down
2 changes: 1 addition & 1 deletion t/t9811-git-p4-label-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ p4_head_revision() {
# has not been seen. The presence of a label on a commit
# we haven't seen should not cause git-p4 to fail. It should
# merely skip that label, and still import other labels.
test_expect_failure 'importing labels with missing revisions' '
test_expect_success 'importing labels with missing revisions' '
test_when_finished cleanup_git &&
(
rm -fr "$cli" "$git" &&
Expand Down

0 comments on commit b43702a

Please sign in to comment.