Example #1
0
    def single(rev, seqno, fp):
        ctx = repo[rev]
        node = ctx.node()
        parents = [p.node() for p in ctx.parents() if p]
        branch = ctx.branch()
        if switch_parent:
            parents.reverse()
        prev = (parents and parents[0]) or nullid

        shouldclose = False
        if not fp:
            fp = make_file(repo, template, node, total=total, seqno=seqno,
                           revwidth=revwidth, mode='ab')
            if fp != template:
                shouldclose = True
        if fp != sys.stdout and hasattr(fp, 'name'):
            repo.ui.note("%s\n" % fp.name)

        fp.write("# HG changeset patch\n")
        fp.write("# User %s\n" % ctx.user())
        fp.write("# Date %d %d\n" % ctx.date())
        if branch and branch != 'default':
            fp.write("# Branch %s\n" % branch)
        fp.write("# Node ID %s\n" % hex(node))
        fp.write("# Parent  %s\n" % hex(prev))
        if len(parents) > 1:
            fp.write("# Parent  %s\n" % hex(parents[1]))
        fp.write(ctx.description().rstrip())
        fp.write("\n\n")

        for chunk in patch.diff(repo, prev, node, opts=opts):
            fp.write(chunk)

        if shouldclose:
            fp.close()
Example #2
0
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
                   changes=None, stat=False, fp=None, prefix='',
                   listsubrepos=False):
    '''show diff or diffstat.'''
    if fp is None:
        write = ui.write
    else:
        def write(s, **kw):
            fp.write(s)

    if stat:
        diffopts = diffopts.copy(context=0)
        width = 80
        if not ui.plain():
            width = ui.termwidth()
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
                            prefix=prefix)
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                             width=width,
                                             git=diffopts.git):
            write(chunk, label=label)
    else:
        for chunk, label in patch.diffui(repo, node1, node2, match,
                                         changes, diffopts, prefix=prefix):
            write(chunk, label=label)

    if listsubrepos:
        ctx1 = repo[node1]
        ctx2 = repo[node2]
        for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
            if node2 is not None:
                node2 = ctx2.substate[subpath][1]
            submatch = matchmod.narrowmatcher(subpath, match)
            sub.diff(diffopts, node2, submatch, changes=changes,
                     stat=stat, fp=fp, prefix=prefix)
 def diff(self, ctx2=None, match=None, **opts):
     """Returns a diff generator for the given contexts and matcher"""
     if ctx2 is None:
         ctx2 = self.p1()
     if ctx2 is not None and not isinstance(ctx2, changectx):
         ctx2 = self._repo[ctx2]
     diffopts = patch.diffopts(self._repo.ui, opts)
     return patch.diff(self._repo, ctx2.node(), self.node(), match=match, opts=diffopts)
Example #4
0
 def showpatch(self, node):
     if self.patch:
         prev = self.repo.changelog.parents(node)[0]
         chunks = patch.diff(self.repo, prev, node, match=self.patch,
                             opts=patch.diffopts(self.ui, self.diffopts))
         for chunk in chunks:
             self.ui.write(chunk)
         self.ui.write("\n")
Example #5
0
def showdiffstat(repo, ctx, templ, **args):
    diff = patch.diff(repo, ctx.parents()[0].node(), ctx.node())
    files, adds, removes = 0, 0, 0
    for i in patch.diffstatdata(util.iterlines(diff)):
        files += 1
        adds += i[1]
        removes += i[2]
    return '%s: +%s/-%s' % (files, adds, removes)
Example #6
0
 def diff(self, ctx2=None, match=None, **opts):
     """Returns a diff generator for the given contexts and matcher"""
     if ctx2 is None:
         ctx2 = self.p1()
     if ctx2 is not None and not isinstance(ctx2, changectx):
         ctx2 = self._repo[ctx2]
     diffopts = patch.diffopts(self._repo.ui, opts)
     return patch.diff(self._repo,
                       ctx2.node(),
                       self.node(),
                       match=match,
                       opts=diffopts)
    def single(rev, seqno, fp):
        ctx = repo[rev]
        node = ctx.node()
        parents = [p.node() for p in ctx.parents() if p]
        branch = ctx.branch()
        if switch_parent:
            parents.reverse()
        prev = (parents and parents[0]) or nullid

        shouldclose = False
        if not fp:
            desc_lines = ctx.description().rstrip().split('\n')
            desc = desc_lines[0]  #Commit always has a first line.
            fp = makefileobj(repo,
                             template,
                             node,
                             desc=desc,
                             total=total,
                             seqno=seqno,
                             revwidth=revwidth,
                             mode='ab')
            if fp != template:
                shouldclose = True
        if fp != sys.stdout and util.safehasattr(fp, 'name'):
            repo.ui.note("%s\n" % fp.name)

        fp.write("# HG changeset patch\n")
        fp.write("# User %s\n" % ctx.user())
        fp.write("# Date %d %d\n" % ctx.date())
        if branch and branch != 'default':
            fp.write("# Branch %s\n" % branch)
        fp.write("# Node ID %s\n" % hex(node))
        fp.write("# Parent  %s\n" % hex(prev))
        if len(parents) > 1:
            fp.write("# Parent  %s\n" % hex(parents[1]))
        fp.write(ctx.description().rstrip())
        fp.write("\n\n")

        for chunk in patch.diff(repo, prev, node, opts=opts):
            fp.write(chunk)

        if shouldclose:
            fp.close()
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
                   changes=None, stat=False, fp=None, prefix='',
                   listsubrepos=False):
    '''show diff or diffstat.'''
    if fp is None:
        write = ui.write
    else:
        def write(s, **kw):
            fp.write(s)

    if stat:
        diffopts = diffopts.copy(context=0)
        width = 80
        if not ui.plain():
            width = ui.termwidth()
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
                            prefix=prefix)
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                             width=width,
                                             git=diffopts.git):
            write(chunk, label=label)
    else:
        for chunk, label in patch.diffui(repo, node1, node2, match,
                                         changes, diffopts, prefix=prefix):
            write(chunk, label=label)

    if listsubrepos:
        ctx1 = repo[node1]
        ctx2 = repo[node2]
        for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
            tempnode2 = node2
            try:
                if node2 is not None:
                    tempnode2 = ctx2.substate[subpath][1]
            except KeyError:
                # A subrepo that existed in node1 was deleted between node1 and
                # node2 (inclusive). Thus, ctx2's substate won't contain that
                # subpath. The best we can do is to ignore it.
                tempnode2 = None
            submatch = matchmod.narrowmatcher(subpath, match)
            sub.diff(diffopts, tempnode2, submatch, changes=changes,
                     stat=stat, fp=fp, prefix=prefix)
Example #9
0
 def showpatch(self, node):
     if self.patch:
         prev = self.repo.changelog.parents(node)[0]
         patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui,
                    opts=patch.diffopts(self.ui))
         self.ui.write("\n")