[PATCH 01 of 10] Import darcs tags

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


# HG changeset patch
# User Guy Brand <gb at isis.u-strasbg.fr>
# Date 1171321437 -3600
# Node ID e477842c5567cca9d94d4469c47aa2b17d13914c
# Parent  97251938485365716a52aebb013d271ba5f55e68
Import darcs tags

diff --git a/contrib/darcs2hg.py b/contrib/darcs2hg.py
--- a/contrib/darcs2hg.py
+++ b/contrib/darcs2hg.py
@@ -11,7 +11,7 @@
 # Last mod  : 05-Jun-2006
 # -----------------------------------------------------------------------------
 
-import os, sys
+import os, sys, re
 import tempfile
 import xml.dom.minidom as xml_dom
 from time import strptime, mktime
@@ -117,6 +117,7 @@ def hg_commit( hg_repo, text, author, da
 	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
 		else:
 			error("Mercurial commit did not work as expected: " + res)
@@ -126,6 +127,18 @@ def hg_tip( hg_repo ):
 	tip = cmd("hg tip", hg_repo, silent=True)
 	tip = tip.split("\n")[0].split(":")[1].strip()
 	return int(tip)
+
+def hg_tag( hg_repo, text, author, date ):
+	old_tip = hg_tip(hg_repo)
+	text = text.strip()
+	tag_file = hg_repo + "/.hgtags"
+	res = cmd("hg tags", hg_repo, silent=True)
+	(dead_text,hit) = re.subn(text,'',res)
+	if hit == 0:
+		cmd("hg tag -u \"%s\" -d \"%s 0\" \"%s\""  % (author, date, text), hg_repo)
+		new_tip = hg_tip(hg_repo)
+	else:
+		print "Ignoring already seen tag %s\n" % (text)
 
 # ------------------------------------------------------------------------------
 #
@@ -172,7 +185,11 @@ if __name__ == "__main__":
 			# --------------------------------YYYYMMDDHHMMSS
 			date = chash.split("-")[0]
 			epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S')))
-			hg_commit(hg_repo, text, author, epoch)
+			(text,hit) = re.subn('^TAG ','',text)
+			if hit == 0:
+				hg_commit(hg_repo, text, author, epoch)
+			else:
+				hg_tag(hg_repo, text, author, epoch)
 		change_number += 1
 	print "Darcs repository (_darcs) was not deleted. You can keep or remove it."
 



More information about the Mercurial-devel mailing list