Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# visdiff.py - launch external visual diff tools## Copyright 2009 Steve Borho <steve@borho.org>## This software may be used and distributed according to the terms of the# GNU General Public License version 2, incorporated herein by reference.importgtkimportgobjectimportosimportshleximportsubprocessimportshutilimporttempfileimportrefrommercurialimporthg,ui,cmdutil,utilfrommercurial.nodeimportshort,nullidfromtortoisehg.util.i18nimport_fromtortoisehg.utilimporthglib,settings,pathsfromtortoisehg.hgtkimportgdialog,gtklibtry:importwin32conopenflags=win32con.CREATE_NO_WINDOWexceptImportError:openflags=0defsnapshot(repo,files,node,tmproot):'''snapshot files as of some revision'''dirname=os.path.basename(repo.root)ifdirname=="":dirname="root"ifnodeisnotNone:dirname='%s.%s'%(dirname,short(node))base=os.path.join(tmproot,dirname)os.mkdir(base)ctx=repo[node]forfninfiles:wfn=util.pconvert(fn)ifnotwfninctx:# File doesn't exist; could be a bogus modifycontinuedest=os.path.join(base,wfn)destdir=os.path.dirname(dest)ifnotos.path.isdir(destdir):os.makedirs(destdir)data=repo.wwritedata(wfn,ctx[wfn].data())f=open(dest,'wb')f.write(data)f.close()returndirnameclassFileSelectionDialog(gtk.Dialog):'Dialog for selecting visual diff candidates'def__init__(self,canonpats,opts):'Initialize the Dialog'gtk.Dialog.__init__(self,title=_('Visual Diffs'))gtklib.set_tortoise_icon(self,'menushowchanged.ico')gtklib.set_tortoise_keys(self) self.set_default_size(400, 150)
self.set_has_separator(False)
+ self.tmproot = None lbl = gtk.Label(_('Temporary files are removed when this dialog'
' is closed'))
self.vbox.pack_start(lbl,False,False,2)scroller=gtk.ScrolledWindow()scroller.set_shadow_type(gtk.SHADOW_IN)scroller.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)treeview=gtk.TreeView()self.treeview=treeviewtreeview.get_selection().set_mode(gtk.SELECTION_SINGLE)treeview.set_search_equal_func(self.search_filelist)scroller.add(treeview)self.vbox.pack_start(scroller,True,True,2)hbox=gtk.HBox()self.vbox.pack_start(hbox,False,False,2)vsettings=settings.Settings('visdiff')single=vsettings.get_value('launchsingle',False)check=gtk.CheckButton(_('Always launch single files'))check.set_active(single) hbox.pack_start(check, True, True, 2)
self.singlecheck = check
- self.connect('response', self.response)- treeview.connect('row-activated', self.rowactivated)
treeview.set_headers_visible(False)
treeview.set_property('enable-grid-lines', True)
treeview.set_enable_search(False)try:path=opts.get('bundle')orpaths.find_root()repo=hg.repository(ui.ui(),path=path)excepthglib.RepoError:# hgtk should catch this earliergdialog.Prompt(_('No repository'),_('No repository found here'),None).run()returntools=readtools(repo.ui)preferred=repo.ui.config('tortoisehg','vdiff','vdiff')ifpreferredandpreferredintools:iflen(tools)>1:lbl=gtk.Label(_('Select diff tool'))combo=gtk.combo_box_new_text()fori,nameinenumerate(tools.iterkeys()):combo.append_text(name)ifname==preferred:defrow=icombo.connect('changed',self.toolselect,tools)combo.set_active(defrow)hbox.pack_start(lbl,False,False,2)hbox.pack_start(combo,False,False,2)else:self.diffpath,self.diffopts=tools[preferred]cwd=os.getcwd()try:os.chdir(repo.root)model=self.find_files(repo,canonpats,opts,treeview)do3way=model.get_n_columns()==3treeview.set_model(model)cell=gtk.CellRendererText()stcol=gtk.TreeViewColumn('Status 1',cell)stcol.set_resizable(True)stcol.add_attribute(cell,'text',0)treeview.append_column(stcol)ifdo3way:cell=gtk.CellRendererText()stcol=gtk.TreeViewColumn('Status 2',cell)stcol.set_resizable(True)stcol.add_attribute(cell,'text',1)treeview.append_column(stcol)cell=gtk.CellRendererText()fcol=gtk.TreeViewColumn('Filename',cell)fcol.set_resizable(True)fcol.add_attribute(cell,'text',do3wayand2or1)treeview.append_column(fcol)iflen(model)==1andself.singlecheck.get_active():self.launch(*model[0])finally:os.chdir(cwd)else:gdialog.Prompt(_('No visual diff tool'),_('No visual diff tool has been configured'),None).run()fromtortoisehg.hgtkimportthgconfigdlg=thgconfig.ConfigDialog(False)dlg.show_all()dlg.focus_field('tortoisehg.vdiff')dlg.run()dlg.hide()gtklib.idle_add_single_call(self.destroy)defsearch_filelist(self,model,column,key,iter):'case insensitive filename search'key=key.lower()ifkeyinmodel.get_value(iter,1).lower():returnFalsereturnTruedeftoolselect(self,combo,tools):sel=combo.get_active_text()ifselintools:self.diffpath,self.diffopts=tools[sel]deffind_files(self,repo,pats,opts,treeview):revs=opts.get('rev')change=opts.get('change')do3way='$parent2'in''.join(self.diffopts)ifchangeand(do3wayornotrevs):title=_('changeset ')+str(change)node2=repo.lookup(change)node1a,node1b=repo.changelog.parents(node2)else:node1a,node2=cmdutil.revpair(repo,revs)ifnotrevs:title=_('working changes')node1b=repo.dirstate.parents()[1]else:title=_('revisions ')+' to '.join(revs)node1b=nullid# Disable 3-way merge if there is only one parentifnode1b==nullid:do3way=Falsetitle=_('Visual Diffs - ')+titleifpats:title+=' filtered'self.set_title(title)matcher=cmdutil.match(repo,pats,opts)mod_a,add_a,rem_a=map(set,repo.status(node1a,node2,matcher)[:3])ifdo3way:mod_b,add_b,rem_b=map(set,repo.status(node1b,node2,matcher)[:3])else:mod_b,add_b,rem_b=set(),set(),set()modadd=mod_a|add_a|mod_b|add_bcommon=modadd|rem_a|rem_bifnotcommon:gdialog.Prompt(_('No file changes'),_('There are no file changes to view'),self).run()# GTK+ locks up if this is done immediately heregtklib.idle_add_single_call(self.destroy) return
tmproot = tempfile.mkdtemp(prefix='extdiff.')
- self.connect('destroy', self.delete_tmproot, tmproot)+ self.connect('response', self.response)+ self.tmproot = tmproot
# Always make a copy of node1a (and node1b, if applicable)
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
dir1a=snapshot(repo,dir1a_files,node1a,tmproot)ifdo3way:dir1b_files=mod_b|rem_b|((mod_a|add_a)-add_b)dir1b=snapshot(repo,dir1b_files,node1b,tmproot)else:dir1b=None# If node2 in not the wc or there is >1 change, copy itdir2root=''ifnode2:dir2=snapshot(repo,modadd,node2,tmproot)eliflen(common)>1:#we only actually need to get the files to copy back to the working#dir in this case (because the other cases are: diffing 2 revisions#or single file -- in which case the file is already directly passed#to the diff tool).dir2=snapshot(repo,modadd,None,tmproot)else:# This lets the diff tool open the changed file directlydir2=''dir2root=repo.rootself.dirs=(dir1a,dir1b,dir2,dir2root,tmproot)defget_status(file,mod,add,rem):iffileinmod:return'M'iffileinadd:return'A'iffileinrem:return'R'return' 'ifdo3way:model=gtk.ListStore(str,str,str)forfincommon:model.append([get_status(f,mod_a,add_a,rem_a),get_status(f,mod_b,add_b,rem_b),hglib.toutf(f)])else:model=gtk.ListStore(str,str)forfincommon:model.append([get_status(f,mod_a,add_a,rem_a),hglib.toutf(f)])returnmodeldefresponse(self,window,resp):self.should_live()defshould_live(self): vsettings = settings.Settings('visdiff')
vsettings.set_value('launchsingle', self.singlecheck.get_active())
vsettings.write()
- return False-- def delete_tmproot(self, window, tmproot):- while True:
+ while self.tmproot:
try:
- shutil.rmtree(tmproot)
- return
+ shutil.rmtree(self.tmproot)
+ return False except (IOError, OSError), e:
resp = gdialog.CustomPrompt(_('Unable to delete temp files'),
_('Close diff tools and try again, or quit to leak files?'),
self,(_('Try &Again'),_('&Quit')),1).run() if resp == 0:
continue
else:
- return
+ return False+ return False def rowactivated(self, tree, path, column):
selection = tree.get_selection()
ifselection.count_selected_rows()!=1:returnFalsemodel,paths=selection.get_selected_rows()self.launch(*model[paths[0]])deflaunch(self,st1,st2,fname=None):ifnotfname:fname=st2st2=Nonefname=hglib.fromutf(fname)dir1a,dir1b,dir2,dir2root,tmproot=self.dirsifst1=='A'orst2=='R':dir1a=os.devnullelse:dir1a=os.path.join(dir1a,util.localpath(fname))ifst2:ifst2=='A'orst1=='R':dir1b=os.devnullelse:dir1b=os.path.join(dir1b,util.localpath(fname))ifst1=='R'orst2=='R':dir2=os.devnullelse:dir2=os.path.join(dir2root,dir2,util.localpath(fname))# Function to quote file/dir names in the argument string# When not operating in 3-way mode, an empty string is returned for parent2replace=dict(parent=dir1a,parent1=dir1a,parent2=dir1b,child=dir2)defquote(match):key=match.group()[1:]ifnotst2andkey=='parent2':return''returnutil.shellquote(replace[key])# Match parent2 first, so 'parent1?' will match both parent1 and parentargs=' '.join(self.diffopts)regex='\$(parent2|parent1?|child)'ifnotst2andnotre.search(regex,args):args+=' $parent1 $child'args=re.sub(regex,quote,args)cmdline=util.shellquote(self.diffpath)+' '+argsifos.name=='nt':cmdline='"%s"'%cmdlinetry:subprocess.Popen(cmdline,shell=True,cwd=tmproot,creationflags=openflags,stderr=subprocess.PIPE,stdout=subprocess.PIPE,stdin=subprocess.PIPE)except(OSError,EnvironmentError),e:gdialog.Prompt(_('Tool launch failure'),_('%s : %s')%(self.diffpath,str(e)),None).run()defreadtools(ui):tools={}forcmd,pathinui.configitems('extdiff'):ifcmd.startswith('cmd.'):cmd=cmd[4:]ifnotpath:path=cmddiffopts=ui.config('extdiff','opts.'+cmd,'')diffopts=diffoptsand[diffopts]or[]tools[cmd]=[path,diffopts]elifcmd.startswith('opts.'):continueelse:# command = path optsifpath:diffopts=shlex.split(path)path=diffopts.pop(0)else:path,diffopts=cmd,[]tools[cmd]=[path,diffopts]returntoolsdefrawextdiff(ui,*pats,**opts):'launch raw extdiff command, block until finish'fromhgextimportextdifftry:path=opts.get('bundle')orpaths.find_root()repo=hg.repository(ui,path=path)excepthglib.RepoError:# hgtk should catch this earlierui.warn(_('No repository found here')+'\n')returntools=readtools(ui)preferred=ui.config('tortoisehg','vdiff','vdiff')try:diffcmd,diffopts=tools[preferred]exceptKeyError:ui.warn(_('Extdiff command not recognized\n'))returnpats=hglib.canonpaths(pats)# if both --change and --rev is given, remove --rev in 3-way mode,# and --change in normal modeif'change'inoptsandopts.get('rev'):if'$parent2'in''.join(diffopts):delopts['rev']else:delopts['change']try:ret=extdiff.dodiff(ui,repo,diffcmd,diffopts,pats,opts)exceptOSError,e:ui.warn(str(e)+'\n')returnifret==0:gdialog.Prompt(_('No file changes'),_('There are no file changes to view'),None).run()defrun(ui,*pats,**opts):ifui.configbool('tortoisehg','vdiffnowin'):importsys# Spawn background process and exitifhasattr(sys,"frozen"):args=[sys.argv[0]]else:args=[sys.executable]+[sys.argv[0]]args.extend(['vdiff','--nofork','--raw'])revs=opts.get('rev',[])change=opts.get('change')ifchange:args.extend(['--change',str(change)])forrinrevs:args.extend(['--rev',str(r)])bfile=opts.get('bundle')ifbfile:args.extend(['--bundle',bfile])args.extend(pats)args.extend(opts.get('canonpats',[]))ifos.name=='nt':args=['"%s"'%argforarginargs]oldcwd=os.getcwd()root=paths.find_root(oldcwd)try:os.chdir(root)os.spawnv(os.P_NOWAIT,sys.executable,args)finally:os.chdir(oldcwd)returnNoneelse:pats=hglib.canonpaths(pats)ifopts.get('canonpats'):pats=list(pats)+opts['canonpats']returnFileSelectionDialog(pats,opts)
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.