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.
# hglib.py - Mercurial API wrappers for TortoiseHg## Copyright 2007 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.importosimportsysimportshleximporttimeimportinspectfrommercurialimportui,util,extensions,match,bundlerepo,urlfrommercurialimportdispatch,encoding,templatefilters,filemerge_encoding=encoding.encoding_encodingmode=encoding.encodingmode_fallbackencoding=encoding.fallbackencodingfromtortoisehg.utilimportpathsfromtortoisehg.util.i18nimport_fromtortoisehg.util.hgversionimporthgversiondeftounicode(s):""" Convert the encoding of string from MBCS to Unicode. Based on mercurial.util.tolocal(). Return 'unicode' type string. """ifisinstance(s,unicode):returnsforein('utf-8',_encoding):try:returns.decode(e,'strict')exceptUnicodeDecodeError:passreturns.decode(_fallbackencoding,'replace')deftoutf(s):""" Convert the encoding of string from MBCS to UTF-8. Return 'str' type string. """returntounicode(s).encode('utf-8')deffromutf(s):""" Convert the encoding of string from UTF-8 to MBCS Return 'str' type string. """try:returns.decode('utf-8').encode(_encoding)except(UnicodeDecodeError,UnicodeEncodeError):passtry:returns.decode('utf-8').encode(_fallbackencoding)except(UnicodeDecodeError,UnicodeEncodeError):passu=s.decode('utf-8','replace')# last ditchreturnu.encode(_encoding,'replace')_tabwidth=Nonedefgettabwidth(ui):global_tabwidthif_tabwidthisnotNone:return_tabwidthtabwidth=ui.config('tortoisehg','tabwidth')try:tabwidth=int(tabwidth)iftabwidth<1ortabwidth>16:tabwidth=0except(ValueError,TypeError):tabwidth=0_tabwidth=tabwidthreturntabwidth_maxdiff=Nonedefgetmaxdiffsize(ui):global_maxdiffif_maxdiffisnotNone:return_maxdiffmaxdiff=ui.config('tortoisehg','maxdiff')try:maxdiff=int(maxdiff)ifmaxdiff<1:maxdiff=sys.maxintexcept(ValueError,TypeError):maxdiff=1024# 1MB by default_maxdiff=maxdiff*1024return_maxdiff_deadbranch=Nonedefgetdeadbranch(ui):global_deadbranchif_deadbranchisNone:db=toutf(ui.config('tortoisehg','deadbranch',''))dblist=[b.strip()forbindb.split(',')]_deadbranch=dblistreturn_deadbranchdefgetlivebranch(repo):lives=[]deads=getdeadbranch(repo.ui)forbranchinrepo.branchtags().keys():ifbranchnotindeads:lives.append(branch)returnlives_hidetags=Nonedefgethidetags(ui):global_hidetagsif_hidetagsisNone:tags=toutf(ui.config('tortoisehg','hidetags',''))taglist=[t.strip()fortintags.split()]_hidetags=taglistreturn_hidetagsdefdiffexpand(line):'Expand tabs in a line of diff/patch text'if_tabwidthisNone:gettabwidth(ui.ui())ifnot_tabwidthorlen(line)<2:returnlinereturnline[0]+line[1:].expandtabs(_tabwidth)defuiwrite(u,args):''' write args if there are buffers returns True if the caller shall handle writing '''ifu._buffers:ui.ui.write(u,*args)returnFalsereturnTruedefinvalidaterepo(repo):repo.dirstate.invalidate()ifisinstance(repo,bundlerepo.bundlerepository):# Work around a bug in hg-1.3. repo.invalidate() breaks# overlay bundlereposreturnrepo.invalidate()# way _bookmarks / _bookmarkcurrent cached changed# from 1.4 to 1.5...forcachedAttrin('_bookmarks','_bookmarkcurrent'):# Check if it's a property or normal value...ifis_descriptor(repo,cachedAttr):# The very act of calling hasattr would# re-cache the property, so just assume it's# already cached, and catch the error if it wasn't.try:delattr(repo,cachedAttr)exceptAttributeError:passelifhasattr(repo,cachedAttr):setattr(repo,cachedAttr,None)if'mq'inrepo.__dict__:#do not create if it does not existrepo.mq.invalidate()defloadextension(ui,name):# Between Mercurial revisions 1.2 and 1.3, extensions.load() stopped# calling uisetup() after loading an extension. This could do# unexpected things if you use an hg version < 1.3extensions.load(ui,name,None)mod=extensions.find(name)uisetup=getattr(mod,'uisetup',None)ifuisetup:uisetup(ui)defcanonpaths(list):'Get canonical paths (relative to root) for list of files'# This is a horrible hack. Please remove this when HG acquires a# decent case-folding solution.canonpats=[]cwd=os.getcwd()root=paths.find_root(cwd)forfinlist:try:canonpats.append(util.canonpath(root,cwd,f))exceptutil.Abort:# Attempt to resolve case folding conflicts.fu=f.upper()cwdu=cwd.upper()iffu.startswith(cwdu):canonpats.append(util.canonpath(root,cwd,f[len(cwd+os.sep):]))else:# May already be canonicalcanonpats.append(f)returncanonpatsdefnormpats(pats):'Normalize file patterns'normpats=[]forpatinpats:kind,p=match._patsplit(pat,None)ifkind:normpats.append(pat)else:if'['inpor'{'inpor'*'inpor'?'inp:normpats.append('glob:'+p)else:normpats.append('path:'+p)returnnormpatsdefmergetools(ui,values=None):'returns the configured merge tools and the internal ones'ifvalues==None:values=[]forkey,valueinui.configitems('merge-tools'):t=key.split('.')[0]iftnotinvalues:# Ensure the tool is installediffilemerge._findtool(ui,t):values.append(t)values.append('internal:merge')values.append('internal:prompt')values.append('internal:dump')values.append('internal:local')values.append('internal:other')values.append('internal:fail')returnvalues_difftools=Nonedefdifftools(ui):global_difftoolsif_difftools:return_difftools def fixup_extdiff(diffopts):
if '$child' not in diffopts:
- diffopts += '$parent1 $child'
+ diffopts.append('$parent1')+ diffopts.append('$child') if '$parent2' in diffopts:
- mergeopts = diffopts
- diffopts = diffopts.replace('$parent2', '')
+ mergeopts = diffopts[:]+ diffopts.remove('$parent2')
else:
- mergeopts = None+ mergeopts = [] return diffopts, mergeopts
tools = {}
forcmd,pathinui.configitems('extdiff'):ifcmd.startswith('cmd.'):cmd=cmd[4:] if not path:
path = cmd
diffopts = ui.config('extdiff', 'opts.' + cmd, '')
+ diffopts = shlex.split(diffopts) diffopts, mergeopts = fixup_extdiff(diffopts)
tools[cmd] = [path, diffopts, mergeopts]
elif cmd.startswith('opts.'):
continueelse:# command = path optsifpath:diffopts=shlex.split(path) path = diffopts.pop(0)
else:
path, diffopts = cmd, []
- diffopts, mergeopts = fixup_extdiff(' '.join(diffopts))+ diffopts, mergeopts = fixup_extdiff(diffopts)
tools[cmd] = [path, diffopts, mergeopts]
mt = []
mergetools(ui, mt)
fortinmt:ift.startswith('internal:'):continuedopts=ui.config('merge-tools',t+'.diffargs','')mopts=ui.config('merge-tools',t+'.diff3args','')dopts,mopts=shlex.split(dopts),shlex.split(mopts)tools[t]=[filemerge._findtool(ui,t),dopts,mopts]_difftools=toolsreturntoolsdefhgcmd_toq(q,*args):''' Run an hg command in a background thread, pipe all output to a Queue object. Assumes command is completely noninteractive. '''classQui(ui.ui):def__init__(self,src=None):super(Qui,self).__init__(src)self.setconfig('ui','interactive','off')defwrite(self,*args):ifuiwrite(self,args):forainargs:q.put(str(a))u=Qui()fork,vinu.configitems('defaults'):u.setconfig('defaults',k,'')returndispatch._dispatch(u,list(args))defget_reponame(repo):ifrepo.ui.config('tortoisehg','fullpath',False):name=repo.rootelifrepo.ui.config('web','name',False):name=repo.ui.config('web','name')else:name=os.path.basename(repo.root)returntoutf(name)defdisplaytime(date):returnutil.datestr(date,'%Y-%m-%d %H:%M:%S %1%2')defutctime(date):returntime.strftime("%Y-%m-%d %H:%M:%S",time.gmtime(date[0]))defage(date):returntemplatefilters.age(date)defusername(user):author=templatefilters.person(user)ifnotauthor:author=util.shortuser(user)returnauthordefvalidate_synch_path(path,repo):''' Validate the path that must be used to sync operations (pull, push, outgoing and incoming) '''return_path=pathforalias,path_auxinrepo.ui.configitems('paths'):ifpath==alias:return_path=path_auxelifpath==url.hidepassword(path_aux):return_path=path_auxreturnreturn_pathdefget_repo_bookmarks(repo,values=False):""" Will return the bookmarks for the given repo if the bookmarks extension is loaded. By default, returns a list of bookmark names; if values is True, returns a dict mapping names to nodes. If the extension is not loaded, returns an empty list/dict. """try:bookmarks=extensions.find('bookmarks')exceptKeyError:returnvaluesand{}or[]ifbookmarks:# Bookmarks changed from 1.4 to 1.5...ifhasattr(bookmarks,'parse'):marks=bookmarks.parse(repo)elifhasattr(repo,'_bookmarks'):marks=repo._bookmarkselse:marks={}else:marks={}ifvalues:returnmarkselse:returnmarks.keys()defget_repo_bookmarkcurrent(repo):""" Will return the current bookmark for the given repo if the bookmarks extension is loaded, and the track.current option is on. If the extension is not loaded, or track.current is not set, returns None """try:bookmarks=extensions.find('bookmarks')exceptKeyError:returnNoneifbookmarksandrepo.ui.configbool('bookmarks','track.current'):# Bookmarks changed from 1.4 to 1.5...ifhasattr(bookmarks,'current'):returnbookmarks.current(repo)elifhasattr(repo,'_bookmarkcurrent'):returnrepo._bookmarkcurrentreturnNonedefis_rev_current(repo,rev):''' Returns True if the revision indicated by 'rev' is the current working directory parent. If rev is '' or None, it is assumed to mean 'tip'. '''ifrevin('',None):rev='tip'rev=repo.lookup(rev)parents=repo.parents()iflen(parents)>1:returnFalsereturnrev==parents[0].node()defis_descriptor(obj,attr):""" Returns True if obj.attr is a descriptor - ie, accessing the attribute will actually invoke the '__get__' method of some object. Returns False if obj.attr exists, but is not a descriptor, and None if obj.attr was not found at all. """forclsininspect.getmro(obj.__class__):ifattrincls.__dict__:returnhasattr(cls.__dict__[attr],'__get__')returnNone
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.