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.
# guess.py - TortoiseHg's dialogs for detecting copies and renames## 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.importosimportsysimportgtkimportgobjectimportpangoimportcStringIOimportQueuefrommercurialimporthg,ui,mdiff,cmdutil,match,util,errorfromtortoisehg.util.i18nimport_fromtortoisehg.utilimporthglib,shlib,paths,thread2,settingsfromtortoisehg.hgtkimportgtklib,statusbar# This function and some key bits below borrowed ruthelessly from# Peter Arrenbrecht <peter.arrenbrecht@gmail.com># Thanks!deffindmoves(repo,added,removed,threshold):'''find renamed files -- yields (before, after, score) tuples'''ctx=repo['.']forrinremoved:rr=ctx.filectx(r).data()forainadded:aa=repo.wread(a)ifaa==rr:yieldr,a,1.0breakclassDetectRenameDialog(gtk.Window):'Detect renames after they occur'def__init__(self):'Initialize the Dialog'gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)gtklib.set_tortoise_icon(self,'detect_rename.ico')gtklib.set_tortoise_keys(self)try:repo=hg.repository(ui.ui(),path=paths.find_root())excepterror.RepoError:gtklib.idle_add_single_call(self.destroy)returnself.repo=repoself.notify_func=Nonereponame=hglib.get_reponame(repo)self.set_title(_('Detect Copies/Renames in %s')%reponame)self.settings=settings.Settings('guess')dims=self.settings.get_value('dims',(800,600))self.set_default_size(dims[0],dims[1])# vbox for dialog main & status barmainvbox=gtk.VBox()self.add(mainvbox)# vsplit for top & diffself.vpaned=gtk.VPaned()mainvbox.pack_start(self.vpaned,True,True,2)pos=self.settings.get_value('vpaned',None)ifpos:self.vpaned.set_position(pos)# vbox for top contentstopvbox=gtk.VBox()self.vpaned.pack1(topvbox,True,False)# frame for simularityframe=gtk.Frame(_('Minimum Simularity Percentage'))topvbox.pack_start(frame,False,False,2)#$ simularity sliderself.adjustment=gtk.Adjustment(50,0,100,1)value=self.settings.get_value('percent',None)ifvalue:self.adjustment.set_value(value)hscale=gtk.HScale(self.adjustment)frame.add(hscale)# horizontal splitter for unknown & candidateself.hpaned=gtk.HPaned()topvbox.pack_start(self.hpaned,True,True,2)pos=self.settings.get_value('hpaned',None)ifpos:self.hpaned.set_position(pos)#$ frame for unknown listunknownframe=gtk.Frame(_('Unrevisioned Files'))self.hpaned.pack1(unknownframe,True,True)#$$ vbox for unknown list & rename/copy buttonsunkvbox=gtk.VBox()unknownframe.add(unkvbox)#$$$ scroll window for unknown listscroller=gtk.ScrolledWindow()unkvbox.pack_start(scroller,True,True,2)scroller.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)#$$$$ unknown listunkmodel=gtk.ListStore(str,# pathstr)# path (utf-8)self.unktree=gtk.TreeView(unkmodel)scroller.add(self.unktree)self.unktree.get_selection().set_mode(gtk.SELECTION_MULTIPLE)cell=gtk.CellRendererText()cell.set_property("ellipsize",pango.ELLIPSIZE_START)col=gtk.TreeViewColumn('File',cell,text=1)self.unktree.append_column(col)self.unktree.set_enable_search(True)self.unktree.set_headers_visible(False)#$$$ hbox for rename/copy buttonsbtnhbox=gtk.HBox()unkvbox.pack_start(btnhbox,False,False,2)#$$$$ rename/copy buttons in unknown frameself.renamebtn=gtk.Button(_('Find Renames'))self.renamebtn.set_sensitive(False)btnhbox.pack_start(self.renamebtn,False,False,2)self.copybtn=gtk.Button(_('Find Copies'))self.copybtn.set_sensitive(False)btnhbox.pack_start(self.copybtn,False,False,2)#$ frame for candidate listcandidateframe=gtk.Frame(_('Candidate Matches'))self.hpaned.pack2(candidateframe,True,True)#$$ vbox for candidate list & accept buttoncanvbox=gtk.VBox()candidateframe.add(canvbox)#$$$ scroll window for candidate listscroller=gtk.ScrolledWindow()canvbox.pack_start(scroller,True,True,2)scroller.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)#$$$$ candidate listcanmodel=gtk.ListStore(str,# sourcestr,# source (utf-8)str,# deststr,# dest (utf-8)str,# percentbool)# sensitiveself.cantree=gtk.TreeView(canmodel)scroller.add(self.cantree)self.cantree.set_rules_hint(True)self.cantree.set_reorderable(False)self.cantree.set_enable_search(False)self.cantree.get_selection().set_mode(gtk.SELECTION_MULTIPLE)cell=gtk.CellRendererText()cell.set_property('width-chars',30)cell.set_property('ellipsize',pango.ELLIPSIZE_START)col=gtk.TreeViewColumn(_('Source'),cell,text=1,sensitive=5)col.set_resizable(True)self.cantree.append_column(col)cell=gtk.CellRendererText()cell.set_property('width-chars',30)cell.set_property('ellipsize',pango.ELLIPSIZE_START)col=gtk.TreeViewColumn(_('Dest'),cell,text=3,sensitive=5)col.set_resizable(True)self.cantree.append_column(col)cell=gtk.CellRendererText()cell.set_property('width-chars',5)cell.set_property('ellipsize',pango.ELLIPSIZE_NONE)col=gtk.TreeViewColumn('%',cell,text=4,sensitive=5)col.set_resizable(True)self.cantree.append_column(col)#$$$ hbox for accept buttonbtnhbox=gtk.HBox()canvbox.pack_start(btnhbox,False,False,2)#$$$$ accept button in candidate frameself.acceptbtn=gtk.Button(_('Accept Match'))btnhbox.pack_start(self.acceptbtn,False,False,2)self.acceptbtn.set_sensitive(False)# frame for diffdiffframe=gtk.Frame(_('Differences from Source to Dest'))self.vpaned.pack2(diffframe)diffframe.set_shadow_type(gtk.SHADOW_ETCHED_IN)#$ scroll window for diffscroller=gtk.ScrolledWindow()diffframe.add(scroller)scroller.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)#$$ text view for diffself.buf=gtk.TextBuffer()self.buf.create_tag('removed',foreground=gtklib.DRED)self.buf.create_tag('added',foreground=gtklib.DGREEN)self.buf.create_tag('position',foreground='#FF8000')self.buf.create_tag('header',foreground=gtklib.DBLUE)diffview=gtk.TextView(self.buf)scroller.add(diffview)fontdiff=hglib.getfontconfig()['fontdiff']diffview.modify_font(pango.FontDescription(fontdiff))diffview.set_wrap_mode(gtk.WRAP_NONE)diffview.set_editable(False)# status barself.stbar=statusbar.StatusBar()mainvbox.pack_start(self.stbar,False,False,2)# register signal handlersself.copybtn.connect('pressed',lambdab:self.find_copies())self.renamebtn.connect('pressed',lambdab:self.find_renames()) self.acceptbtn.connect('pressed', lambda b: self.accept_match())
self.unktree.get_selection().connect('changed', self.unknown_sel_change)
- self.cantree.connect('row-activated', lambda b: self.accept_match())
+ self.cantree.connect('row-activated', lambda t,p,c: self.accept_match())
self.cantree.get_selection().connect('changed', self.show_diff)
self.connect('delete-event', lambda *a: self.save_settings())
gtklib.idle_add_single_call(self.refresh)
defset_notify_func(self,func):self.notify_func=funcdefrefresh(self):q=Queue.Queue()unkmodel=self.unktree.get_model()unkmodel.clear()thread=thread2.Thread(target=self.unknown_thread,args=(q,))thread.start()gobject.timeout_add(50,self.unknown_wait,thread,q)defunknown_thread(self,q):hglib.invalidaterepo(self.repo)matcher=match.always(self.repo.root,self.repo.root)status=self.repo.status(node1=self.repo.dirstate.parents()[0],node2=None,match=matcher,ignored=False,clean=False,unknown=True)(modified,added,removed,deleted,unknown,ignored,clean)=statusforuinunknown:q.put(u)forainadded:ifnotself.repo.dirstate.copied(a):q.put(a)defunknown_wait(self,thread,q):unkmodel=self.unktree.get_model()whileq.qsize():wfile=q.get(0)unkmodel.append([wfile,hglib.toutf(wfile)])returnthread.isAlive()defsave_settings(self):self.settings.set_value('vpaned',self.vpaned.get_position())self.settings.set_value('hpaned',self.hpaned.get_position())self.settings.set_value('percent',self.adjustment.get_value())rect=self.get_allocation()self.settings.set_value('dims',(rect.width,rect.height))self.settings.write()deffind_renames(self):'User pressed "find renames" button'canmodel=self.cantree.get_model()canmodel.clear()umodel,upaths=self.unktree.get_selection().get_selected_rows()ifnotupaths:returntgts=[umodel[p][0]forpinupaths]q=Queue.Queue()thread=thread2.Thread(target=self.search_thread,args=(q,tgts))thread.start()self.stbar.begin()self.stbar.set_status_text(_('finding source of ')+', '.join(tgts))gobject.timeout_add(50,self.search_wait,thread,q)defsearch_thread(self,q,tgts):hglib.invalidaterepo(self.repo)srcs=[]audit_path=util.path_auditor(self.repo.root)m=cmdutil.match(self.repo)forabsinself.repo.walk(m):target=self.repo.wjoin(abs)good=Truetry:audit_path(abs)except:good=Falsestatus=self.repo.dirstate[abs]if(notgoodornotutil.lexists(target)or(os.path.isdir(target)andnotos.path.islink(target))):srcs.append(abs)elifnotself.adjustmentandstatus=='n':# looking for copies, so any revisioned file is a# potential source (yes, this will be expensive)# Added and removed files are not considered as copy# sources.srcs.append(abs)ifself.adjustment:simularity=self.adjustment.get_value()/100.0;gen=cmdutil.findrenameselse:simularity=1.0gen=findmovesforold,new,scoreingen(self.repo,tgts,srcs,simularity):q.put([old,new,'%d%%'%(score*100)])defsearch_wait(self,thread,q):canmodel=self.cantree.get_model()whileq.qsize():source,dest,sim=q.get(0)canmodel.append([source,hglib.toutf(source),dest,hglib.toutf(dest),sim,True])ifthread.isAlive():returnTrueelse:self.stbar.end()returnFalsedeffind_copies(self):'User pressed "find copies" button'# call rename function with simularity = 100%self.find_renames()defaccept_match(self):'User pressed "accept match" button'hglib.invalidaterepo(self.repo)canmodel,upaths=self.cantree.get_selection().get_selected_rows()forpathinupaths:row=canmodel[path]src,usrc,dest,udest,percent,sensitive=rowifnotsensitive:continueifnotos.path.exists(self.repo.wjoin(src)):# Mark missing rename source as removedself.repo.remove([src])self.repo.copy(src,dest)shlib.shell_notify([self.repo.wjoin(src),self.repo.wjoin(dest)])ifself.notify_func:self.notify_func()# Mark all rows with this target file as non-sensitiveforrowincanmodel:ifrow[2]==dest:row[5]=Falseself.refresh()defunknown_sel_change(self,selection):'User selected a row in the unknown tree'model,upaths=selection.get_selected_rows()sensitive=upathsandTrueorFalseself.renamebtn.set_sensitive(sensitive)self.copybtn.set_sensitive(sensitive)defshow_diff(self,selection):'User selected a row in the candidate tree'hglib.invalidaterepo(self.repo)model,cpaths=selection.get_selected_rows()sensitive=cpathsandTrueorFalseself.acceptbtn.set_sensitive(sensitive)self.buf.set_text('')bufiter=self.buf.get_start_iter()forpathincpaths:row=model[path]src,usrc,dest,udest,percent,sensitive=rowifnotsensitive:continuectx=self.repo['.']aa=self.repo.wread(dest)rr=ctx.filectx(src).data()opts=mdiff.defaultoptsdifftext=mdiff.unidiff(rr,'',aa,'',src,dest,None,opts=opts)ifnotdifftext:l=_('== %s and %s have identical contents ==\n\n')%(src,dest)self.buf.insert(bufiter,l)continuedifflines=difftext.splitlines(True)forlineindifflines:line=hglib.toutf(line)ifline.startswith('---')orline.startswith('+++'):self.buf.insert_with_tags_by_name(bufiter,line,'header')elifline.startswith('-'):line=hglib.diffexpand(line)self.buf.insert_with_tags_by_name(bufiter,line,'removed')elifline.startswith('+'):line=hglib.diffexpand(line)self.buf.insert_with_tags_by_name(bufiter,line,'added')elifline.startswith('@@'):self.buf.insert_with_tags_by_name(bufiter,line,'position')else:line=hglib.diffexpand(line)self.buf.insert(bufiter,line)defrun(ui,*pats,**opts):returnDetectRenameDialog()
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.