Example #1
0
def listcmd(ui, repo, pats, opts):
    """subcommand that displays the list of shelves"""
    pats = set(pats)
    width = 80
    if not ui.plain():
        width = ui.termwidth()
    namelabel = 'shelve.newest'
    for mtime, name in listshelves(repo):
        sname = util.split(name)[1]
        if pats and sname not in pats:
            continue
        ui.write(sname, label=namelabel)
        namelabel = 'shelve.name'
        if ui.quiet:
            ui.write('\n')
            continue
        ui.write(' ' * (16 - len(sname)))
        used = 16
        age = '(%s)' % templatefilters.age(util.makedate(mtime), abbrev=True)
        ui.write(age, label='shelve.age')
        ui.write(' ' * (12 - len(age)))
        used += 12
        fp = open(name + '.patch', 'rb')
        try:
            while True:
                line = fp.readline()
                if not line:
                    break
                if not line.startswith('#'):
                    desc = line.rstrip()
                    if ui.formatted():
                        desc = util.ellipsis(desc, width - used)
                    ui.write(desc)
                    break
            ui.write('\n')
            if not (opts['patch'] or opts['stat']):
                continue
            difflines = fp.readlines()
            if opts['patch']:
                for chunk, label in patch.difflabel(iter, difflines):
                    ui.write(chunk, label=label)
            if opts['stat']:
                for chunk, label in patch.diffstatui(difflines,
                                                     width=width,
                                                     git=True):
                    ui.write(chunk, label=label)
        finally:
            fp.close()
Example #2
0
def listcmd(ui, repo, pats, opts):
    """subcommand that displays the list of shelves"""
    pats = set(pats)
    width = 80
    if not ui.plain():
        width = ui.termwidth()
    namelabel = 'shelve.newest'
    for mtime, name in listshelves(repo):
        sname = util.split(name)[1]
        if pats and sname not in pats:
            continue
        ui.write(sname, label=namelabel)
        namelabel = 'shelve.name'
        if ui.quiet:
            ui.write('\n')
            continue
        ui.write(' ' * (16 - len(sname)))
        used = 16
        age = '(%s)' % templatefilters.age(util.makedate(mtime), abbrev=True)
        ui.write(age, label='shelve.age')
        ui.write(' ' * (12 - len(age)))
        used += 12
        fp = open(name + '.patch', 'rb')
        try:
            while True:
                line = fp.readline()
                if not line:
                    break
                if not line.startswith('#'):
                    desc = line.rstrip()
                    if ui.formatted():
                        desc = util.ellipsis(desc, width - used)
                    ui.write(desc)
                    break
            ui.write('\n')
            if not (opts['patch'] or opts['stat']):
                continue
            difflines = fp.readlines()
            if opts['patch']:
                for chunk, label in patch.difflabel(iter, difflines):
                    ui.write(chunk, label=label)
            if opts['stat']:
                for chunk, label in patch.diffstatui(difflines, width=width,
                                                     git=True):
                    ui.write(chunk, label=label)
        finally:
            fp.close()
Example #3
0
def qshow(ui, repo, patchspec=None, **opts):
    '''display a patch

    If no patch is given, the top of the applied stack is shown.'''

    patchf = resolve_patchfile(ui, repo, patchspec)

    if patchf is None:
        # commands.diff has a bad error message
        if patchspec is None:
            patchspec = '.'
        if patchspec not in repo and not repo.revs(patchspec).first():
            raise util.Abort(_("Unknown patch '%s'") % patchspec)

        # the built-in export command does not label the diff for color
        # output, and the patch header generation is not reusable
        # independently
        def empty_diff(*args, **kwargs):
            return []

        temp = patch.diff
        try:
            patch.diff = empty_diff
            cmdutil.export(repo, repo.revs(patchspec), fp=ui)
        finally:
            patch.diff = temp

        return commands.diff(ui, repo, change=patchspec, date=None, **opts)

    if opts['stat']:
        del opts['stat']
        lines = patch.diffstatui(patchf, **opts)
    else:

        def singlefile(*a, **b):
            return patchf

        lines = patch.difflabel(singlefile, **opts)

    for chunk, label in lines:
        ui.write(chunk, label=label)

    patchf.close()
