comparison hgext/hgk.py @ 3093:edefbb3a3b08

hgk: add --limit, and revranges
author Brendan Cully <brendan@kublai.com>
date Wed, 13 Sep 2006 18:24:58 -0700
parents d0fcce3728d1
children eb0906ebba81
comparison
equal deleted inserted replaced
3092:d0fcce3728d1 3093:edefbb3a3b08
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from mercurial.demandload import * 8 from mercurial.demandload import *
9 demandload(globals(), 'time sys signal os') 9 demandload(globals(), 'time sys signal os')
10 demandload(globals(), 'mercurial:hg,fancyopts,commands,ui,util,patch') 10 demandload(globals(), 'mercurial:hg,fancyopts,commands,ui,util,patch,revlog')
11 11
12 def difftree(ui, repo, node1=None, node2=None, *files, **opts): 12 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
13 """diff trees from two commits""" 13 """diff trees from two commits"""
14 def __difftree(repo, node1, node2, files=[]): 14 def __difftree(repo, node1, node2, files=[]):
15 if node2: 15 if node2:
215 if p in stop_sha1: 215 if p in stop_sha1:
216 continue 216 continue
217 217
218 # walk the repository looking for commits that are in our 218 # walk the repository looking for commits that are in our
219 # reachability graph 219 # reachability graph
220 #for i in range(repo.changelog.count()-1, -1, -1):
221 for i, changes in chlogwalk(): 220 for i, changes in chlogwalk():
222 n = repo.changelog.node(i) 221 n = repo.changelog.node(i)
223 mask = is_reachable(want_sha1, reachable, n) 222 mask = is_reachable(want_sha1, reachable, n)
224 if mask: 223 if mask:
225 parentstr = "" 224 parentstr = ""
250 print "" 249 print ""
251 if maxnr and count >= maxnr: 250 if maxnr and count >= maxnr:
252 break 251 break
253 count += 1 252 count += 1
254 253
254 def revparse(ui, repo, *revs, **opts):
255 """Parse given revisions"""
256 def revstr(rev):
257 if rev == 'HEAD':
258 rev = 'tip'
259 return revlog.hex(repo.lookup(rev))
260
261 for r in revs:
262 revrange = r.split(':', 1)
263 ui.write('%s\n' % revstr(revrange[0]))
264 if len(revrange) == 2:
265 ui.write('^%s\n' % revstr(revrange[1]))
266
255 # git rev-list tries to order things by date, and has the ability to stop 267 # git rev-list tries to order things by date, and has the ability to stop
256 # at a given commit without walking the whole repo. TODO add the stop 268 # at a given commit without walking the whole repo. TODO add the stop
257 # parameter 269 # parameter
258 def revlist(ui, repo, *revs, **opts): 270 def revlist(ui, repo, *revs, **opts):
259 """print revisions""" 271 """print revisions"""
262 else: 274 else:
263 full = None 275 full = None
264 copy = [x for x in revs] 276 copy = [x for x in revs]
265 revtree(copy, repo, full, opts['max_count'], opts['parents']) 277 revtree(copy, repo, full, opts['max_count'], opts['parents'])
266 278
267 def view(ui, repo, *etc): 279 def view(ui, repo, *etc, **opts):
268 "start interactive history viewer" 280 "start interactive history viewer"
269 os.chdir(repo.root) 281 os.chdir(repo.root)
270 os.system(ui.config("hgk", "path", "hgk") + " " + " ".join(etc)) 282 optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems()])
283 os.system(ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc)))
271 284
272 cmdtable = { 285 cmdtable = {
273 "view": (view, [], 'hg view'), 286 "view": (view,
287 [('l', 'limit', '', 'limit number of changes displayed')],
288 'hg view [-l LIMIT] [REVRANGE]'),
274 "debug-diff-tree": (difftree, [('p', 'patch', None, 'generate patch'), 289 "debug-diff-tree": (difftree, [('p', 'patch', None, 'generate patch'),
275 ('r', 'recursive', None, 'recursive'), 290 ('r', 'recursive', None, 'recursive'),
276 ('P', 'pretty', None, 'pretty'), 291 ('P', 'pretty', None, 'pretty'),
277 ('s', 'stdin', None, 'stdin'), 292 ('s', 'stdin', None, 'stdin'),
278 ('C', 'copy', None, 'detect copies'), 293 ('C', 'copy', None, 'detect copies'),
279 ('S', 'search', "", 'search')], 294 ('S', 'search', "", 'search')],
280 "hg git-diff-tree [options] node1 node2 [files...]"), 295 "hg git-diff-tree [options] node1 node2 [files...]"),
281 "debug-cat-file": (catfile, [('s', 'stdin', None, 'stdin')], 296 "debug-cat-file": (catfile, [('s', 'stdin', None, 'stdin')],
282 "hg debug-cat-file [options] type file"), 297 "hg debug-cat-file [options] type file"),
283 "debug-merge-base": (base, [], "hg debug-merge-base node node"), 298 "debug-merge-base": (base, [], "hg debug-merge-base node node"),
299 'debug-rev-parse': (revparse,
300 [('', 'default', '', 'ignored')],
301 "hg debug-rev-parse rev"),
284 "debug-rev-list": (revlist, [('H', 'header', None, 'header'), 302 "debug-rev-list": (revlist, [('H', 'header', None, 'header'),
285 ('t', 'topo-order', None, 'topo-order'), 303 ('t', 'topo-order', None, 'topo-order'),
286 ('p', 'parents', None, 'parents'), 304 ('p', 'parents', None, 'parents'),
287 ('n', 'max-count', 0, 'max-count')], 305 ('n', 'max-count', 0, 'max-count')],
288 "hg debug-rev-list [options] revs"), 306 "hg debug-rev-list [options] revs"),