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

[PATCH/RFC 1/2] git-p4: Search for parent commit on branch creation

From
Vitor Antunes <vitor.hda@gmail.com>
Date
Aug 19, 2011, 00:09 UTC
Message-ID
<1313712590-26876-2-git-send-email-vitor.hda@gmail.com>
In-Reply-To
<1313712590-26876-1-git-send-email-vitor.hda@gmail.com>

The new commit is applied sequentially to each blob of the parent branch. The first blob which results in a zero diff with the new commit is considered the parent commit. If none is found, then the commit is applied to the top of the parent branch. This algorithm requires a checkpoint and a time.sleep() to be able to use diff-tree, making it slower than what would be desirable. It also requires using --force argument of fast-import, leaving lots of trash commits when finished.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 contrib/fast-import/git-p4 |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index f622a38..0bced6d 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1671,7 +1671,25 @@ class P4Sync(Command, P4UserMap):
                             parent = self.initialParents[branch]
                             del self.initialParents[branch]
 
-                        self.commit(description, filesForCommit, branch, [branchPrefix], parent)
+                        parentFound = 0
+                        if len(parent) > 0:
+                            self.gitStream.write("checkpoint\n\n")
+                            time.sleep(0.1)
+                            for blob in read_pipe_lines("git rev-list --reverse --no-merges %s" % parent):
+                                blob = blob.strip()
+                                self.gitStream.write("reset %s\nfrom %s\n" % (branch, blob))
+                                self.commit(description, filesForCommit, branch, [branchPrefix], blob)
+                                self.gitStream.write("checkpoint\n\n")
+                                time.sleep(0.1)
+                                if len( read_pipe("git diff-tree %s %s" % (blob, branch)) ) == 0:
+                                    parentFound = 1
+                                    if self.verbose:
+                                        print "Found parent of %s in commit %s" % (branch, blob)
+                                    break
+                        if not parentFound:
+                            if self.verbose:
+                                print "Parent of %s not found. Committing into head of %s" % (branch, parent)
+                            self.commit(description, filesForCommit, branch, [branchPrefix], parent)
                 else:
                     files = self.extractFilesFromCommit(description)
                     self.commit(description, files, self.branch, self.depotPaths,
@@ -1948,7 +1966,7 @@ class P4Sync(Command, P4UserMap):
 
         self.tz = "%+03d%02d" % (- time.timezone / 3600, ((- time.timezone % 3600) / 60))
 
-        importProcess = subprocess.Popen(["git", "fast-import"],
+        importProcess = subprocess.Popen(["git", "fast-import", "--force"],
                                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE);
         self.gitOutput = importProcess.stdout
-- 
1.7.5.4
Previous: Vitor AntunesNext: Vitor Antunes
Message 2 of 11 in “Search for parent commit in new branch import”
  1. 0/2 Search for parent commit in new branch importVitor Antunes, Aug 19, 2011
  2. 1/2 git-p4: Search for parent commit on branch creationVitor Antunes, Aug 19, 2011
  3. 2/2 git-p4: Add complex test case for branch importVitor Antunes, Aug 19, 2011
  4. Pete WyckoffAug 20, 2011
  5. Vitor AntunesAug 22, 2011
  6. Pete WyckoffAug 23, 2011
  7. Vitor AntunesAug 23, 2011
  8. Pete WyckoffAug 23, 2011
  9. Vitor AntunesAug 24, 2011
  10. Vitor AntunesAug 24, 2011
  11. Pete WyckoffAug 27, 2011

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.