summaryrefslogtreecommitdiff
path: root/.hgext/hgshelve.py
diff options
context:
space:
mode:
Diffstat (limited to '.hgext/hgshelve.py')
-rw-r--r--.hgext/hgshelve.py110
1 files changed, 45 insertions, 65 deletions
diff --git a/.hgext/hgshelve.py b/.hgext/hgshelve.py
index 6d7b27d..a8069da 100644
--- a/.hgext/hgshelve.py
+++ b/.hgext/hgshelve.py
@@ -15,36 +15,6 @@ import copy, cStringIO, errno, operator, os, re, shutil, tempfile
lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)')
-def internalpatch(patchobj, ui, strip, cwd, reverse=False, files={}):
- """use builtin patch to apply <patchobj> to the working directory.
- returns whether patch was applied with fuzz factor.
-
- Adapted from patch.internalpatch() to support reverse patching.
- """
-
- eolmode = ui.config('patch', 'eol', 'strict')
- try:
- eol = {'strict': None, 'crlf': '\r\n', 'lf': '\n'}[eolmode.lower()]
- except KeyError:
- raise util.Abort(_('Unsupported line endings type: %s') % eolmode)
-
- try:
- fp = file(patchobj, 'rb')
- except TypeError:
- fp = patchobj
- if cwd:
- curdir = os.getcwd()
- os.chdir(cwd)
- try:
- ret = patch.applydiff(ui, fp, files, strip=strip,
- reverse=reverse, eol=eol)
- finally:
- if cwd:
- os.chdir(curdir)
- if ret < 0:
- raise PatchError
- return ret > 0
-
def scanpatch(fp):
lr = patch.linereader(fp)
@@ -304,6 +274,7 @@ def filterpatch(ui, chunks, shouldprompt=True):
if resp_file[0] is not None:
return resp_file[0]
while True:
+ resps = _('[Ynsfdaq?]')
choices = (_('&Yes, shelve this change'),
_('&No, skip this change'),
_('&Skip remaining changes to this file'),
@@ -312,24 +283,27 @@ def filterpatch(ui, chunks, shouldprompt=True):
_('Shelve &all changes to all remaining files'),
_('&Quit, shelving no changes'),
_('&?'))
- r = (ui.prompt(query + _(' [Ynsfdaq?] '), choices)
- or 'y').lower()
- if r == '?':
+ r = ui.promptchoice("%s %s " % (query, resps), choices)
+ if r == 7:
c = shelve.__doc__.find('y - shelve this change')
for l in shelve.__doc__[c:].splitlines():
if l: ui.write(_(l.strip()) + '\n')
continue
- elif r == 's':
- r = resp_file[0] = 'n'
- elif r == 'f':
- r = resp_file[0] = 'y'
- elif r == 'd':
- r = resp_all[0] = 'n'
- elif r == 'a':
- r = resp_all[0] = 'y'
- elif r == 'q':
+ elif r == 0: # yes
+ ret = 'y'
+ elif r == 1: # no
+ ret = 'n'
+ elif r == 2: # Skip
+ ret = resp_file[0] = 'n'
+ elif r == 3: # file (shelve remaining)
+ ret = resp_file[0] = 'y'
+ elif r == 4: # done, skip remaining
+ ret = resp_all[0] = 'n'
+ elif r == 5: # all
+ ret = resp_all[0] = 'y'
+ elif r == 6: # quit
raise util.Abort(_('user quit'))
- return r
+ return ret
while chunks:
chunk = chunks.pop()
if isinstance(chunk, header):
@@ -427,7 +401,7 @@ def shelve(ui, repo, *pats, **opts):
The shelve command works with the Color extension to display
diffs in color.
- On each prompt, the following responses are possible:
+ On each prompt, the following responses are possible::
y - shelve this change
n - skip this change
@@ -517,7 +491,7 @@ def shelve(ui, repo, *pats, **opts):
if dopatch:
ui.debug('applying patch\n')
ui.debug(fp.getvalue())
- patch.internalpatch(fp, ui, 1, repo.root)
+ patch.internalpatch(ui, repo, fp, 1)
del fp
# 3c. apply filtered patch to clean repo (shelve)
@@ -550,7 +524,19 @@ def shelve(ui, repo, *pats, **opts):
except OSError:
pass
fancyopts.fancyopts([], commands.commitopts, opts)
- return cmdutil.commit(ui, repo, shelvefunc, pats, opts)
+
+ # wrap ui.write so diff output can be labeled/colorized
+ def wrapwrite(orig, *args, **kw):
+ label = kw.pop('label', '')
+ if label: label += ' '
+ for chunk, l in patch.difflabel(lambda: args):
+ orig(chunk, label=label + l)
+ oldwrite = ui.write
+ extensions.wrapfunction(ui, 'write', wrapwrite)
+ try:
+ return cmdutil.commit(ui, repo, shelvefunc, pats, opts)
+ finally:
+ ui.write = oldwrite
def listshelves(ui, repo):
# Check for shelve file at old location first
@@ -579,7 +565,18 @@ def unshelve(ui, repo, **opts):
patch_diff = repo.opener(shelfpath).read()
fp = cStringIO.StringIO(patch_diff)
if opts['inspect']:
- ui.status(fp.getvalue())
+ # wrap ui.write so diff output can be labeled/colorized
+ def wrapwrite(orig, *args, **kw):
+ label = kw.pop('label', '')
+ if label: label += ' '
+ for chunk, l in patch.difflabel(lambda: args):
+ orig(chunk, label=label + l)
+ oldwrite = ui.write
+ extensions.wrapfunction(ui, 'write', wrapwrite)
+ try:
+ ui.status(fp.getvalue())
+ finally:
+ ui.write = oldwrite
else:
files = []
ac = parsepatch(fp)
@@ -594,7 +591,7 @@ def unshelve(ui, repo, **opts):
try:
try:
fp.seek(0)
- internalpatch(fp, ui, 1, repo.root)
+ patch.internalpatch(ui, repo, fp, 1)
patchdone = 1
except:
if opts['force']:
@@ -618,23 +615,6 @@ def unshelve(ui, repo, **opts):
ui.status("unshelve completed\n")
except IOError:
ui.warn('nothing to unshelve\n')
-
-_ui = None
-
-def uisetup(ui):
- # FIXME: no ui object passed to extsetup()?
- global _ui
- _ui = ui
-
-
-def extsetup():
- try:
- # enable color diff in shelve command via Color extension
- color = extensions.find('color')
- color._setupcmd(_ui, 'shelve', cmdtable, color.colordiff,
- color._diff_effects)
- except KeyError:
- pass
cmdtable = {
"shelve":