[Frugalware-darcs] vmexam: dg: added options to rec

VMiklos vmiklos at frugalware.org
Wed Jun 13 19:15:04 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070613171254-e2957-b13dc07b670e69b9ac9abf47874f44a74810a7e8.gz;

[dg: added options to rec
VMiklos <vmiklos at frugalware.org>**20070613171254] {
hunk ./python/dg.py 3
-import sys, tty, termios, os, re
+import sys, tty, termios, os, re, getopt
hunk ./python/dg.py 55
-	sock = os.popen("git status -v -a")
+	sock = os.popen("git diff HEAD")
hunk ./python/dg.py 105
-def askhunks(hunks):
+def askhunks(hunks, preans=None):
hunk ./python/dg.py 108
-	preans = None
hunk ./python/dg.py 151
-def record():
+def record(argv):
+	def usage(ret):
+		print """Usage: darcs-git record [OPTION]... [FILE or DIRECTORY]...
+Save changes in the unstaged index to the current branch as a commit.
+
+Options:
+  -m PATCHNAME  --commit-name=PATCHNAME  name of commit
+  -a            --all                    answer yes to all hunks
+  -e            --edit-long-comment      backward compatibility
+  -h            --help                   shows brief description of command and its arguments"""
+		sys.exit(ret)
+
+	class Options:
+		def __init__(self):
+			self.name = None
+			self.all = False
+			self.help = False
+	options = Options()
+
+	try:
+		opts, args = getopt.getopt(argv, "m:ah", ["commit-name=", "all", "help"])
+	except getopt.GetoptError:
+		usage(1)
+	for opt, arg in opts:
+		if opt in ("-m", "--commit-name"):
+			options.name = arg
+		elif opt in ("-a", "--all"):
+			options.all = True
+		elif opt in ("-h", "--help"):
+			options.help = True
+	if options.help:
+		usage(0)
hunk ./python/dg.py 184
-	status.hunks = askhunks(status.hunks)
-	flist = []
-	for i in status.hunks:
-		if i.picked:
-			flist.append(re.sub(r".* a/([^ ]+) .*", r"\1", i.text.split("\n")[0]))
+	if options.all:
+		status.hunks = askhunks(status.hunks, True)
+	else:
+		status.hunks = askhunks(status.hunks)
hunk ./python/dg.py 189
-		pass
-		msg = ask("What is the patch name?", str)
+		if options.name:
+			msg = options.name
+		else:
+			msg = ask("What is the patch name?", str)
hunk ./python/dg.py 196
+	flist = []
+	for i in status.hunks:
+		if i.picked:
+			flist.append(re.sub(r".* a/([^ ]+) .*", r"\1", i.text.split("\n")[0]))
hunk ./python/dg.py 220
-def main():
+def main(argv):
hunk ./python/dg.py 224
-		if sys.argv[1] == "rec":
-			record()
+		if sys.argv[1][:3] == "rec":
+			record(argv[1:])
hunk ./python/dg.py 230
-	main()
+	main(sys.argv[1:])
}


More information about the Frugalware-darcs mailing list