Example #1
0
def touched(ui, repo, sourcefile=None, **opts):
    '''Show what files are touched by what patches

    If no file is given, print out a series of lines containing a
    patch and a file changed by that patch, for all files changed by
    all patches. This is mainly intended for easy grepping.

    If a file is given, print out the list of patches that touch that file.'''

    q = repo.mq

    if opts['patch'] and opts['applied']:
        raise error.Abort(_('Cannot use both -a and -p options'))

    if opts['patch']:
        patches = [ q.lookup(opts['patch']) ]
    elif opts['applied']:
        patches = [ p.name for p in q.applied ]
    else:
        patches = q.series

    for patchname in [ q.lookup(p) for p in patches ]:
        lines = q.opener(patchname)
        for filename, adds, removes, isbinary in patch.diffstatdata(lines):
            if sourcefile is None:
                ui.write(patchname + "\t" + filename + "\n")
            elif sourcefile == filename:
                ui.write(patchname + "\n")
Example #2
0
def touched(ui, repo, sourcefile=None, **opts):
    '''Show what files are touched by what patches

    If no file is given, print out a series of lines containing a
    patch and a file changed by that patch, for all files changed by
    all patches. This is mainly intended for easy grepping.

    If a file is given, print out the list of patches that touch that file.'''

    q = repo.mq

    if opts['patch'] and opts['applied']:
        raise util.Abort(_('Cannot use both -a and -p options'))

    if opts['patch']:
        patches = [ q.lookup(opts['patch']) ]
    elif opts['applied']:
        patches = [ p.name for p in q.applied ]
    else:
        patches = q.series

    for patchname in [ q.lookup(p) for p in patches ]:
        lines = q.opener(patchname)
        for filename, adds, removes, isbinary in patch.diffstatdata(lines):
            if sourcefile is None:
                ui.write(patchname + "\t" + filename + "\n")
            elif sourcefile == filename:
                ui.write(patchname + "\n")
Example #3
0
def diffstatgen(ctx, basectx):
    '''Generator function that provides the diffstat data.'''

    stats = patch.diffstatdata(util.iterlines(ctx.diff(basectx)))
    maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
    while True:
        yield stats, maxname, maxtotal, addtotal, removetotal, binary
Example #4
0
def diffstatgen(ctx):
    '''Generator function that provides the diffstat data.'''

    stats = patch.diffstatdata(util.iterlines(ctx.diff()))
    maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
    while True:
        yield stats, maxname, maxtotal, addtotal, removetotal, binary
Example #5
0
def _file_changes(hg_ui, local_repo_path, commit):
    "Return FileChange instances for a commit"
    repo = hg.repository(hg_ui, path=local_repo_path)
    node2 = repo.lookup(commit.hash)
    node1 = repo[node2].parents()[0].node()
    lines = util.iterlines(patch.diff(repo, node1, node2))
    for f in patch.diffstatdata(lines):
        yield FileChange(f[0], commit.file_changes[f[0]], f[1], f[2], f[3])
Example #6
0
 def __iter__(self):
     for item in self.stream:
         ctx = item.ctx
         if len(ctx.parents()) < 2:
             p = ''.join(patch.diff(ctx._repo, ctx.p1().node(), ctx.node()))
             lines = p.split('\n')
             stats = sum(map(self.delta_function, patch.diffstatdata(lines)))
             yield item.child(x=ctx.date()[0], y=stats)
Example #7
0
def getShortStat(obj, node1, node2):  ## SLOW FIXME
    repo = obj.repo
    ## if not node1 ## FIXME
    stats = diffstatdata(iterlines(diff(
        repo,
        str(node1),
        str(node2),
    )))
    maxname, maxtotal, insertions, deletions, hasbinary = diffstatsum(stats)
    return len(stats), insertions, deletions
Example #8
0
def getShortStat(obj, node1, node2):## SLOW FIXME
    repo = obj.repo
    ## if not node1 ## FIXME
    stats = diffstatdata(
        iterlines(
            diff(
                repo,
                str(node1),
                str(node2),
            )
        )
    )
    maxname, maxtotal, insertions, deletions, hasbinary = diffstatsum(stats)
    return len(stats), insertions, deletions
Example #9
0
def diffcmd(orig, ui, repo, *args, **opts):
    if not opts.get('per_file_stat_json'):
        return orig(ui, repo, *args, **opts)

    ui.pushbuffer()
    res = orig(ui, repo, *args, **opts)
    buffer = ui.popbuffer()
    difflines = util.iterlines([buffer])
    diffstat = patch.diffstatdata(difflines)
    output = {}
    for filename, adds, removes, isbinary in diffstat:
        # use special encoding that allows non-utf8 filenames
        filename = encoding.jsonescape(filename, paranoid=True)
        output[filename] = {
            'adds': adds, 'removes': removes, 'isbinary': isbinary,
        }
    ui.write('%s\n' % (json.dumps(output, sort_keys=True)))
    return res