hgext/extdiff.py
changeset 45942 89a2afe31e82
parent 45410 2d08dcf8fd9e
child 46131 55542b213813
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
   116 
   116 
   117 configtable = {}
   117 configtable = {}
   118 configitem = registrar.configitem(configtable)
   118 configitem = registrar.configitem(configtable)
   119 
   119 
   120 configitem(
   120 configitem(
   121     b'extdiff', br'opts\..*', default=b'', generic=True,
   121     b'extdiff',
       
   122     br'opts\..*',
       
   123     default=b'',
       
   124     generic=True,
   122 )
   125 )
   123 
   126 
   124 configitem(
   127 configitem(
   125     b'extdiff', br'gui\..*', generic=True,
   128     b'extdiff',
       
   129     br'gui\..*',
       
   130     generic=True,
   126 )
   131 )
   127 
   132 
   128 configitem(
   133 configitem(
   129     b'diff-tools', br'.*\.diffargs$', default=None, generic=True,
   134     b'diff-tools',
       
   135     br'.*\.diffargs$',
       
   136     default=None,
       
   137     generic=True,
   130 )
   138 )
   131 
   139 
   132 configitem(
   140 configitem(
   133     b'diff-tools', br'.*\.gui$', generic=True,
   141     b'diff-tools',
       
   142     br'.*\.gui$',
       
   143     generic=True,
   134 )
   144 )
   135 
   145 
   136 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
   146 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
   137 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
   147 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
   138 # be specifying the version(s) of Mercurial they are tested with, or
   148 # be specifying the version(s) of Mercurial they are tested with, or
   139 # leave the attribute unspecified.
   149 # leave the attribute unspecified.
   140 testedwith = b'ships-with-hg-core'
   150 testedwith = b'ships-with-hg-core'
   141 
   151 
   142 
   152 
   143 def snapshot(ui, repo, files, node, tmproot, listsubrepos):
   153 def snapshot(ui, repo, files, node, tmproot, listsubrepos):
   144     '''snapshot files as of some revision
   154     """snapshot files as of some revision
   145     if not using snapshot, -I/-X does not work and recursive diff
   155     if not using snapshot, -I/-X does not work and recursive diff
   146     in tools like kdiff3 and meld displays too many files.'''
   156     in tools like kdiff3 and meld displays too many files."""
   147     dirname = os.path.basename(repo.root)
   157     dirname = os.path.basename(repo.root)
   148     if dirname == b"":
   158     if dirname == b"":
   149         dirname = b"root"
   159         dirname = b"root"
   150     if node is not None:
   160     if node is not None:
   151         dirname = b'%s.%s' % (dirname, short(node))
   161         dirname = b'%s.%s' % (dirname, short(node))
   228         cmdline += b' $parent1 $child'
   238         cmdline += b' $parent1 $child'
   229     return re.sub(regex, quote, cmdline)
   239     return re.sub(regex, quote, cmdline)
   230 
   240 
   231 
   241 
   232 def _systembackground(cmd, environ=None, cwd=None):
   242 def _systembackground(cmd, environ=None, cwd=None):
   233     ''' like 'procutil.system', but returns the Popen object directly
   243     """like 'procutil.system', but returns the Popen object directly
   234         so we don't have to wait on it.
   244     so we don't have to wait on it.
   235     '''
   245     """
   236     env = procutil.shellenviron(environ)
   246     env = procutil.shellenviron(environ)
   237     proc = subprocess.Popen(
   247     proc = subprocess.Popen(
   238         procutil.tonativestr(cmd),
   248         procutil.tonativestr(cmd),
   239         shell=True,
   249         shell=True,
   240         close_fds=procutil.closefds,
   250         close_fds=procutil.closefds,
   528 
   538 
   529     return 1
   539     return 1
   530 
   540 
   531 
   541 
   532 def dodiff(ui, repo, cmdline, pats, opts, guitool=False):
   542 def dodiff(ui, repo, cmdline, pats, opts, guitool=False):
   533     '''Do the actual diff:
   543     """Do the actual diff:
   534 
   544 
   535     - copy to a temp structure if diffing 2 internal revisions
   545     - copy to a temp structure if diffing 2 internal revisions
   536     - copy to a temp structure if diffing working revision with
   546     - copy to a temp structure if diffing working revision with
   537       another one and more than 1 file is changed
   547       another one and more than 1 file is changed
   538     - just invoke the diff for a single file in the working dir
   548     - just invoke the diff for a single file in the working dir
   539     '''
   549     """
   540 
   550 
   541     cmdutil.check_at_most_one_arg(opts, b'rev', b'change')
   551     cmdutil.check_at_most_one_arg(opts, b'rev', b'change')
   542     revs = opts.get(b'rev')
   552     revs = opts.get(b'rev')
   543     change = opts.get(b'change')
   553     change = opts.get(b'change')
   544     do3way = b'$parent2' in cmdline
   554     do3way = b'$parent2' in cmdline
   626 )
   636 )
   627 
   637 
   628 
   638 
   629 @command(
   639 @command(
   630     b'extdiff',
   640     b'extdiff',
   631     [(b'p', b'program', b'', _(b'comparison program to run'), _(b'CMD')),]
   641     [
       
   642         (b'p', b'program', b'', _(b'comparison program to run'), _(b'CMD')),
       
   643     ]
   632     + extdiffopts,
   644     + extdiffopts,
   633     _(b'hg extdiff [OPT]... [FILE]...'),
   645     _(b'hg extdiff [OPT]... [FILE]...'),
   634     helpcategory=command.CATEGORY_FILE_CONTENTS,
   646     helpcategory=command.CATEGORY_FILE_CONTENTS,
   635     inferrepo=True,
   647     inferrepo=True,
   636 )
   648 )
   637 def extdiff(ui, repo, *pats, **opts):
   649 def extdiff(ui, repo, *pats, **opts):
   638     '''use external program to diff repository (or selected files)
   650     """use external program to diff repository (or selected files)
   639 
   651 
   640     Show differences between revisions for the specified files, using
   652     Show differences between revisions for the specified files, using
   641     an external program. The default program used is diff, with
   653     an external program. The default program used is diff, with
   642     default options "-Npru".
   654     default options "-Npru".
   643 
   655 
   662     of one by one. See :hg:`help -e extdiff` for information about how
   674     of one by one. See :hg:`help -e extdiff` for information about how
   663     to tell Mercurial that a given program has a graphical interface.
   675     to tell Mercurial that a given program has a graphical interface.
   664 
   676 
   665     The --confirm option will prompt the user before each invocation of
   677     The --confirm option will prompt the user before each invocation of
   666     the external program. It is ignored if --per-file isn't specified.
   678     the external program. It is ignored if --per-file isn't specified.
   667     '''
   679     """
   668     opts = pycompat.byteskwargs(opts)
   680     opts = pycompat.byteskwargs(opts)
   669     program = opts.get(b'program')
   681     program = opts.get(b'program')
   670     option = opts.get(b'option')
   682     option = opts.get(b'option')
   671     if not program:
   683     if not program:
   672         program = b'diff'
   684         program = b'diff'