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.
# Trivial Mercurial plugin for Nautilus## Copyright (C) 2007 Steve Borho## Stolen mercilessly from nautilus-bzr, thanks guys# Copyright (C) 2006 Jeff Bailey# Copyright (C) 2006 Wouter van Heyst# Copyright (C) 2006 Jelmer Vernooij## Published under the GNU GPLimportgconfimportgtkimportgobjectfrommercurialimporthg,ui,repo,match,utilfrommercurial.nodeimportshortimportnautilusimportosimportsubprocessimportsysimporttempfileimporttimeimporturllibTORTOISEHG_PATH='~/tools/tortoisehg-dev'TERMINAL_KEY='/desktop/gnome/applications/terminal/exec'classHgExtension(nautilus.MenuProvider,nautilus.ColumnProvider,nautilus.InfoProvider,nautilus.PropertyPageProvider):def__init__(self):self.cacherepo=Noneself.cacheroot=Noneself.client=gconf.client_get_default()thgpath=os.environ.get('TORTOISEHG_PATH',os.path.expanduser(TORTOISEHG_PATH))os.environ['TORTOISEHG_PATH']=thgpathos.environ['THG_ICON_PATH']=os.path.join(thgpath,'icons')self.hgproc=os.path.join(thgpath,'hgproc.py')self.ipath=os.path.join(thgpath,'icons','tortoise')deficon(self,iname):returnos.path.join(self.ipath,iname)defget_path_for_vfs_file(self,vfs_file):ifvfs_file.get_uri_scheme()!='file':returnNonereturnurllib.unquote(vfs_file.get_uri()[7:])defclear_cached_repo(self):self.cacheroot=Noneself.cacherepo=Nonedefget_repo_for_path(self,path):''' Find mercurial repository for vfs_file Returns hg.repo '''p=os.path.isdir(path)andpathoros.path.dirname(path)whilenotos.path.isdir(os.path.join(p,".hg")):oldp=pp=os.path.dirname(p)ifp==oldp:returnNoneifp==self.cacheroot:returnself.cacherepo# Keep one repo cachedtry:self.cacheroot=pself.cacherepo=hg.repository(ui.ui(),path=p)returnself.cacherepoexceptrepo.RepoError:self.cacheroot=Noneself.cacherepo=NonereturnNonedef_open_terminal_cb(self,window,vfs_file):path=self.get_path_for_vfs_file(vfs_file)ifpathisNone:returnos.chdir(path)terminal=self.client.get_string(TERMINAL_KEY)os.system('%s &'%terminal)def_about_cb(self,window,vfs_file):self._run_dialog('about',[vfs_file])def_add_cb(self,window,vfs_files):self._run_dialog('add',vfs_files)self.clear_cached_repo()def_clone_cb(self,window,vfs_file):self._run_dialog('clone',[vfs_file])def_commit_cb(self,window,vfs_files):self._run_dialog('commit',vfs_files)self.clear_cached_repo()def_datamine_cb(self,window,vfs_files):self._run_dialog('datamine',vfs_files)def_diff_cb(self,window,vfs_files):path=self.get_path_for_vfs_file(vfs_files[0])ifpathisNone:returnrepo=self.get_repo_for_path(path)ifrepoisNone:returndiffcmd=repo.ui.config('tortoisehg','vdiff',None)ifdiffcmdisNone:self._run_dialog('diff',vfs_files)else:cmdline=['hg',diffcmd]cwd=os.path.isdir(path)andpathoros.path.dirname(path)paths=[self.get_path_for_vfs_file(f)forfinvfs_files]subprocess.Popen(cmdline+paths,shell=False,cwd=cwd)def_history_cb(self,window,vfs_files):self._run_dialog('history',vfs_files)self.clear_cached_repo()def_init_cb(self,window,vfs_file):self._run_dialog('init',[vfs_file])def_recovery_cb(self,window,vfs_file):self._run_dialog('recovery',[vfs_file])self.clear_cached_repo()def_revert_cb(self,window,vfs_files):self._run_dialog('revert',vfs_files)self.clear_cached_repo()def_serve_cb(self,window,vfs_file):self._run_dialog('serve',[vfs_file],filelist=False)def_status_cb(self,window,vfs_file):self._run_dialog('status',[vfs_file])def_sync_cb(self,window,vfs_file):self._run_dialog('synch',[vfs_file],filelist=False)self.clear_cached_repo()def_thgconfig_repo_cb(self,window,vfs_file):self._run_dialog('config',[vfs_file])def_thgconfig_user_cb(self,window,vfs_file):self._run_dialog('config',[vfs_file],filelist=False)def_unmerge_cb(self,window,vfs_file):self._run_dialog('checkout',[vfs_file],filelist=False,extras=['--','--clean',str(self.rev0)])self.clear_cached_repo()def_run_dialog(self,hgcmd,vfs_files,filelist=True,extras=[]):''' hgcmd - hgproc subcommand vfs_files - directory, or list of selected files filelist - bool for whether to generate file list for hgproc '''paths=[self.get_path_for_vfs_file(f)forfinvfs_files]ifpaths[0]isNone:returnpath=paths[0]repo=self.get_repo_for_path(path)cwd=os.path.isdir(path)andpathoros.path.dirname(path)ifrepoisnotNone:root=repo.rootelse:root=cwdcmdopts=[sys.executable,self.hgproc]cmdopts+=['--root',root]cmdopts+=['--cwd',cwd]cmdopts+=['--command',hgcmd]iffilelist:# Use temporary file to store file list (avoid shell command# line limitations)fd,tmpfile=tempfile.mkstemp(prefix="tortoisehg_filelist_")os.write(fd,"\n".join(paths))os.close(fd)cmdopts+=['--listfile',tmpfile,'--deletelistfile']cmdopts.extend(extras)subprocess.Popen(cmdopts,cwd=cwd,shell=False)# Remove cached repo object, dirstate may changeself.cacherepo=Noneself.cacheroot=Nonedefget_background_items(self,window,vfs_file):'''Build context menu for current directory'''mainitem=nautilus.MenuItem('HgNautilus','Mercurial','')submenu=nautilus.Menu()mainitem.set_submenu(submenu)path=self.get_path_for_vfs_file(vfs_file)ifpathisNone:returnrepo=self.get_repo_for_path(path)ifrepoisNone:''' The name given to nautilus.MenuItem decides the of the menu, which is ordered alpahbetically '''item=nautilus.MenuItem('HgNautilus::newtree','Create New Repository','Make directory versioned',self.icon('menucreaterepos.ico'))item.connect('activate',self._init_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::clone','Create Clone','Create clone here from source',self.icon('menuclone.ico'))item.connect('activate',self._clone_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::99about','About TortoiseHg','Information about TortoiseHg installation',self.icon('menuabout.ico'))item.connect('activate',self._about_cb,vfs_file)submenu.append_item(item)returnmainitem,iflen(repo.changectx(None).parents())>1:self.rev0=repo.changectx(None).parents()[0].rev()item=nautilus.MenuItem('HgNautilus::undomerge','Undo Merge','Clean checkout of original parent revision',self.icon('menuunmerge.ico'))item.connect('activate',self._unmerge_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::10commit','Commit','Commit changes',self.icon('menucommit.ico'))item.connect('activate',self._commit_cb,[vfs_file])submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::20status','Show Status','Show Repository Status',self.icon('menushowchanged.ico'))item.connect('activate',self._status_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::30diff','Visual Diff','Show Changes to Repository',self.icon('menudiff.ico'))item.connect('activate',self._diff_cb,[vfs_file])submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::40dag','Revision History','Show revision DAG',self.icon('menurevisiongraph.ico'))item.connect('activate',self._history_cb,[vfs_file])submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::50datamine','Data Mining','Search revision history',self.icon('menulog.ico'))item.connect('activate',self._datamine_cb,[vfs_file])submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::60sync','Synchronize','Sync with another repository',self.icon('menusynch.ico'))item.connect('activate',self._sync_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::70serve','Web Server','Start internal web server',self.icon('proxy.ico'))item.connect('activate',self._serve_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::75recover','Recovery','General repair and recovery of repository',self.icon('general.ico'))item.connect('activate',self._recovery_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::80repoconfig','Repository Settings','Configure Mercurial settings for this repo',self.icon('menusettings.ico'))item.connect('activate',self._thgconfig_repo_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::85userconfig','User-Global Settings','Configure global Mercurial settings',self.icon('menusettings.ico'))item.connect('activate',self._thgconfig_user_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::99about','About TortoiseHg','Information about TortoiseHg installation',self.icon('menuabout.ico'))item.connect('activate',self._about_cb,vfs_file)submenu.append_item(item)returnmainitem,defget_file_items(self,window,vfs_files):mainitem=nautilus.MenuItem('HgNautilus','Mercurial','')submenu=nautilus.Menu()mainitem.set_submenu(submenu)'''Build context menu for selected files'''ifnotvfs_files:returnNonevfs_file=vfs_files[0]path=self.get_path_for_vfs_file(vfs_file)repo=self.get_repo_for_path(path)ifrepoisNone:ifnotvfs_file.is_directory():returnNone# Menu for unrevisioned subdirectoryname=vfs_files[0].get_name()item=nautilus.MenuItem('HgNautilus::10newtree','Make directory versioned','Create Repository in %s'%name,self.icon('menucreaterepos.ico'))item.connect('activate',self._init_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::20clone','Create clone from source','Create Clone in %s'%name,self.icon('menuclone.ico'))item.connect('activate',self._clone_cb,vfs_file)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::99about','About TortoiseHg','Information about TortoiseHg installation',self.icon('menuabout.ico'))item.connect('activate',self._about_cb,vfs_file)submenu.append_item(item)returnmainitem,localpaths=[]forvfs_fileinvfs_files:path=self.get_path_for_vfs_file(vfs_file)ifpathisNone:continuelocalpath=path[len(repo.root)+1:]localpaths.append(localpath)ifnotlocalpaths:returnpath=localpaths[0]cwd=os.path.isdir(path)andpathoros.path.dirname(path)matcher=match.exact(repo.root,cwd,localpaths)changes=repo.dirstate.status(matcher,True,True,True)(lookup,modified,added,removed,deleted,unknown,ignored,clean)=changes# Add menu items based on states listifunknown:item=nautilus.MenuItem('HgNautilus::30add','Add Files','Add unversioned files',self.icon('menuadd.ico'))item.connect('activate',self._add_cb,vfs_files)submenu.append_item(item)ifmodifiedoraddedorremovedordeletedorunknown:item=nautilus.MenuItem('HgNautilus::40commit','Commit Files','Commit changes',self.icon('menucommit.ico'))item.connect('activate',self._commit_cb,vfs_files)submenu.append_item(item)item=nautilus.MenuItem('HgNautilus::50revert','Undo Changes','Revert changes to files',self.icon('menurevert.ico'))item.connect('activate',self._revert_cb,vfs_files)submenu.append_item(item)ifmodifiedorclean:item=nautilus.MenuItem('HgNautilus::60log','File Changelog','Show file revision history',self.icon('menulog.ico'))item.connect('activate',self._history_cb,vfs_files)item=nautilus.MenuItem('HgNautilus::annotate','Annotate File','Annotate file at current revision',self.icon('menulog.ico'))item.connect('activate',self._datamine_cb,vfs_files)submenu.append_item(item)ifmodified:item=nautilus.MenuItem('HgNautilus::70diff','File Diffs','Show file changes',self.icon('menudiff.ico'))item.connect('activate',self._diff_cb,vfs_files)submenu.append_item(item)returnmainitem,defget_columns(self):returnnautilus.Column("HgNautilus::80hg_status","hg_status","HG Status","Version control status"),def_get_file_status(self,repo,localpath):emblem=Nonestatus='?'# This is not what the API is optimized for, but this appears# to work efficiently enoughmatcher=match.always(repo.root,localpath)changes=repo.dirstate.status(matcher,True,True,True)(lookup,modified,added,removed,deleted,unknown,ignored,clean)=changesiflocalpathinclean:emblem='default'status='clean'eliflocalpathinmodified:emblem='cvs-modified'status='modified'eliflocalpathinadded:emblem='cvs-aded'status='added'eliflocalpathinunknown:emblem='new'status='unrevisioned'eliflocalpathinignored:status='ignored'eliflocalpathindeleted:# Should be hard to reach this stateemblem='stockmail-priority-high'status='deleted'returnemblem,statusdefupdate_file_info(self,file):'''Return emblem and hg status for this file'''path=self.get_path_for_vfs_file(file)ifpathisNoneorfile.is_directory():returnrepo=self.get_repo_for_path(path)ifrepoisNone:returnlocalpath=path[len(repo.root)+1:]emblem,status=self._get_file_status(repo,localpath)ifemblemisnotNone:file.add_emblem(emblem)file.add_string_attribute('hg_status',status)# property page borrowed from http://www.gnome.org/~gpoo/hg/nautilus-hg/def__add_row(self,table,row,label_item,label_value):label=gtk.Label(label_item)label.set_use_markup(True)label.set_alignment(1,0)table.attach(label,0,1,row,row+1,gtk.FILL,gtk.FILL,0,0)label.show()label=gtk.Label(label_value)label.set_use_markup(True)label.set_alignment(0,1)label.show()table.attach(label,1,2,row,row+1,gtk.FILL,0,0,0)defget_property_pages(self,vfs_files):iflen(vfs_files)!=1:returnfile=vfs_files[0]path=self.get_path_for_vfs_file(file)ifpathisNoneorfile.is_directory():returnrepo=self.get_repo_for_path(path)ifrepoisNone:returnlocalpath=path[len(repo.root)+1:]emblem,status=self._get_file_status(repo,localpath)# Get the information from Mercurial ctx = repo.changectx(None).parents()[0]
try:
fctx = ctx.filectx(localpath)
- rev = fctx.filelog().linkrev(fctx.filenode())
+ rev = fctx.filelog().linkrev(fctx.filerev())
except:
rev = ctx.rev()
ctx = repo.changectx(rev)
node=short(ctx.node())date=util.datestr(ctx.date(),'%Y-%m-%d %H:%M:%S %1%2')parents='\n'.join([short(p.node())forpinctx.parents()])description=ctx.description()user=ctx.user()user=gobject.markup_escape_text(user)tags=', '.join(ctx.tags())branch=ctx.branch()self.property_label=gtk.Label('Mercurial')table=gtk.Table(7,2,False)table.set_border_width(5)table.set_row_spacings(5)table.set_col_spacings(5)self.__add_row(table,0,'<b>Status</b>:',status)self.__add_row(table,1,'<b>Last-Commit-Revision</b>:',str(rev))self.__add_row(table,2,'<b>Last-Commit-Description</b>:',description)self.__add_row(table,3,'<b>Last-Commit-Date</b>:',date)self.__add_row(table,4,'<b>Last-Commit-User</b>:',user)iftags:self.__add_row(table,5,'<b>Tags</b>:',tags)ifbranch!='default':self.__add_row(table,6,'<b>Branch</b>:',branch)table.show()returnnautilus.PropertyPage("MercurialPropertyPage::status",self.property_label,table),
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.