diff options
Diffstat (limited to 'hgext/record.py')
-rw-r--r-- | hgext/record.py | 101 |
1 files changed, 18 insertions, 83 deletions
diff --git a/hgext/record.py b/hgext/record.py index ec9e384..1bbfb11 100644 --- a/hgext/record.py +++ b/hgext/record.py @@ -14,7 +14,6 @@ import copy, cStringIO, errno, os, re, shutil, tempfile cmdtable = {} command = cmdutil.command(cmdtable) -testedwith = 'internal' lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)') @@ -262,7 +261,7 @@ def parsepatch(fp): def filterpatch(ui, headers): """Interactively filter patch chunks into applied-only chunks""" - def prompt(skipfile, skipall, query, chunk): + def prompt(skipfile, skipall, query): """prompt query, and process base inputs - y/n for the rest of file @@ -272,16 +271,14 @@ def filterpatch(ui, headers): Return True/False and possibly updated skipfile and skipall. """ - newpatches = None if skipall is not None: - return skipall, skipfile, skipall, newpatches + return skipall, skipfile, skipall if skipfile is not None: - return skipfile, skipfile, skipall, newpatches + return skipfile, skipfile, skipall while True: - resps = _('[Ynesfdaq?]') + resps = _('[Ynsfdaq?]') choices = (_('&Yes, record this change'), _('&No, skip this change'), - _('&Edit the change manually'), _('&Skip remaining changes to this file'), _('Record remaining changes to this &file'), _('&Done, skip remaining changes and files'), @@ -290,7 +287,7 @@ def filterpatch(ui, headers): _('&?')) r = ui.promptchoice("%s %s" % (query, resps), choices) ui.write("\n") - if r == 8: # ? + if r == 7: # ? doc = gettext(record.__doc__) c = doc.find('::') + 2 for l in doc[c:].splitlines(): @@ -301,70 +298,17 @@ def filterpatch(ui, headers): ret = True elif r == 1: # no ret = False - elif r == 2: # Edit patch - if chunk is None: - ui.write(_('cannot edit patch for whole file')) - ui.write("\n") - continue - if chunk.header.binary(): - ui.write(_('cannot edit patch for binary file')) - ui.write("\n") - continue - # Patch comment based on the Git one (based on comment at end of - # http://mercurial.selenic.com/wiki/RecordExtension) - phelp = '---' + _(""" -To remove '-' lines, make them ' ' lines (context). -To remove '+' lines, delete them. -Lines starting with # will be removed from the patch. - -If the patch applies cleanly, the edited hunk will immediately be -added to the record list. If it does not apply cleanly, a rejects -file will be generated: you can use that when you try again. If -all lines of the hunk are removed, then the edit is aborted and -the hunk is left unchanged. -""") - (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-", - suffix=".diff", text=True) - ncpatchfp = None - try: - # Write the initial patch - f = os.fdopen(patchfd, "w") - chunk.header.write(f) - chunk.write(f) - f.write('\n'.join(['# ' + i for i in phelp.splitlines()])) - f.close() - # Start the editor and wait for it to complete - editor = ui.geteditor() - util.system("%s \"%s\"" % (editor, patchfn), - environ={'HGUSER': ui.username()}, - onerr=util.Abort, errprefix=_("edit failed"), - out=ui.fout) - # Remove comment lines - patchfp = open(patchfn) - ncpatchfp = cStringIO.StringIO() - for line in patchfp: - if not line.startswith('#'): - ncpatchfp.write(line) - patchfp.close() - ncpatchfp.seek(0) - newpatches = parsepatch(ncpatchfp) - finally: - os.unlink(patchfn) - del ncpatchfp - # Signal that the chunk shouldn't be applied as-is, but - # provide the new patch to be used instead. - ret = False - elif r == 3: # Skip + elif r == 2: # Skip ret = skipfile = False - elif r == 4: # file (Record remaining) + elif r == 3: # file (Record remaining) ret = skipfile = True - elif r == 5: # done, skip remaining + elif r == 4: # done, skip remaining ret = skipall = False - elif r == 6: # all + elif r == 5: # all ret = skipall = True - elif r == 7: # quit + elif r == 6: # quit raise util.Abort(_('user quit')) - return ret, skipfile, skipall, newpatches + return ret, skipfile, skipall seen = set() applied = {} # 'filename' -> [] of chunks @@ -381,8 +325,8 @@ the hunk is left unchanged. if skipall is None: h.pretty(ui) msg = (_('examine changes to %s?') % - _(' and ').join("'%s'" % f for f in h.files())) - r, skipfile, skipall, np = prompt(skipfile, skipall, msg, None) + _(' and ').join(map(repr, h.files()))) + r, skipfile, skipall = prompt(skipfile, skipall, msg) if not r: continue applied[h.filename()] = [h] @@ -398,19 +342,12 @@ the hunk is left unchanged. idx = pos - len(h.hunks) + i msg = _('record change %d/%d to %r?') % (idx, total, chunk.filename()) - r, skipfile, skipall, newpatches = prompt(skipfile, - skipall, msg, chunk) + r, skipfile, skipall = prompt(skipfile, skipall, msg) if r: if fixoffset: chunk = copy.copy(chunk) chunk.toline += fixoffset applied[chunk.filename()].append(chunk) - elif newpatches is not None: - for newpatch in newpatches: - for newhunk in newpatch.hunks: - if fixoffset: - newhunk.toline += fixoffset - applied[newhunk.filename()].append(newhunk) else: fixoffset += chunk.removed - chunk.added return sum([h for h in applied.itervalues() @@ -435,7 +372,6 @@ def record(ui, repo, *pats, **opts): y - record this change n - skip this change - e - edit this change manually s - skip remaining changes to this file f - record remaining changes to this file @@ -517,11 +453,10 @@ def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, *pats, **opts): '(use "hg commit" instead)')) changes = repo.status(match=match)[:3] - diffopts = mdiff.diffopts( - git=True, nodates=True, - ignorews=opts.get('ignore_all_space'), - ignorewsamount=opts.get('ignore_space_change'), - ignoreblanklines=opts.get('ignore_blank_lines')) + diffopts = mdiff.diffopts(git=True, nodates=True, + ignorews=opts.get('ignore_all_space'), + ignorewsamount=opts.get('ignore_space_change'), + ignoreblanklines=opts.get('ignore_blank_lines')) chunks = patch.diff(repo, changes=changes, opts=diffopts) fp = cStringIO.StringIO() fp.write(''.join(chunks)) |