o ]Lbc @s0dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl mZmZmZmZmZmZmZmZmZmZmZddlmZmZiZeeZiZeeZedd d d d edd d dedddd d eddd ddZ ddZ!ddZ"dGddZ#ddZ$ddZ%ddZ&dHd d!Z'd"d#ge d$e d%fd&d'ge d(e d)fd d*d e d+e d,fd d-d e d.e d/fd0d1d e d2e d)fd d3de d4fd d5de d6fd d7de d8fgej(ej)Z*edd9d:d e d;e d<fge*e d=ej+d d>d?d@Z,GdAdBdBe-Z.dCdDZ/dEdFZ0e.gZ1dS)IaB command to allow external programs to compare revisions The extdiff Mercurial extension allows you to use external programs to compare revisions, or revision with working directory. The external diff programs are called with a configurable set of options and two non-option arguments: paths to directories containing snapshots of files to compare. If there is more than one file being compared and the "child" revision is the working directory, any modifications made in the external diff program will be copied back to the working directory from the temporary directory. The extdiff extension also allows you to configure new diff commands, so you do not need to type :hg:`extdiff -p kdiff3` always. :: [extdiff] # add new command that runs GNU diff(1) in 'context diff' mode cdiff = gdiff -Nprc5 ## or the old way: #cmd.cdiff = gdiff #opts.cdiff = -Nprc5 # add new command called meld, runs meld (no need to name twice). If # the meld executable is not available, the meld tool in [merge-tools] # will be used, if available meld = # add new command called vimdiff, runs gvimdiff with DirDiff plugin # (see http://www.vim.org/scripts/script.php?script_id=102) Non # English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in # your .vimrc vimdiff = gvim -f "+next" \ "+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))" Tool arguments can include variables that are expanded at runtime:: $parent1, $plabel1 - filename, descriptive label of first parent $child, $clabel - filename, descriptive label of child revision $parent2, $plabel2 - filename, descriptive label of second parent $root - repository root $parent is an alias for $parent1. The extdiff extension will look in your [diff-tools] and [merge-tools] sections for diff tool arguments, when none are specified in [extdiff]. :: [extdiff] kdiff3 = [diff-tools] kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child If a program has a graphical interface, it might be interesting to tell Mercurial about it. It will prevent the program from being mistakenly used in a terminal-only environment (such as an SSH terminal session), and will make :hg:`extdiff --per-file` open multiple file diffs at once instead of one by one (if you still want to open file diffs one by one, you can use the --confirm option). Declaring that a tool has a graphical interface can be done with the ``gui`` flag next to where ``diffargs`` are specified: :: [diff-tools] kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child kdiff3.gui = true You can use -I/-X and list of file or directory names like normal :hg:`diff` command. The extdiff extension makes snapshots of only needed files, so running the external diff program will actually be pretty fast (at least faster than having to compare the entire tree). )absolute_importN)_)nullrevshort) archivalcmdutilencodingerror filemerge formatter logcmdutilpycompat registrarscmutilutil)procutil stringutilextdiffsopts\..*T)defaultgenericsgui\..*)r diff-toolss .*\.diffargs$s.*\.gui$sships-with-hg-corec Cstj|j}|dkr d}|durd|t|f}tj||}t|g}|dur;|tdt |t|fn |tdt ||r|j ddd t j |||d t|||d t|D]'} t| } |d | |durtj|| } || || t| fqc||fS) zsnapshot files as of some revision if not using snapshot, -I/-X does not work and recursive diff in tools like kdiff3 and meld displays too many files.rrootNs%s.%ss(making snapshot of %d files from rev %s s3making snapshot of %d files from working directory suis archivemetaFsfiles)matchsubreposs %s )ospathbasenamerootrjoinmkdirnoterlenui setconfigrarchiver matchfilessortedrpconvertappendwjoinlstat) r#repofilesnodetmproot listsubreposdirnamebase fnsandstatfnwfndestr7//usr/lib/python3/dist-packages/hgext/extdiff.pysnapshotsJ   r9c sN||||||||dfdd} d} s t| |s |d7}t| | |S)N)sparentsparent1parent2splabel1splabel2schildsclabelrcs6|d}|d}s|dkr|S|t|S)Nr:)groupr shellquote)rprekeydo3wayreplacer7r8quotes   zformatcmdline..quotesJ(['"]?)([^\s'"$]*)\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1s $parent1 $child)researchsub) cmdline repo_rootrBparent1plabel1parent2plabel2childclabelrDregexr7rAr8 formatcmdlines  rQc Cs:t|}tjt|dtjt|ttj|d}|S)zflike 'procutil.system', but returns the Popen object directly so we don't have to wait on it. T)shell close_fdsenvcwd) r shellenviron subprocessPopen tonativestrclosefds tonativeenvr rapply)cmdenvironrUrTprocr7r7r8_systembackgrounds  r`c Csg}t|}tt|D]\}}tj||}|| }tj|s$tj}d}d}|r>tj| |}|| }tj|s>tj}tj| |}|| }|rt d||d|f}t d}| d||f}|dkr|dkr| |dD]\}}| d|t |fqr| d||f}|dksk|dkrn |dkrq |d krn>t|||||||||d }|s|s|d t||f|j||d d q |dt||ft||d}||q |r|d |D]}|qWddS1swYdSdS)Nrsdiff %s (%d of %d)sZ[Yns?]$$ &Yes, show diff$$ &No, skip this diff$$ &Skip remaining diffs$$ &? (display help)s%s %sr<s%s - %s rr;rBrJrKrLrMrNrOrunning %r in %s rrU blockedtags running %r in %s (backgrounded) )rU)r" enumerater'rrrisfiler osdevnullr promptchoiceextractchoiceswriterlowerrQdebugbytestrsystemr`r)timeblockedsectionwait)rHrIr#guitoolrBconfirm commonfilesr/dir1adir1bdir2rev1arev1brev2 waitprocs totalfilesidx commonfilepath1alabel1apath1blabel1bpath2label2 difffiles responsesrct curcmdliner_r7r7r8_runperfilediffs        "rc Csd}t|di!}tj|||||g||j|||dWdn1s-wYt|||} t|||} |j|| } |j|| } t||j d| | dd| | d }| dt ||f|j ||dddS) Ns hg-%h.patchr) fntemplaterFrbrcrdra)r nullformatterrexportrevvfsreljoin makefilenamerQrrmr rnro) r#r,node1node2r/matcherrHtemplatefmlabel1rfile1file2r7r7r8 diffpatchks8  rc 'Csj| d} |j||| d} t| jt| jt| j} }}|r:|j||| d}t|jt|jt|j}}}n ttt}}}| |B|B|B}||B|B}|sWdS| |B||B|B}t|||||| d}|durvdnd|}|r||B| |B|B}t|||||| d}d|}nd}d}g}d}d}|durt|||||| d}d|}nt |dkrt|||d|| \}}nd}|j }|} |}!|}"| dsOt |dkr,t | }#tj|||#}|#|} tj|stj}|r tj|||#}|#|}!tj|s tj}tj|||#}|#|}"t||j ||| ||!||"d }|d t||f|j||d d n*t||j || || d ||tj|||rltj||ndtj|||||d |D]7\}$}%} t|$}&|&tj| tjks|&j| jks|&jd@| jd@kr|d|%|$ft |$|%q{dS)Nsubrepos)r0rrs@%draper_filerbrcrrdconfirm) rrrBrsrtr/rurvrwrxryrz@s6file changed while diffing. Overwriting: %s (src: %s) )getstatussetmodifiedaddedremovedr9r.rr"rr localpathpoprrrrgr rhrQrmrnrorr+statST_MTIMEst_sizest_modecopyfile)'r#r,ctx1actx1bctx2rr/rHrBrroptsrstmod_aadd_arem_astbmod_badd_brem_bmodaddcommon dir1a_filesrurx dir1b_filesrvryr3dir2rootrzrwrrr common_filecopy_fn working_fncpstatr7r7r8diffrevss "           rFc Cst|dd|d}|d}|d}|d} d|v} | r2t|| d} | | } } n7|s6|rTt||g|gd}t||d} |t } t||d} nt ||\} } |se|d} n|t } | rs| t krsd} t | ||}|d r|d rt td |d rt td | durt tdtjdd}z;|d rt||| | |||W|tdt|St||| | | |||| || W|tdt|S|tdt|w)a Do the actual diff: - copy to a temp structure if diffing 2 internal revisions - copy to a temp structure if diffing working revision with another one and more than 1 file is changed - just invoke the diff for a single file in the working dir revchangefromtos$parent2NsnowarnFpatchrs&--patch cannot be used with --subreposrs&--patch cannot be used with --per-files--patch requires two revisionssextdiff.)prefixscleaning up temp directory )rcheck_at_most_one_argrr revsinglep1p2runhidehashlikerevsrrevpairrrr Abortrr.r mkdtemprr!shutilrmtreer)r#r,rHpatsrrrrevsfrom_revto_revchangerBrrrrr/r7r7r8dodiff!sp              rooptions!pass option to comparison programsOPTrrsrevision (DEPRECATED)sREVrsrevision to diff fromsREV1rsrevision to diff tosREV2crschange made by revisionsper-files/compare each file instead of revision snapshotsrs3prompt user before each external program invocationrs!compare patches for two revisionspprogramscomparison program to runsCMDshg extdiff [OPT]... [FILE]... helpcategory inferrepocOsXt|}|d}|d}|sd}|pdg}dttj|g|}t|||||S)aPuse external program to diff repository (or selected files) Show differences between revisions for the specified files, using an external program. The default program used is diff, with default options "-Npru". To select a different program, use the -p/--program option. The program will be passed the names of two directories to compare, unless the --per-file option is specified (see below). To pass additional options to the program, use -o/--option. These will be passed before the names of the directories or files to compare. The --from, --to, and --change options work the same way they do for :hg:`diff`. The --per-file option runs the external program repeatedly on each file to diff, instead of once on two directories. By default, this happens one by one, where the next file diff is open in the external program only once the previous external program (for the previous file diff) has exited. If the external program has a graphical interface, it can open all the file diffs at once instead of one by one. See :hg:`help -e extdiff` for information about how to tell Mercurial that a given program has a graphical interface. The --confirm option will prompt the user before each invocation of the external program. It is ignored if --per-file isn't specified. rrsdiffs-Npru )r byteskwargsrrmaprr>r)r#r,rrprogramoptionrHr7r7r8extdiffs &   rc@s eZdZdZddZddZdS)savedcmdause external program to diff repository (or selected files) Show differences between revisions for the specified files, using the following program:: %(path)s When two revision arguments are given, then changes are shown between those revisions. If only one revision is specified then that revision is compared to the working directory, and, when no revisions are specified, the working directory files are compared to its parent. cCs@t|dd}|jdtt|i;_||_||_dS)Ns\\\r) r escapestrrC__doc__r sysstruirepr_cmdline_isgui)selfrrHisguidocpathr7r7r8__init__s zsavedcmd.__init__cOsHt|}dttj|d}|rd|}t|||j||||jdS)Nrr)rr) r rrrrr>rrr)rr#r,rroptionsr7r7r8__call__s zsavedcmd.__call__N)__name__ __module__ __qualname__rrrr7r7r7r8rs rc Cs<t|}|drA|dd}|s#t|}|dur#t||p"|}|dd|}t|}|r8|d|7}| dd|}n.|rO|}t t |dk}nt|}|dur`t||p_|}t|}d }| dd|}|s|d }d D] }|||}|r|d|7}|dur| ||d pd }nqw||||fS) a returns following things for a ``` [extdiff] = ``` entry: cmd: command/tool name path: path to the tool cmdline: the command which should be run isgui: whether the tool uses GUI or not Reads all external tools related configs, whether it be extdiff section, diff-tools or merge-tools section, or its specified in an old format or the latest format. scmd.Nropts.rgui.raFs .diffargs)rs merge-toolss.gui) r expandpath startswithrfindexer findexternaltoolconfigr> configboolr"r shlexsplit) r#r]rdiffoptsrHrr@sectionargsr7r7r8_gettooldetailss@           rcCsr|dD]1\}}|ds|drqt|||\}}}}t|tddtd|tjddt|||qdS)Nrrrshg %s [OPTION]... [FILE]...Tr) configitemsrrcommand extdiffoptsrCATEGORY_FILE_CONTENTSr)r#r]rrHrr7r7r8uisetups   r )NN)F)2r __future__rrrErrrWmercurial.i18nrmercurial.noderr mercurialrrrr r r r r rrrmercurial.utilsrrcmdtabler configtable configitem testedwithr9rQr`rrrrwalkopts subrepooptsr r robjectrrr  i18nfunctionsr7r7r7r8s L 4    / *i! M  &"8