Skip to content

Instantly share code, notes, and snippets.

@caisui
Created August 13, 2011 07:34
Show Gist options
  • Save caisui/1143578 to your computer and use it in GitHub Desktop.
Save caisui/1143578 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf8 -*-
from mercurial.i18n import _
from mercurial import ui, hg
from mercurial import extensions, patch, cmdutil, commands
def committohookfunc(repo, commitfunc, **opts):
def _commitfunc(ui, repo, *pats, **opts):
opts = opts.copy()
opts['force_editor'] = True
chunk = patch.diff(repo, None, None, match=cmdutil.matchfiles(repo, pats))
opts['message'] += '\n'.join(chunk)
opts.pop('patch')
commitfunc(ui, repo, *pats, **opts)
if opts['patch']:
return _commitfunc
else:
return commitfunc
#return _commitfunc if opts['patch'] else commitfunc
def record(ui, repo, *pats, **opts):
diffstr = []
record = extensions.find('record')
record.dorecord(ui, repo, committohookfunc(repo, commands.commit, **opts), *pats, **opts)
def qrecord(ui, repo, patchname, *pats, **opts):
mq = extensions.find('mq')
rec = extensions.find('record')
def commitfunc(ui, repo, *pats, **opts):
opts['edit'] = True
mq.new(ui, repo, patchname, *pats, **opts)
opts = opts.copy()
opts['force'] = True
rec.dorecord(ui, repo, committohookfunc(repo, commitfunc, **opts), *pats, **opts)
cmdtable = {}
def uisetup(ui):
try:
rec = extensions.find('record')
except KeyError:
return
reccmdtable = rec.cmdtable
optp = [('p', 'patch', False, _('insert patch comment message'))]
cmdrec = reccmdtable['record']
record.__doc__ = cmdrec[0].__doc__
reccmdtable.update({
"record": (record,
[opt for opt in cmdrec[1]] + optp,
cmdrec[2]),
})
try:
mq = extensions.find('mq')
except KeyError:
return
cmdqrec = reccmdtable['qrecord']
qrecord.__doc__ = cmdqrec[0].__doc__
reccmdtable.update({
"qrecord": (qrecord,
[opt for opt in cmdqrec[1]] + optp,
cmdqrec[2]),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment