[PATCH 07 of 10] Handle empty Darcs changesets

jgoerzen at complete.org jgoerzen at complete.org
Sun Mar 4 13:16:15 CST 2007


# HG changeset patch
# User John Goerzen <jgoerzen at complete.org>
# Date 1173038402 21600
# Node ID 820de3cbb48bf52b869e164363d6c95fc7c56f2a
# Parent  7ba79d2266886dc42a851f82dc9f5b7ef232e29d
Handle empty Darcs changesets
In Darcs, it is possible and valid to commit a changeset that doesn't
actually change anything.  In the past, darcs2hg.py dropped these.
Although they don't change code, they may contain log messages that
are of use to the history of the project.

Work around this in Mercurial by creating a file .hgempty and adding
the log message to iw.

diff --git a/contrib/darcs2hg.py b/contrib/darcs2hg.py
--- a/contrib/darcs2hg.py
+++ b/contrib/darcs2hg.py
@@ -119,15 +119,19 @@ def hg_commit( hg_repo, text, author, da
 	cmd("hg remove -X _darcs --after", hg_repo)
 	res = cmd("hg commit -l %s -u \"%s\" -d \"%s 0\""  % (tmpfile, author, date), hg_repo)
 	os.close(fd)
-	os.unlink(tmpfile)
 	new_tip = hg_tip(hg_repo)
 	if not new_tip == old_tip + 1:
 		# Sometimes we may have empty commits, we simply skip them
 		if res.strip().lower().find("nothing changed") != -1:
-			print "Nothing to commit\n"
-			pass
+                        cmd("echo 'Empty darcs changeset:' >> .hgempty",
+                            hg_repo)
+                        cmd("cat %s >> .hgempty" % tmpfile, hg_repo)
+                        cmd("hg add .hgempty", hg_repo)
+                        cmd("hg commit -l %s -u \"%s\" -d \"%s 0\"" %
+                            (tmpfile, author, date), hg_repo)
 		else:
 			error("Mercurial commit did not work as expected: " + res)
+	os.unlink(tmpfile)
 
 def hg_tip( hg_repo ):
 	"""Returns the latest local revision number in the given repository."""



More information about the Mercurial-devel mailing list