Skip to content

Commit b43702a

Browse files
luked99gitster
authored andcommitted
git-p4: fix P4 label import for unprocessed commits
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ab1cfe commit b43702a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

git-p4.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,8 +2322,11 @@ def make_email(self, userid):
23222322
else:
23232323
return "%s <a@b>" % userid
23242324

2325-
# Stream a p4 tag
23262325
def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
2326+
""" Stream a p4 tag.
2327+
commit is either a git commit, or a fast-import mark, ":<p4commit>"
2328+
"""
2329+
23272330
if verbose:
23282331
print "writing tag %s for commit %s" % (labelName, commit)
23292332
gitStream.write("tag %s\n" % labelName)
@@ -2374,7 +2377,7 @@ def commit(self, details, files, branch, parent = ""):
23742377
self.clientSpecDirs.update_client_spec_path_cache(files)
23752378

23762379
self.gitStream.write("commit %s\n" % branch)
2377-
# gitStream.write("mark :%s\n" % details["change"])
2380+
self.gitStream.write("mark :%s\n" % details["change"])
23782381
self.committedChanges.add(int(details["change"]))
23792382
committer = ""
23802383
if author not in self.users:
@@ -2493,13 +2496,19 @@ def importP4Labels(self, stream, p4Labels):
24932496
if change.has_key('change'):
24942497
# find the corresponding git commit; take the oldest commit
24952498
changelist = int(change['change'])
2496-
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
2497-
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
2498-
if len(gitCommit) == 0:
2499-
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
2500-
else:
2501-
gitCommit = gitCommit.strip()
2499+
if changelist in self.committedChanges:
2500+
gitCommit = ":%d" % changelist # use a fast-import mark
25022501
commitFound = True
2502+
else:
2503+
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
2504+
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
2505+
if len(gitCommit) == 0:
2506+
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
2507+
else:
2508+
commitFound = True
2509+
gitCommit = gitCommit.strip()
2510+
2511+
if commitFound:
25032512
# Convert from p4 time format
25042513
try:
25052514
tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")

t/t9811-git-p4-label-import.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ p4_head_revision() {
222222
# has not been seen. The presence of a label on a commit
223223
# we haven't seen should not cause git-p4 to fail. It should
224224
# merely skip that label, and still import other labels.
225-
test_expect_failure 'importing labels with missing revisions' '
225+
test_expect_success 'importing labels with missing revisions' '
226226
test_when_finished cleanup_git &&
227227
(
228228
rm -fr "$cli" "$git" &&

0 commit comments

Comments
 (0)