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

[PATCH] git-p4: speed up search for branch parent

From
Joachim Kuebart via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 28, 2021, 20:06 UTC
Message-ID
<pull.1013.git.git.1619640416533.gitgitgadget@gmail.com>
From: Joachim Kuebart <joachim.kuebart@gmail.com>

Previously, the code iterated through the parent branch commits and compared each one to the target tree using diff-tree.

This patch outputs the revision's tree hash along with the commit hash, thereby saving the diff-tree invocation. This results in a considerable speed-up, at least on Windows.

Signed-off-by: Joachim Kuebart <joachim.kuebart@gmail.com>
---
    git-p4: speed up search for branch parent
    
    Previously, the code iterated through the parent branch commits and
    compared each one to the target tree using diff-tree.
    
    This patch outputs the revision's tree hash along with the commit hash,
    thereby saving the diff-tree invocation. This results in a considerable
    speed-up, at least on Windows.
    
    Signed-off-by: Joachim Kuebart joachim.kuebart@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1013%2Fjkuebart%2Fp4-faster-parent-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1013/jkuebart/p4-faster-parent-v1
Pull-Request: https://github.com/git/git/pull/1013
 git-p4.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 09c9e93ac401..dbe94e6fb83b 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3600,19 +3600,19 @@ def importNewBranch(self, branch, maxChange):
         return True
 
     def searchParent(self, parent, branch, target):
-        parentFound = False
-        for blob in read_pipe_lines(["git", "rev-list", "--reverse",
+        for tree in read_pipe_lines(["git", "rev-parse",
+                                     "{}^{{tree}}".format(target)]):
+            targetTree = tree.strip()
+        for blob in read_pipe_lines(["git", "rev-list", "--format=%H %T",
                                      "--no-merges", parent]):
-            blob = blob.strip()
-            if len(read_pipe(["git", "diff-tree", blob, target])) == 0:
-                parentFound = True
+            if blob[:7] == "commit ":
+                continue
+            blob = blob.strip().split(" ")
+            if blob[1] == targetTree:
                 if self.verbose:
-                    print("Found parent of %s in commit %s" % (branch, blob))
-                break
-        if parentFound:
-            return blob
-        else:
-            return None
+                    print("Found parent of %s in commit %s" % (branch, blob[0]))
+                return blob[0]
+        return None
 
     def importChanges(self, changes, origin_revision=0):
         cnt = 1

base-commit: 311531c9de557d25ac087c1637818bd2aad6eb3a
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 10 in “git-p4: speed up search for branch parent”
  1. git-p4: speed up search for branch parentJoachim Kuebart via GitGitGadget, Apr 28, 2021
  2. Junio C HamanoApr 29, 2021
  3. Joachim KuebartApr 29, 2021
  4. Luke DiamandApr 29, 2021
  5. Junio C HamanoApr 29, 2021
  6. Joachim KuebartApr 29, 2021
  7. Joachim KuebartApr 29, 2021
  8. 0/2 git-p4: speed up search for branch parentJoachim Kuebart via GitGitGadget, May 5, 2021
  9. 1/2 git-p4: ensure complex branches are cloned correctlyJoachim Kuebart via GitGitGadget, May 5, 2021
  10. 2/2 git-p4: speed up search for branch parentJoachim Kuebart via GitGitGadget, May 5, 2021

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.