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.
# repotreeitem.py - treeitems for the reporegistry## Copyright 2010 Adrian Buehlmann <adrian@cadifra.com>## This software may be used and distributed according to the terms of the# GNU General Public License version 2 or any later version.importsys,osfrommercurialimportnodefrommercurialimportui,hg,util,errorfromtortoisehg.utilimporthglibfromtortoisehg.hgqt.i18nimport_fromtortoisehg.hgqtimportqtlib,hgrcutilfromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*xmlClassMap={'allgroup':'AllRepoGroupItem','group':'RepoGroupItem','repo':'RepoItem','subrepo':'SubrepoItem','treeitem':'RepoTreeItem',}inverseXmlClassMap={}defxmlToClass(ele):returnxmlClassMap[ele]defclassToXml(classname):iflen(inverseXmlClassMap)==0:fork,vinxmlClassMap.iteritems():inverseXmlClassMap[v]=kreturninverseXmlClassMap[classname]defundumpObject(xr):classname=xmlToClass(str(xr.name().toString()))class_=getattr(sys.modules[RepoTreeItem.__module__],classname)obj=class_()obj.undump(xr)returnobjclassRepoTreeItem(object):def__init__(self,parent=None):self._parent=parentself.childs=[]self._row=0defappendChild(self,child):child._row=len(self.childs)child._parent=selfself.childs.append(child)definsertChild(self,row,child):child._row=rowchild._parent=selfself.childs.insert(row,child)defchild(self,row):returnself.childs[row]defchildCount(self):returnlen(self.childs)defcolumnCount(self):return2defdata(self,column,role):returnQVariant()defsetData(self,column,value):returnFalsedefrow(self):returnself._rowdefparent(self):returnself._parentdefmenulist(self):return[]defflags(self):returnQt.NoItemFlagsdefremoveRows(self,row,count):cs=self.childsremove=cs[row:row+count]keep=cs[:row]+cs[row+count:]self.childs=keepforcinremove:c._row=0c._parent=Nonefori,cinenumerate(keep):c._row=ireturnTruedefdump(self,xw):forcinself.childs:c.dumpObject(xw)defundump(self,xr):whilenotxr.atEnd():xr.readNext()ifxr.isStartElement():try:item=undumpObject(xr)self.appendChild(item)exceptKeyError:pass# ignore unknown classes in xmlelifxr.isEndElement():breakdefdumpObject(self,xw):xw.writeStartElement(classToXml(self.__class__.__name__))self.dump(xw)xw.writeEndElement()defisRepo(self):returnFalsedefdetails(self):return''defgetRepoItem(self,reporoot,lookForSubrepos=False):forcinself.childs:ri=c.getRepoItem(reporoot,lookForSubrepos=lookForSubrepos)ifri:returnrireturnNonedefokToDelete(self):returnTruedefgetSupportedDragDropActions(self):returnQt.MoveActionclassRepoItem(RepoTreeItem):shortnameChanged=pyqtSignal()def__init__(self,root=None,parent=None):RepoTreeItem.__init__(self,parent)self._root=rootor''self._shortname=u''self._basenode=node.nullidself._repotype='hg'# The _valid property is used to display a "warning" icon for repos# that cannot be open# If root is set we assume that the repo is valid (an actual validity# test would require calling hg.repository() which is expensive)# Regardless, self._valid may be set to False if self.undump() failsifself._root:self._valid=Trueelse:self._valid=Falseself._isActiveTab=FalsedefisRepo(self):returnTruedefrootpath(self):returnself._rootdefshortname(self):ifself._shortname:returnself._shortnameelse:returnhglib.tounicode(os.path.basename(self._root))defrepotype(self):returnself._repotypedefbasenode(self):"""Return node id of revision 0"""returnself._basenodedefsetBaseNode(self,basenode):self._basenode=basenodedefsetShortName(self,uname):ifuname!=self._shortname:self._shortname=unamedefdata(self,column,role):ifrole==Qt.DecorationRole:ifcolumn==0:ico=qtlib.geticon('hg')ifnotself._valid:ico=qtlib.getoverlaidicon(ico,qtlib.geticon('dialog-warning'))returnQVariant(ico)returnQVariant()elifrole==Qt.FontRole:ifself._isActiveTab:font=QFont()font.setBold(True)else:returnQVariant()returnQVariant(font)ifcolumn==0:returnQVariant(self.shortname())elifcolumn==1:returnQVariant(self.shortpath())returnQVariant()defgetCommonPath(self):returnself.parent().getCommonPath()defshortpath(self):try:cpath=self.getCommonPath()except:cpath=''spath=os.path.normpath(self._root)ifcpathandspath.startswith(cpath):iShortPathStart=len(cpath)+1spath=spath[iShortPathStart:]returnhglib.tounicode(spath)defmenulist(self):return['open','clone','addsubrepo',None,'explore','terminal','copypath',None,'rename','remove',None,'settings']defflags(self):return(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsDragEnabled|Qt.ItemIsEditable)defdump(self,xw):xw.writeAttribute('root',hglib.tounicode(self._root))xw.writeAttribute('shortname',self.shortname())xw.writeAttribute('basenode',node.hex(self.basenode()))defundump(self,xr):self._valid=Truea=xr.attributes()self._root=hglib.fromunicode(a.value('','root').toString())self._shortname=unicode(a.value('','shortname').toString())self._basenode=node.bin(str(a.value('','basenode').toString()))RepoTreeItem.undump(self,xr)defdetails(self):return_('Local Repository %s')%hglib.tounicode(self._root)defgetRepoItem(self,reporoot,lookForSubrepos=False):reporoot=os.path.normcase(reporoot)if(reporoot==os.path.normcase(self._root)):returnselfiflookForSubrepos:returnsuper(RepoItem,self).getRepoItem(reporoot,lookForSubrepos)returnNonedefappendSubrepos(self,repo=None):invalidRepoList=[]try:sri=NoneifrepoisNone:repo=hg.repository(ui.ui(),self._root)wctx=repo['.']forsubpathinwctx.substate:sri=Noneabssubpath=repo.wjoin(subpath)subtype=wctx.substate[subpath][2]sriIsValid=os.path.isdir(abssubpath)sri=SubrepoItem(abssubpath,subtype=subtype)sri._valid=sriIsValidself.appendChild(sri)ifnotsriIsValid:self._valid=Falsesri._valid=FalseinvalidRepoList.append(repo.wjoin(subpath))returninvalidRepoListcontinueifsubtype=='hg':# Only recurse into mercurial subrepossctx=wctx.sub(subpath)invalidSubrepoList=sri.appendSubrepos(sctx._repo)ifinvalidSubrepoList:self._valid=FalseinvalidRepoList+=invalidSubrepoListexcept(EnvironmentError,error.RepoError,util.Abort),e:# Add the repo to the list of repos/subrepos# that could not be openself._valid=Falseifsri:sri._valid=FalseinvalidRepoList.append(abssubpath)invalidRepoList.append(self._root)returninvalidRepoListdefsetActive(self,sel):# Will be set to true when this item corresponds to the currently# selected tab widget on the workbenchself._isActiveTab=seldefsetData(self,column,value):ifcolumn==0:shortname=hglib.fromunicode(value.toString())abshgrcpath=os.path.join(self.rootpath(),'.hg','hgrc')ifnothgrcutil.setConfigValue(abshgrcpath,'web.name',shortname):qtlib.WarningMsgBox(_('Unable to update repository name'), _('An error occurred while updating the repository hgrc '
'file (%s)' % abshgrcpath))
return False
+ self.setShortName(shortname) return True
return False
classSubrepoItem(RepoItem):_subrepoType2IcoMap={'hg':'hg','git':'thg-git-subrepo','svn':'thg-svn-subrepo',}def__init__(self,repo=None,parent=None,parentrepo=None,subtype='hg'):RepoItem.__init__(self,repo,parent)self._parentrepo=parentrepoself._repotype=subtypeifself._repotype!='hg':# Make sure that we cannot drag non hg subrepos# To do so we disable the dumpObject method for non hg subreposdefdoNothing(dummy):passself.dumpObject=doNothing# Limit the context menu to those actions that are valid for non# mercurial subreposdefnonHgMenulist():return['remove',None,'explore','terminal']self.menulist=nonHgMenulistdefdata(self,column,role):ifrole==Qt.DecorationRole:ifcolumn==0:subiconame=SubrepoItem._subrepoType2IcoMap.get(self._repotype,None)ifsubiconameisNone:# Unknown (or generic) subrepo typeico=qtlib.geticon('thg-subrepo')else:# Overlay the "subrepo icon" on top of the selected subrepo# type iconico=qtlib.geticon(subiconame)ico=qtlib.getoverlaidicon(ico,qtlib.geticon('thg-subrepo'))ifnotself._valid:ico=qtlib.getoverlaidicon(ico,qtlib.geticon('dialog-warning'))returnQVariant(ico)returnQVariant()else:returnsuper(SubrepoItem,self).data(column,role)defmenulist(self):ifisinstance(self._parent,RepoGroupItem):returnsuper(SubrepoItem,self).menulist()else:return['open','clone','addsubrepo',None,'explore','terminal','copypath',None,'settings']defgetSupportedDragDropActions(self):ifissubclass(type(self.parent()),RepoGroupItem):returnQt.MoveActionelse:returnQt.CopyActiondefflags(self):# Only stand-alone subrepo items can be renamedifisinstance(self._parent,RepoGroupItem):returnsuper(SubrepoItem,self).flags()else:return(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsDragEnabled)classRepoGroupItem(RepoTreeItem):def__init__(self,name=None,parent=None):RepoTreeItem.__init__(self,parent)ifname:self.name=nameelse:self.name=QString()self._commonpath=''defdata(self,column,role):ifrole==Qt.DecorationRole:ifcolumn==0:s=QApplication.style()ico=s.standardIcon(QStyle.SP_DirIcon)returnQVariant(ico)returnQVariant()ifcolumn==0:returnQVariant(self.name)elifcolumn==1:returnQVariant(self.getCommonPath())returnQVariant()defsetData(self,column,value):ifcolumn==0: self.name = value.toString()
return True
return False
+ def menulist(self):
return ['openAll', 'add', None, 'newGroup', None, 'rename', 'remove',
None, 'reloadRegistry']
+ def flags(self):
return (Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDropEnabled
| Qt.ItemIsDragEnabled | Qt.ItemIsEditable)
defchildRoots(self):return[c._rootforcinself.childs]defdump(self,xw):xw.writeAttribute('name',self.name)RepoTreeItem.dump(self,xw)defundump(self,xr):a=xr.attributes()self.name=a.value('','name').toString()RepoTreeItem.undump(self,xr)defokToDelete(self):returnFalsedefupdateCommonPath(self,cpath=None):""" Update or set the group 'common path' When called with no arguments, the group common path is calculated by looking for the common path of all the repos on a repo group When called with an argument, the group common path is set to the input argument. This is commonly used to set the group common path to an empty string, thus disabling the "show short paths" functionality. """ifnotcpathisNone:self._commonpath=cpatheliflen(self.childs)==0:# If a group has no repo items, the common path is emptyself._commonpath=''else:# Calculate the group common pathdefsplitPath(path):path=os.path.normpath(path)returnpath.split(os.path.sep)[:-1]cpath=splitPath(self.childs[0].rootpath())forcinself.childs[1:]:ifnotcpath:# There is no common pathbreak# Update the common path to the common path with the current# childchildpath=splitPath(c.rootpath())# The common part cannot go beyond the smaller of the current# common path and the current childclen=min(len(cpath),len(childpath))cpath=cpath[:clen]childpath=childpath[:clen]ifcpath==childpath:# Trivial casecontinueforninrange(clen):# From left to right, find the first path part that is not# the sameifcpath[n]!=childpath[n]:cpath=cpath[:n]breakself._commonpath=os.path.sep.join(cpath)returnself._commonpathdefgetCommonPath(self):returnself._commonpathclass AllRepoGroupItem(RepoGroupItem):
def __init__(self, parent=None):
RepoGroupItem.__init__(self, name=_('default'), parent=parent)
+ def menulist(self):
return ['openAll', 'add', None, 'newGroup', None, 'rename',
None, 'reloadRegistry']
+ def undump(self, xr):
a = xr.attributes()
name = a.value('', 'name').toString()
ifname:self.name=nameRepoTreeItem.undump(self,xr)
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.