[PATCH 1 of 3] Import darcs tags

Guy Brand gb at isis.u-strasbg.fr
Sat Feb 24 18:52:48 UTC 2007


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

diff -r 972519384853 -r 9028722e6096 contrib/darcs2hg.py
--- a/contrib/darcs2hg.py	Fri Feb 23 14:16:50 2007 -0600
+++ b/contrib/darcs2hg.py	Tue Feb 13 00:03:57 2007 +0100
@@ -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 mailing list