comparison hgext/hgk.py @ 34998:fc0e6d298cd4

py3: handle keyword arguments in hgext/hgk.py Differential Revision: https://phab.mercurial-scm.org/D1317
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 23 Oct 2017 00:03:27 +0530
parents b8f74c4d188f
children 1c4247b0040a
comparison
equal deleted inserted replaced
34997:0c9ba2ac60a8 34998:fc0e6d298cd4
46 ) 46 )
47 from mercurial import ( 47 from mercurial import (
48 commands, 48 commands,
49 obsolete, 49 obsolete,
50 patch, 50 patch,
51 pycompat,
51 registrar, 52 registrar,
52 scmutil, 53 scmutil,
53 util, 54 util,
54 ) 55 )
55 56
77 ('S', 'search', "", _('search'))], 78 ('S', 'search', "", _('search'))],
78 ('[OPTION]... NODE1 NODE2 [FILE]...'), 79 ('[OPTION]... NODE1 NODE2 [FILE]...'),
79 inferrepo=True) 80 inferrepo=True)
80 def difftree(ui, repo, node1=None, node2=None, *files, **opts): 81 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
81 """diff trees from two commits""" 82 """diff trees from two commits"""
83
82 def __difftree(repo, node1, node2, files=None): 84 def __difftree(repo, node1, node2, files=None):
83 assert node2 is not None 85 assert node2 is not None
84 if files is None: 86 if files is None:
85 files = [] 87 files = []
86 mmap = repo[node1].manifest() 88 mmap = repo[node1].manifest()
100 ui.write((":100664 000000 %s %s D\t%s\t%s\n") % 102 ui.write((":100664 000000 %s %s D\t%s\t%s\n") %
101 (short(mmap[f]), empty, f, f)) 103 (short(mmap[f]), empty, f, f))
102 ## 104 ##
103 105
104 while True: 106 while True:
105 if opts['stdin']: 107 if opts[r'stdin']:
106 try: 108 try:
107 line = util.bytesinput(ui.fin, ui.fout).split(' ') 109 line = util.bytesinput(ui.fin, ui.fout).split(' ')
108 node1 = line[0] 110 node1 = line[0]
109 if len(line) > 1: 111 if len(line) > 1:
110 node2 = line[1] 112 node2 = line[1]
116 if node2: 118 if node2:
117 node2 = repo.lookup(node2) 119 node2 = repo.lookup(node2)
118 else: 120 else:
119 node2 = node1 121 node2 = node1
120 node1 = repo.changelog.parents(node1)[0] 122 node1 = repo.changelog.parents(node1)[0]
121 if opts['patch']: 123 if opts[r'patch']:
122 if opts['pretty']: 124 if opts[r'pretty']:
123 catcommit(ui, repo, node2, "") 125 catcommit(ui, repo, node2, "")
124 m = scmutil.match(repo[node1], files) 126 m = scmutil.match(repo[node1], files)
125 diffopts = patch.difffeatureopts(ui) 127 diffopts = patch.difffeatureopts(ui)
126 diffopts.git = True 128 diffopts.git = True
127 chunks = patch.diff(repo, node1, node2, match=m, 129 chunks = patch.diff(repo, node1, node2, match=m,
128 opts=diffopts) 130 opts=diffopts)
129 for chunk in chunks: 131 for chunk in chunks:
130 ui.write(chunk) 132 ui.write(chunk)
131 else: 133 else:
132 __difftree(repo, node1, node2, files=files) 134 __difftree(repo, node1, node2, files=files)
133 if not opts['stdin']: 135 if not opts[r'stdin']:
134 break 136 break
135 137
136 def catcommit(ui, repo, n, prefix, ctx=None): 138 def catcommit(ui, repo, n, prefix, ctx=None):
137 nlprefix = '\n' + prefix 139 nlprefix = '\n' + prefix
138 if ctx is None: 140 if ctx is None:
181 # in stdin mode, every line except the commit is prefixed with two 183 # in stdin mode, every line except the commit is prefixed with two
182 # spaces. This way the our caller can find the commit without magic 184 # spaces. This way the our caller can find the commit without magic
183 # strings 185 # strings
184 # 186 #
185 prefix = "" 187 prefix = ""
186 if opts['stdin']: 188 if opts[r'stdin']:
187 try: 189 try:
188 (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') 190 (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ')
189 prefix = " " 191 prefix = " "
190 except EOFError: 192 except EOFError:
191 return 193 return
199 if type != "commit": 201 if type != "commit":
200 ui.warn(_("aborting hg cat-file only understands commits\n")) 202 ui.warn(_("aborting hg cat-file only understands commits\n"))
201 return 1 203 return 1
202 n = repo.lookup(r) 204 n = repo.lookup(r)
203 catcommit(ui, repo, n, prefix) 205 catcommit(ui, repo, n, prefix)
204 if opts['stdin']: 206 if opts[r'stdin']:
205 try: 207 try:
206 (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ') 208 (type, r) = util.bytesinput(ui.fin, ui.fout).split(' ')
207 except EOFError: 209 except EOFError:
208 break 210 break
209 else: 211 else:
338 if opts['header']: 340 if opts['header']:
339 full = "commit" 341 full = "commit"
340 else: 342 else:
341 full = None 343 full = None
342 copy = [x for x in revs] 344 copy = [x for x in revs]
343 revtree(ui, copy, repo, full, opts['max_count'], opts['parents']) 345 revtree(ui, copy, repo, full, opts[r'max_count'], opts[r'parents'])
344 346
345 @command('view', 347 @command('view',
346 [('l', 'limit', '', 348 [('l', 'limit', '',
347 _('limit number of changes displayed'), _('NUM'))], 349 _('limit number of changes displayed'), _('NUM'))],
348 _('[-l LIMIT] [REVRANGE]')) 350 _('[-l LIMIT] [REVRANGE]'))
349 def view(ui, repo, *etc, **opts): 351 def view(ui, repo, *etc, **opts):
350 "start interactive history viewer" 352 "start interactive history viewer"
353 opts = pycompat.byteskwargs(opts)
351 os.chdir(repo.root) 354 os.chdir(repo.root)
352 optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v]) 355 optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
353 if repo.filtername is None: 356 if repo.filtername is None:
354 optstr += '--hidden' 357 optstr += '--hidden'
355 358