--- a/hgext/mq.py Mon Dec 31 09:15:39 2007 -0600
+++ b/hgext/mq.py Wed Jan 02 16:24:13 2008 +0100
@@ -604,6 +604,7 @@
msg = opts.get('msg')
force = opts.get('force')
user = opts.get('user')
+ date = opts.get('date')
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:
@@ -618,7 +619,7 @@
try:
insert = self.full_series_end()
commitmsg = msg and msg or ("[mq]: %s" % patch)
- n = repo.commit(commitfiles, commitmsg, user, match=match, force=True)
+ n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True)
if n == None:
raise util.Abort(_("repo commit failed"))
self.full_series[insert:insert] = [patch]
@@ -627,8 +628,15 @@
self.series_dirty = 1
self.applied_dirty = 1
p = self.opener(patch, "w")
- if user:
- p.write("From: " + user + "\n\n")
+ if date:
+ p.write("# HG changeset patch\n")
+ if user:
+ p.write("# User " + user + "\n")
+ p.write("# Date " + date + "\n")
+ p.write("\n")
+ elif user:
+ p.write("From: " + user + "\n")
+ p.write("\n")
if msg:
msg = msg + "\n"
p.write(msg)
@@ -949,21 +957,33 @@
ci += 1
del comments[ci]
+ def setheaderfield(comments, prefixes, new):
+ # Update all references to a field in the patch header.
+ # If none found, add it email style.
+ res = False
+ for prefix in prefixes:
+ for i in xrange(len(comments)):
+ if comments[i].startswith(prefix):
+ comments[i] = prefix + new
+ res = True
+ break
+ return res
+
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
+ if not setheaderfield(comments, ['From: ', '# User '], newuser):
+ try:
+ patchheaderat = comments.index('# HG changeset patch')
+ comments.insert(patchheaderat + 1,'# User ' + newuser)
+ except ValueError:
+ comments = ['From: ' + newuser, ''] + comments
user = newuser
+ newdate = opts.get('date')
+ if newdate:
+ if setheaderfield(comments, ['# Date '], newdate):
+ date = newdate
+
if msg:
comments.append(msg)
@@ -1094,7 +1114,7 @@
self.strip(repo, top, update=False,
backup='strip')
- n = repo.commit(filelist, message, user, match=matchfn,
+ n = repo.commit(filelist, message, user, date, match=matchfn,
force=1)
self.applied[-1] = statusentry(revlog.hex(n), patchfn)
self.applied_dirty = 1
@@ -1632,6 +1652,7 @@
if not opts[opt] and opts['current' + opt]:
opts[opt] = val
do('user', ui.username())
+ do('date', "%d %d" % util.makedate())
def new(ui, repo, patch, *args, **opts):
"""create a new patch
@@ -2170,7 +2191,9 @@
headeropts = [
('U', 'currentuser', None, _('add "From: <current user>" to patch')),
- ('u', 'user', '', _('add "From: <given user>" to patch'))]
+ ('u', 'user', '', _('add "From: <given user>" to patch')),
+ ('D', 'currentdate', None, _('add "Date: <current date>" to patch')),
+ ('d', 'date', '', _('add "Date: <given date>" to patch'))]
cmdtable = {
"qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')),