git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv1 3/3] git-p4: fix P4 label import for unprocessed commits

From
Luke Diamand <luke@diamand.org>
Date
Aug 27, 2015, 07:18 UTC
Message-ID
<1440659938-12952-4-git-send-email-luke@diamand.org>
In-Reply-To
<1440659938-12952-1-git-send-email-luke@diamand.org>

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>
---
 git-p4.py                      | 25 +++++++++++++++++--------
 t/t9811-git-p4-label-import.sh |  2 +-
 2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index a62611a..2018011 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2322,8 +2322,11 @@ class P4Sync(Command, P4UserMap):
         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)
@@ -2374,7 +2377,7 @@ class P4Sync(Command, P4UserMap):
             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:
@@ -2493,13 +2496,19 @@ class P4Sync(Command, P4UserMap):
             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")
diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh
index f7d5048..f994640 100755
--- a/t/t9811-git-p4-label-import.sh
+++ b/t/t9811-git-p4-label-import.sh
@@ -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" &&
-- 
2.5.0.rc0
Previous: Luke DiamandNext: Holl, Marcus
Message 5 of 6 in “[PATCHv1 0/3] git-p4: fixing import with labels when commit is not transferred”
  1. Luke DiamandAug 27, 2015
  2. 1/3 git-p4: failing test for ignoring invalid p4 labelsLuke Diamand, Aug 27, 2015
  3. Eric SunshineAug 27, 2015
  4. 2/3 git-p4: do not terminate creating tag for unknown commitLuke Diamand, Aug 27, 2015
  5. 3/3 git-p4: fix P4 label import for unprocessed commitsLuke Diamand, Aug 27, 2015
  6. Holl, MarcusSep 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.