def getdiff(ctx, diffopts): """plain-text diff without header (user, commit message, etc)""" output = util.stringio() for chunk, _label in patch.diffui(ctx.repo(), ctx.p1().node(), ctx.node(), None, opts=diffopts): output.write(chunk) return output.getvalue()
def __init__(self, part): # copy "public properties" self.type = part.type self.id = part.id self.mandatory = part.mandatory self.mandatoryparams = part.mandatoryparams self.advisoryparams = part.advisoryparams self.params = part.params self.mandatorykeys = part.mandatorykeys # copy the buffer self._io = util.stringio(part.read())
def _formatflags(ui, repo, rev, flags): """build flag string optionally by template""" tmpl = ui.config('patchbomb', 'flagtemplate') if not tmpl: return ' '.join(flags) out = util.stringio() opts = {'template': templater.unquotestring(tmpl)} with formatter.templateformatter(ui, out, 'patchbombflag', opts) as fm: fm.startitem() fm.context(ctx=repo[rev]) fm.write('flags', '%s', fm.formatlist(flags, name='flag')) return out.getvalue()
def _formatflags(ui, repo, rev, flags): """build flag string optionally by template""" tmpl = ui.config(b'patchbomb', b'flagtemplate') if not tmpl: return b' '.join(flags) out = util.stringio() spec = formatter.literal_templatespec(templater.unquotestring(tmpl)) with formatter.templateformatter(ui, out, b'patchbombflag', {}, spec) as fm: fm.startitem() fm.context(ctx=repo[rev]) fm.write(b'flags', b'%s', fm.formatlist(flags, name=b'flag')) return out.getvalue()
def _parsechunk(hunk): """(crecord.uihunk or patch.recordhunk) -> (path, (a1, a2, [bline]))""" if type(hunk) not in (crecord.uihunk, patch.recordhunk): return None, None path = hunk.header.filename() a1 = hunk.fromline + len(hunk.before) - 1 # remove before and after context hunk.before = hunk.after = [] buf = util.stringio() hunk.write(buf) patchlines = mdiff.splitnewlines(buf.getvalue()) # hunk.prettystr() will update hunk.removed a2 = a1 + hunk.removed blines = [l[1:] for l in patchlines[1:] if l[0] != '-'] return path, (a1, a2, blines)
def _parsechunk(hunk): """(crecord.uihunk or patch.recordhunk) -> (path, (a1, a2, [bline]))""" if type(hunk) not in (crecord.uihunk, patch.recordhunk): return None, None path = hunk.header.filename() a1 = hunk.fromline + len(hunk.before) - 1 # remove before and after context hunk.before = hunk.after = [] buf = util.stringio() hunk.write(buf) patchlines = mdiff.splitnewlines(buf.getvalue()) # hunk.prettystr() will update hunk.removed a2 = a1 + hunk.removed blines = [l[1:] for l in patchlines[1:] if not l.startswith(b'-')] return path, (a1, a2, blines)
def split_lines(t): return util.stringio(t).readlines()