git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Drago <markdrago@gmail.com>
To: stelian@popies.net, gitster@pobox.com
Cc: git@vger.kernel.org
Subject: [PATCH] hg-to-git: handle an empty dir in hg by combining git commits
Date: Sat, 01 Dec 2007 12:59:23 -0500	[thread overview]
Message-ID: <4751A0FB.6090705@gmail.com> (raw)

I had a subversion repository which was then converted to hg and now is moving
in to git.  The first commit in the svn repo was just the creation of the empty
directory.  This made its way in to the hg repository fine, but converting from
hg to git would cause an error.  The problem was that hg-to-git.py tries to
commit the change, git-commit fails, and then hg-to-git.py tries to checkout
the new revision and that fails (b/c it was not created).  This may have only
caused an error because it was the first commit in the repository.  If an empty
directory was added in the middle of the repo somewhere things might have
worked out fine.

This patch will detect that there are no changes to commit (using git-status),
and will not perform the commit, but will instead combine the log messages of
that (non-)commit with the next commit.

Signed-off-by: Mark Drago <markdrago@gmail.com>
---
 contrib/hg-to-git/hg-to-git.py |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index 6bff49b..06e1b41 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -139,6 +139,7 @@ if not hgvers.has_key("0"):
     os.system('git-init-db')
 
 # loop through every hg changeset
+previous_comment = None
 for cset in range(int(tip) + 1):
 
     # incremental, already seen
@@ -159,6 +160,8 @@ for cset in range(int(tip) + 1):
 
     (fdcomment, filecomment) = tempfile.mkstemp()
     csetcomment = os.popen('hg log -r %d -v | grep -v ^changeset: | grep -v ^parent: | grep -v ^user: | grep -v ^date | grep -v ^files: | grep -v ^description: | grep -v ^tag: | grep -v ^branch:' % cset).read().strip()
+    if (previous_comment):
+	csetcomment += previous_comment
     os.write(fdcomment, csetcomment)
     os.close(fdcomment)
 
@@ -181,8 +184,8 @@ for cset in range(int(tip) + 1):
         print 'tag:', tag
     print '-----------------------------------------'
 
-    # checkout the parent if necessary
-    if cset != 0:
+    # checkout the parent if there is a repo to checkout from
+    if hgvers.has_key("0"):
         if hgbranch[str(cset)] == "branch-" + str(cset):
             print 'creating new branch', hgbranch[str(cset)]
             os.system('git-checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
@@ -210,6 +213,14 @@ for cset in range(int(tip) + 1):
     # delete removed files
     os.system('git-ls-files -x .hg --deleted | git-update-index --remove --stdin')
 
+    # is there something that git will commit (maybe just empty dir was added)
+    stat = os.system('git-status -a')
+    if (stat != 0):
+	print "No changes git notices, will combine log with next commit (maybe empty dir?)"
+	previous_comment = "\n\n--- hg-to-git merged commit ---\n\n" + csetcomment
+	continue
+    previous_comment = None
+
     # commit
     os.system(getgitenv(user, date) + 'git-commit -a -F %s' % filecomment)
     os.unlink(filecomment)
-- 
1.5.2.4

             reply	other threads:[~2007-12-01 17:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-01 17:59 Mark Drago [this message]
2007-12-01 20:02 ` [PATCH] hg-to-git: handle an empty dir in hg by combining git commits Junio C Hamano
2007-12-03  8:44   ` [PATCH] git-commit --allow-empty Junio C Hamano
2007-12-03  8:53     ` Junio C Hamano
2007-12-03 17:58     ` Nicolas Pitre
2007-12-03 18:16       ` Junio C Hamano
2007-12-05  7:01   ` [PATCH] hg-to-git: handle an empty dir in hg by combining git commits Junio C Hamano
2007-12-06 12:50     ` Mark Drago

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=4751A0FB.6090705@gmail.com \
    --to=markdrago@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stelian@popies.net \
    /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).