Mercurial > public > mercurial-scm > hg
diff hgext/mq.py @ 5673:dd3ce7515f4d
mq: add --currentuser and --user options to qnew and qrefresh
These options make qnew and qrefresh add/update the "From:" header (or, if present,
the "# User" header). This allows proper attribution of patches in patch queues
with multiple contributors.
author | peter.arrenbrecht@gmail.com |
---|---|
date | Wed, 19 Dec 2007 22:36:18 +0100 |
parents | 1f044b04fa0a |
children | 4107e823dc2c |
line wrap: on
line diff
--- a/hgext/mq.py Mon Dec 17 23:42:48 2007 +0100 +++ b/hgext/mq.py Wed Dec 19 22:36:18 2007 +0100 @@ -603,6 +603,7 @@ def new(self, repo, patch, *pats, **opts): msg = opts.get('msg') force = opts.get('force') + user = opts.get('user') if os.path.exists(self.join(patch)): raise util.Abort(_('patch "%s" already exists') % patch) if opts.get('include') or opts.get('exclude') or pats: @@ -617,7 +618,7 @@ try: insert = self.full_series_end() commitmsg = msg and msg or ("[mq]: %s" % patch) - n = repo.commit(commitfiles, commitmsg, match=match, force=True) + n = repo.commit(commitfiles, commitmsg, user, match=match, force=True) if n == None: raise util.Abort(_("repo commit failed")) self.full_series[insert:insert] = [patch] @@ -626,6 +627,8 @@ self.series_dirty = 1 self.applied_dirty = 1 p = self.opener(patch, "w") + if user: + p.write("From: " + user + "\n\n") if msg: msg = msg + "\n" p.write(msg) @@ -945,6 +948,22 @@ while message[mi] != comments[ci]: ci += 1 del comments[ci] + + newuser = opts.get('user') + if newuser: + # Update all references to a user in the patch header. + # If none found, add "From: " header. + needfrom = True + for prefix in ['# User ', 'From: ']: + for i in xrange(len(comments)): + if comments[i].startswith(prefix): + comments[i] = prefix + newuser + needfrom = False + break + if needfrom: + comments = ['From: ' + newuser, ''] + comments + user = newuser + if msg: comments.append(msg) @@ -1070,9 +1089,12 @@ else: message = msg + if not user: + user = changes[1] + self.strip(repo, top, update=False, backup='strip') - n = repo.commit(filelist, message, changes[1], match=matchfn, + n = repo.commit(filelist, message, user, match=matchfn, force=1) self.applied[-1] = statusentry(revlog.hex(n), patchfn) self.applied_dirty = 1 @@ -1605,6 +1627,12 @@ return q.qseries(repo, start=l-2, length=1, status='A', summary=opts.get('summary')) +def setupheaderopts(ui, opts): + def do(opt,val): + if not opts[opt] and opts['current' + opt]: + opts[opt] = val + do('user', ui.username()) + def new(ui, repo, patch, *args, **opts): """create a new patch @@ -1623,6 +1651,7 @@ if opts['edit']: message = ui.edit(message, ui.username()) opts['msg'] = message + setupheaderopts(ui, opts) q.new(repo, patch, *args, **opts) q.save_dirty() return 0 @@ -1648,6 +1677,7 @@ patch = q.applied[-1].name (message, comment, user, date, hasdiff) = q.readheaders(patch) message = ui.edit('\n'.join(message), user or ui.username()) + setupheaderopts(ui, opts) ret = q.refresh(repo, pats, msg=message, **opts) q.save_dirty() return ret @@ -2138,6 +2168,10 @@ seriesopts = [('s', 'summary', None, _('print first line of patch header'))] +headeropts = [ + ('U', 'currentuser', None, _('add "From: <current user>" to patch')), + ('u', 'user', '', _('add "From: <given user>" to patch'))] + cmdtable = { "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), "qclone": @@ -2196,7 +2230,7 @@ [('e', 'edit', None, _('edit commit message')), ('f', 'force', None, _('import uncommitted changes into patch')), ('g', 'git', None, _('use git extended diff format')), - ] + commands.walkopts + commands.commitopts, + ] + commands.walkopts + commands.commitopts + headeropts, _('hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH [FILE]...')), "qnext": (next, [] + seriesopts, _('hg qnext [-s]')), "qprev": (prev, [] + seriesopts, _('hg qprev [-s]')), @@ -2219,7 +2253,7 @@ [('e', 'edit', None, _('edit commit message')), ('g', 'git', None, _('use git extended diff format')), ('s', 'short', None, _('refresh only files already in the patch')), - ] + commands.walkopts + commands.commitopts, + ] + commands.walkopts + commands.commitopts + headeropts, _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), 'qrename|qmv': (rename, [], _('hg qrename PATCH1 [PATCH2]')),