Example #4
0
 def showDiff(self, index):
     'User selected a row in the candidate tree'
     indexes = index.indexes()
     if not indexes:
         return
     index = indexes[0]
     ctx = self.repo['.']
     hu = htmlui.htmlui()
     row = self.matchtv.model().getRow(index)
     src, dest, percent = self.matchtv.model().getRow(index)
     aa = self.repo.wread(dest)
     rr = ctx.filectx(src).data()
     date = hglib.displaytime(ctx.date())
     difftext = mdiff.unidiff(rr, date, aa, date, src, dest, None)
     if not difftext:
         t = _('%s and %s have identical contents\n\n') % \
                 (hglib.tounicode(src), hglib.tounicode(dest))
         hu.write(t, label='ui.error')
     else:
         for t, l in patch.difflabel(difftext.splitlines, True):
             hu.write(t, label=l)
     self.difftb.setHtml(hu.getdata()[0])
Example #5
0
 def showDiff(self, index):
     'User selected a row in the candidate tree'
     indexes = index.indexes()
     if not indexes:
         return
     index = indexes[0]
     ctx = self.repo['.']
     hu = htmlui.htmlui()
     row = self.matchtv.model().getRow(index)
     src, dest, percent = self.matchtv.model().getRow(index)
     aa = self.repo.wread(dest)
     rr = ctx.filectx(src).data()
     date = hglib.displaytime(ctx.date())
     difftext = mdiff.unidiff(rr, date, aa, date, src, dest, None)
     if not difftext:
         t = _('%s and %s have identical contents\n\n') % \
                 (hglib.tounicode(src), hglib.tounicode(dest))
         hu.write(t, label='ui.error')
     else:
         for t, l in patch.difflabel(difftext.splitlines, True):
             hu.write(t, label=l)
     self.difftb.setHtml(hu.getdata()[0])
Example #6
0
 def wrapwrite(orig, *args, **kw):
     label = kw.pop("label", "")
     for chunk, l in patch.difflabel(lambda: args):
         orig(chunk, label=label + l)
Example #7
0
                temp = patch.diff
                try:
                    patch.diff = empty_diff
                    cmdutil.export(repo, [ patchspec ], fp=ui)
                finally:
                    patch.diff = temp

                return commands.diff(ui, repo, change=patchspec, date=None)

    if opts['stat']:
        del opts['stat']
        lines = patch.diffstatui(patchf, **opts)
    else:
        def singlefile(*a, **b):
            return patchf
        lines = patch.difflabel(singlefile, **opts)

    for chunk, label in lines:
        ui.write(chunk, label=label)

    patchf.close()

def fullpaths(ui, repo, paths):
    cwd = os.getcwd()
    return [ canonpath(repo.root, cwd, path) for path in paths ]

def patch_changes(ui, repo, patchfile=None, **opts):
    '''Given a patch, look at what files it changes, and map a function over
    the changesets that touch overlapping files.

    Scan through the last LIMIT commits to find the relevant changesets
Example #8
0
 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)
Example #9
0
                    patch.diff = empty_diff
                    cmdutil.export(repo, [patchspec], fp=ui)
                finally:
                    patch.diff = temp

                return commands.diff(ui, repo, change=patchspec, date=None)

    if opts['stat']:
        del opts['stat']
        lines = patch.diffstatui(patchf, **opts)
    else:

        def singlefile(*a, **b):
            return patchf

        lines = patch.difflabel(singlefile, **opts)

    for chunk, label in lines:
        ui.write(chunk, label=label)

    patchf.close()


def fullpaths(ui, repo, paths):
    cwd = os.getcwd()
    return [canonpath(repo.root, cwd, path) for path in paths]


def patch_changes(ui, repo, patchfile=None, **opts):
    '''Given a patch, look at what files it changes, and map a function over
    the changesets that touch overlapping files.
 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)
Example #11
0
 def write_colored(ui, diff):
     for output, label in patch.difflabel(lambda: diff):
         ui.write(output, label=label)