# HG changeset patch # User "Mathieu Clabaut " # Date 1153937514 -7200 # Node ID 0fb28dbf0dc79bf49fd33e937a65c7c396d69e93 # Parent 8342c0286184e1871c084431093a2b5393d99fd3 MQ: uniformise message and logfile option. Possibility to change message in qrefresh option diff -r 8342c0286184 -r 0fb28dbf0dc7 hgext/mq.py --- a/hgext/mq.py Thu Jul 27 09:14:53 2006 -0700 +++ b/hgext/mq.py Wed Jul 26 20:11:54 2006 +0200 @@ -442,7 +442,7 @@ r = self.qrepo() if r: r.add([patch]) if commitfiles: - self.refresh(repo, short=True) + self.refresh(repo, msg=None, short=True) def strip(self, repo, rev, update=True, backup="all", wlock=None): def limitheads(chlog, stop): @@ -739,7 +739,7 @@ qp = self.qparents(repo, top) commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) - def refresh(self, repo, short=False): + def refresh(self, repo, msg=None, short=False): if len(self.applied) == 0: self.ui.write("No patches applied\n") return @@ -822,10 +822,14 @@ repo.dirstate.update(c, 'n') repo.dirstate.forget(forget) - if not message: - message = "patch queue: %s\n" % patch + if not msg: + if not message: + message = "patch queue: %s\n" % patch + else: + message = "\n".join(message) else: - message = "\n".join(message) + message = msg + self.strip(repo, top, update=False, backup='strip', wlock=wlock) n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) self.applied[-1] = revlog.hex(n) + ':' + patch @@ -1144,14 +1148,16 @@ def new(ui, repo, patch, **opts): """create a new patch""" q = repomap[repo] - q.new(repo, patch, msg=opts['message'], force=opts['force']) + message=commands.logmessage(**opts) + q.new(repo, patch, msg=message, force=opts['force']) q.save_dirty() return 0 def refresh(ui, repo, **opts): """update the current patch""" q = repomap[repo] - q.refresh(repo, short=opts['short']) + message=commands.logmessage(**opts) + q.refresh(repo, msg=message, short=opts['short']) q.save_dirty() return 0 @@ -1234,7 +1240,8 @@ def save(ui, repo, **opts): """save current queue state""" q = repomap[repo] - ret = q.save(repo, msg=opts['message']) + message=commands.logmessage(**opts) + ret = q.save(repo, msg=message) if ret: return ret q.save_dirty() @@ -1325,9 +1332,10 @@ 'hg qinit [-c]'), "qnew": (new, - [('m', 'message', '', 'commit message'), + [('m', 'message', '', _('use as commit message')), + ('l', 'logfile', '', _('read the commit message from ')), ('f', 'force', None, 'force')], - 'hg qnew [-m TEXT] [-f] PATCH'), + 'hg qnew [-m TEXT] [-l FILE] [-f] PATCH'), "qnext": (next, [], 'hg qnext'), "qprev": (prev, [], 'hg qprev'), "^qpop": @@ -1346,8 +1354,10 @@ 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), "^qrefresh": (refresh, - [('s', 'short', None, 'short refresh')], - 'hg qrefresh [-s]'), + [('m', 'message', '', _('change commit message with ')), + ('l', 'logfile', '', _('change commit message with content')), + ('s', 'short', None, 'short refresh')], + 'hg qrefresh [-m TEXT] [-l FILE] [-s]'), "qrestore": (restore, [('d', 'delete', None, 'delete save entry'), @@ -1355,12 +1365,13 @@ 'hg qrestore [-d] [-u] REV'), "qsave": (save, - [('m', 'message', '', 'commit message'), + [('m', 'message', '', _('use as commit message')), + ('l', 'logfile', '', _('read the commit message from ')), ('c', 'copy', None, 'copy patch directory'), ('n', 'name', '', 'copy directory name'), ('e', 'empty', None, 'clear queue status file'), ('f', 'force', None, 'force copy')], - 'hg qsave [-m TEXT] [-c] [-n NAME] [-e] [-f]'), + 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), "qseries": (series, [('m', 'missing', None, 'print patches not in series')], diff -r 8342c0286184 -r 0fb28dbf0dc7 mercurial/commands.py --- a/mercurial/commands.py Thu Jul 27 09:14:53 2006 -0700 +++ b/mercurial/commands.py Wed Jul 26 20:11:54 2006 +0200 @@ -40,6 +40,25 @@ return [util.normpath(os.path.join(cwd, x)) for x in args] return args +def logmessage(**opts): + """ get the log message according to -m and -l option """ + message = opts['message'] + logfile = opts['logfile'] + + if message and logfile: + raise util.Abort(_('options --message and --logfile are mutually ' + 'exclusive')) + if not message and logfile: + try: + if logfile == '-': + message = sys.stdin.read() + else: + message = open(logfile).read() + except IOError, inst: + raise util.Abort(_("can't read commit message '%s': %s") % + (logfile, inst.strerror)) + return message + def matchpats(repo, pats=[], opts={}, head=''): cwd = repo.getcwd() if not pats and cwd: @@ -989,21 +1008,7 @@ If no commit message is specified, the editor configured in your hgrc or in the EDITOR environment variable is started to enter a message. """ - message = opts['message'] - logfile = opts['logfile'] - - if message and logfile: - raise util.Abort(_('options --message and --logfile are mutually ' - 'exclusive')) - if not message and logfile: - try: - if logfile == '-': - message = sys.stdin.read() - else: - message = open(logfile).read() - except IOError, inst: - raise util.Abort(_("can't read commit message '%s': %s") % - (logfile, inst.strerror)) + message = logmessage(**opts) if opts['addremove']: addremove_lock(ui, repo, pats, opts) diff -r 8342c0286184 -r 0fb28dbf0dc7 tests/test-mq-qrefresh-replace-log-message --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-mq-qrefresh-replace-log-message Wed Jul 26 20:11:54 2006 +0200 @@ -0,0 +1,51 @@ +#!/bin/sh + +# Environement setup for MQ +export HGRCPATH=./hgrc +echo "[extensions]" >> ./hgrc +echo "mq=" >> ./hgrc + +#Repo init +hg init +hg qinit + +hg qnew -m "First commit message" first-patch +echo aaaa > file +hg add file +hg qrefresh +echo ======================= +echo "Should display 'First commit message'" +hg log -l1 -v | sed -n '/description/,$p' +echo + +# Testing changing message with -m +echo bbbb > file +hg qrefresh -m "Second commit message" +echo ======================= +echo "Should display 'Second commit message'" +hg log -l1 -v | sed -n '/description/,$p' +echo + + +# Testing changing message with -l +echo "Third commit message" > logfile +echo " This is the 3rd log message" >> logfile +echo bbbb > file +hg qrefresh -l logfile +echo ======================= +echo "Should display 'Third commit message\n This is the 3rd log message'" +hg log -l1 -v | sed -n '/description/,$p' +echo + +# Testing changing message with -l- +hg qnew -m "First commit message" second-patch +echo aaaa > file2 +hg add file2 +echo bbbb > file2 +(echo "Fifth commit message" +echo " This is the 5th log message" >> logfile) |\ +hg qrefresh -l- +echo ======================= +echo "Should display 'Fifth commit message\n This is the 5th log message'" +hg log -l1 -v | sed -n '/description/,$p' +echo diff -r 8342c0286184 -r 0fb28dbf0dc7 tests/test-mq-qrefresh-replace-log-message.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-mq-qrefresh-replace-log-message.out Wed Jul 26 20:11:54 2006 +0200 @@ -0,0 +1,29 @@ +======================= +Should display 'First commit message' +description: +First commit message + + + +======================= +Should display 'Second commit message' +description: +Second commit message + + + +======================= +Should display 'Third commit message\n This is the 3rd log message' +description: +Third commit message + This is the 3rd log message + + + +======================= +Should display 'Fifth commit message\n This is the 5th log message' +description: +Fifth commit message + + +