From: Vitor Antunes <vitor.hda@gmail.com>
To: git@vger.kernel.org
Cc: Pete Wyckoff <pw@padd.com>, Luke Diamand <luke@diamand.org>,
Vitor Antunes <vitor.hda@gmail.com>
Subject: [PATCH v2 2/3] git-p4: Search for parent commit on branch creation
Date: Sat, 21 Jan 2012 00:21:31 +0000 [thread overview]
Message-ID: <1327105292-30092-3-git-send-email-vitor.hda@gmail.com> (raw)
In-Reply-To: <1327105292-30092-1-git-send-email-vitor.hda@gmail.com>
To find out which is its parent the commit of the new branch is applied
sequentially to each blob of the parent branch from the newest to the
oldest. The first blob which results in a zero diff is considered the
parent commit. If none is found, then the commit is applied to the top
of the parent branch.
A fast-import "checkpoint" call is required for each comparison because
diff-tree is only able to work with blobs on disk. But most of these
commits will not be part of the final imported tree, making fast-import
fail. To avoid this, the temporary branches are tracked and then removed
at the end of the import process.
Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
contrib/fast-import/git-p4 | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 417d119..2e3b741 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1429,6 +1429,8 @@ class P4Sync(Command, P4UserMap):
self.cloneExclude = []
self.useClientSpec = False
self.clientSpecDirs = None
+ self.tempBranches = []
+ self.tempBranchLocation = "git-p4-tmp"
if gitConfig("git-p4.syncFromOrigin") == "false":
self.syncWithOrigin = False
@@ -2012,7 +2014,27 @@ class P4Sync(Command, P4UserMap):
parent = self.initialParents[branch]
del self.initialParents[branch]
- self.commit(description, filesForCommit, branch, [branchPrefix], parent)
+ parentFound = False
+ if len(parent) > 0:
+ tempBranch = os.path.join(self.tempBranchLocation, "%d" % (change))
+ if self.verbose:
+ print "Creating temporary branch: " + tempBranch
+ self.commit(description, filesForCommit, tempBranch, [branchPrefix])
+ self.tempBranches.append(tempBranch)
+ self.checkpoint()
+ for blob in read_pipe_lines("git rev-list --reverse --no-merges %s" % parent):
+ blob = blob.strip()
+ if len( read_pipe("git diff-tree %s %s" % (blob, tempBranch)) ) == 0:
+ parentFound = True
+ if self.verbose:
+ print "Found parent of %s in commit %s" % (branch, blob)
+ break
+ if parentFound:
+ self.commit(description, filesForCommit, branch, [branchPrefix], blob)
+ else:
+ 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,
@@ -2347,6 +2369,12 @@ class P4Sync(Command, P4UserMap):
self.gitOutput.close()
self.gitError.close()
+ # Cleanup temporary branches created during import
+ if self.tempBranches != []:
+ for branch in self.tempBranches:
+ read_pipe("git update-ref -d %s" % branch)
+ os.rmdir(os.path.join(os.environ.get("GIT_DIR", ".git"), self.tempBranchLocation))
+
return True
class P4Rebase(Command):
--
1.7.7.rc2.14.g5e044.dirty
next prev parent reply other threads:[~2012-01-21 0:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-21 0:21 [PATCH v2 0/3] git-p4: Search for parent commit on branch creation Vitor Antunes
2012-01-21 0:21 ` [PATCH v2 1/3] git-p4: Add checkpoint() task Vitor Antunes
2012-01-21 0:21 ` Vitor Antunes [this message]
2012-01-21 4:55 ` [PATCH v2 2/3] git-p4: Search for parent commit on branch creation Junio C Hamano
2012-01-23 13:49 ` Vitor Antunes
2012-01-21 0:21 ` [PATCH v2 3/3] git-p4: Add test case for complex branch import Vitor Antunes
2012-01-21 4:54 ` Junio C Hamano
2012-01-21 10:51 ` Luke Diamand
2012-01-21 17:11 ` Pete Wyckoff
2012-01-23 14:01 ` Vitor Antunes
2012-01-23 22:40 ` Pete Wyckoff
2012-01-25 1:23 ` Vitor Antunes
2012-01-25 12:34 ` Pete Wyckoff
[not found] ` <CAOpHH-Wcf3innjA4LS0TMrLzEwbQzfZmHssxSBYvv4v7UMfi1w@mail.gmail.com>
2012-01-25 1:39 ` Vitor Antunes
2012-01-25 4:02 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327105292-30092-3-git-send-email-vitor.hda@gmail.com \
--to=vitor.hda@gmail.com \
--cc=git@vger.kernel.org \
--cc=luke@diamand.org \
--cc=pw@padd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).