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()
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()
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()
# 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, [ 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):
# independently def empty_diff(*args, **kwargs): return [] 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()