hgext/hgk.py
changeset 21250 8d354d58147c
parent 18816 7f7d5f8a8f15
child 21783 82bf4d89e068
equal deleted inserted replaced
21249:2b8697e20978 21250:8d354d58147c
    33 Revisions context menu will now display additional entries to fire
    33 Revisions context menu will now display additional entries to fire
    34 vdiff on hovered and selected revisions.
    34 vdiff on hovered and selected revisions.
    35 '''
    35 '''
    36 
    36 
    37 import os
    37 import os
    38 from mercurial import commands, util, patch, revlog, scmutil
    38 from mercurial import cmdutil, commands, util, patch, revlog, scmutil
    39 from mercurial.node import nullid, nullrev, short
    39 from mercurial.node import nullid, nullrev, short
    40 from mercurial.i18n import _
    40 from mercurial.i18n import _
    41 
    41 
       
    42 cmdtable = {}
       
    43 command = cmdutil.command(cmdtable)
    42 testedwith = 'internal'
    44 testedwith = 'internal'
    43 
    45 
       
    46 @command('debug-diff-tree',
       
    47     [('p', 'patch', None, _('generate patch')),
       
    48     ('r', 'recursive', None, _('recursive')),
       
    49     ('P', 'pretty', None, _('pretty')),
       
    50     ('s', 'stdin', None, _('stdin')),
       
    51     ('C', 'copy', None, _('detect copies')),
       
    52     ('S', 'search', "", _('search'))],
       
    53     ('hg git-diff-tree [OPTION]... NODE1 NODE2 [FILE]...'))
    44 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
    54 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
    45     """diff trees from two commits"""
    55     """diff trees from two commits"""
    46     def __difftree(repo, node1, node2, files=[]):
    56     def __difftree(repo, node1, node2, files=[]):
    47         assert node2 is not None
    57         assert node2 is not None
    48         mmap = repo[node1].manifest()
    58         mmap = repo[node1].manifest()
   123     else:
   133     else:
   124         ui.write(description + "\n")
   134         ui.write(description + "\n")
   125     if prefix:
   135     if prefix:
   126         ui.write('\0')
   136         ui.write('\0')
   127 
   137 
       
   138 @command('debug-merge-base', [], _('hg debug-merge-base REV REV'))
   128 def base(ui, repo, node1, node2):
   139 def base(ui, repo, node1, node2):
   129     """output common ancestor information"""
   140     """output common ancestor information"""
   130     node1 = repo.lookup(node1)
   141     node1 = repo.lookup(node1)
   131     node2 = repo.lookup(node2)
   142     node2 = repo.lookup(node2)
   132     n = repo.changelog.ancestor(node1, node2)
   143     n = repo.changelog.ancestor(node1, node2)
   133     ui.write(short(n) + "\n")
   144     ui.write(short(n) + "\n")
   134 
   145 
       
   146 @command('debug-cat-file',
       
   147     [('s', 'stdin', None, _('stdin'))],
       
   148     _('hg debug-cat-file [OPTION]... TYPE FILE'))
   135 def catfile(ui, repo, type=None, r=None, **opts):
   149 def catfile(ui, repo, type=None, r=None, **opts):
   136     """cat a specific revision"""
   150     """cat a specific revision"""
   137     # in stdin mode, every line except the commit is prefixed with two
   151     # in stdin mode, every line except the commit is prefixed with two
   138     # spaces.  This way the our caller can find the commit without magic
   152     # spaces.  This way the our caller can find the commit without magic
   139     # strings
   153     # strings
   274                 ui.write("\n")
   288                 ui.write("\n")
   275             if maxnr and count >= maxnr:
   289             if maxnr and count >= maxnr:
   276                 break
   290                 break
   277             count += 1
   291             count += 1
   278 
   292 
       
   293 @command('debug-rev-parse',
       
   294     [('', 'default', '', _('ignored'))],
       
   295     _('hg debug-rev-parse REV'))
   279 def revparse(ui, repo, *revs, **opts):
   296 def revparse(ui, repo, *revs, **opts):
   280     """parse given revisions"""
   297     """parse given revisions"""
   281     def revstr(rev):
   298     def revstr(rev):
   282         if rev == 'HEAD':
   299         if rev == 'HEAD':
   283             rev = 'tip'
   300             rev = 'tip'
   290             ui.write('^%s\n' % revstr(revrange[1]))
   307             ui.write('^%s\n' % revstr(revrange[1]))
   291 
   308 
   292 # git rev-list tries to order things by date, and has the ability to stop
   309 # git rev-list tries to order things by date, and has the ability to stop
   293 # at a given commit without walking the whole repo.  TODO add the stop
   310 # at a given commit without walking the whole repo.  TODO add the stop
   294 # parameter
   311 # parameter
       
   312 @command('debug-rev-list',
       
   313     [('H', 'header', None, _('header')),
       
   314     ('t', 'topo-order', None, _('topo-order')),
       
   315     ('p', 'parents', None, _('parents')),
       
   316     ('n', 'max-count', 0, _('max-count'))],
       
   317     ('hg debug-rev-list [OPTION]... REV...'))
   295 def revlist(ui, repo, *revs, **opts):
   318 def revlist(ui, repo, *revs, **opts):
   296     """print revisions"""
   319     """print revisions"""
   297     if opts['header']:
   320     if opts['header']:
   298         full = "commit"
   321         full = "commit"
   299     else:
   322     else:
   300         full = None
   323         full = None
   301     copy = [x for x in revs]
   324     copy = [x for x in revs]
   302     revtree(ui, copy, repo, full, opts['max_count'], opts['parents'])
   325     revtree(ui, copy, repo, full, opts['max_count'], opts['parents'])
   303 
   326 
       
   327 @command('debug-config', [], _('hg debug-config'))
   304 def config(ui, repo, **opts):
   328 def config(ui, repo, **opts):
   305     """print extension options"""
   329     """print extension options"""
   306     def writeopt(name, value):
   330     def writeopt(name, value):
   307         ui.write(('k=%s\nv=%s\n' % (name, value)))
   331         ui.write(('k=%s\nv=%s\n' % (name, value)))
   308 
   332 
   309     writeopt('vdiff', ui.config('hgk', 'vdiff', ''))
   333     writeopt('vdiff', ui.config('hgk', 'vdiff', ''))
   310 
   334 
   311 
   335 
       
   336 @command('view',
       
   337     [('l', 'limit', '',
       
   338      _('limit number of changes displayed'), _('NUM'))],
       
   339     _('hg view [-l LIMIT] [REVRANGE]'))
   312 def view(ui, repo, *etc, **opts):
   340 def view(ui, repo, *etc, **opts):
   313     "start interactive history viewer"
   341     "start interactive history viewer"
   314     os.chdir(repo.root)
   342     os.chdir(repo.root)
   315     optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
   343     optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
   316     cmd = ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc))
   344     cmd = ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc))
   317     ui.debug("running %s\n" % cmd)
   345     ui.debug("running %s\n" % cmd)
   318     util.system(cmd)
   346     util.system(cmd)
   319 
   347 
   320 cmdtable = {
       
   321     "^view":
       
   322         (view,
       
   323          [('l', 'limit', '',
       
   324            _('limit number of changes displayed'), _('NUM'))],
       
   325          _('hg view [-l LIMIT] [REVRANGE]')),
       
   326     "debug-diff-tree":
       
   327         (difftree,
       
   328          [('p', 'patch', None, _('generate patch')),
       
   329           ('r', 'recursive', None, _('recursive')),
       
   330           ('P', 'pretty', None, _('pretty')),
       
   331           ('s', 'stdin', None, _('stdin')),
       
   332           ('C', 'copy', None, _('detect copies')),
       
   333           ('S', 'search', "", _('search'))],
       
   334          _('hg git-diff-tree [OPTION]... NODE1 NODE2 [FILE]...')),
       
   335     "debug-cat-file":
       
   336         (catfile,
       
   337          [('s', 'stdin', None, _('stdin'))],
       
   338          _('hg debug-cat-file [OPTION]... TYPE FILE')),
       
   339     "debug-config":
       
   340         (config, [], _('hg debug-config')),
       
   341     "debug-merge-base":
       
   342         (base, [], _('hg debug-merge-base REV REV')),
       
   343     "debug-rev-parse":
       
   344         (revparse,
       
   345          [('', 'default', '', _('ignored'))],
       
   346          _('hg debug-rev-parse REV')),
       
   347     "debug-rev-list":
       
   348         (revlist,
       
   349          [('H', 'header', None, _('header')),
       
   350           ('t', 'topo-order', None, _('topo-order')),
       
   351           ('p', 'parents', None, _('parents')),
       
   352           ('n', 'max-count', 0, _('max-count'))],
       
   353          _('hg debug-rev-list [OPTION]... REV...')),
       
   354 }
       
   355 
       
   356 commands.inferrepo += " debug-diff-tree debug-cat-file"
   348 commands.inferrepo += " debug-diff-tree debug-cat-file"