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.
importgtkimportos.pathimportsysimporttracebackimportthreading,thread2importurllib2importQueuefrommercurialimporthg,ui,util,extensions,commands,hookfrommercurial.i18nimport_fromdialogimportentry_dialogtry:frommercurial.errorimportRepoError,ParseError,LookupErrorfrommercurial.errorimportUnknownCommand,AmbiguousCommandexceptImportError:frommercurial.cmdutilimportUnknownCommand,AmbiguousCommandfrommercurial.repoimportRepoErrorfrommercurial.dispatchimportParseErrorfrommercurial.revlogimportLookupErrorfrommercurialimportdispatchtry:frommercurialimportencoding_encoding=encoding.encoding_encodingmode=encoding.encodingmode_fallbackencoding=encoding.fallbackencodingexceptImportError:_encoding=util._encoding_encodingmode=util._encodingmode_fallbackencoding=util._fallbackencodingdeftoutf(s):""" Convert a string to UTF-8 encoding Based on mercurial.util.tolocal() """forein('utf-8',_encoding):try:returns.decode(e,'strict').encode('utf-8')exceptUnicodeDecodeError:passreturns.decode(_fallbackencoding,'replace').encode('utf-8')deffromutf(s):""" Convert UTF-8 encoded string to local. It's primarily used on strings converted to UTF-8 by toutf(). """try:returns.decode('utf-8').encode(_encoding)exceptUnicodeDecodeError:passexceptUnicodeEncodeError:passreturns.decode('utf-8').encode(_fallbackencoding)defrootpath(path=None):""" find Mercurial's repo root of path """ifnotpath:path=os.getcwd()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:return''returnp_tabwidth=Nonedefgettabwidth(ui):global_tabwidthtabwidth=ui.config('tortoisehg','tabwidth')try:tabwidth=int(tabwidth)iftabwidth<1ortabwidth>16:tabwidth=0except(ValueError,TypeError):tabwidth=0_tabwidth=tabwidthreturntabwidthdefdiffexpand(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 '''buffers=getattr(u,'_buffers',None)ifbuffers==None:buffers=u.buffersifbuffers:ui.ui.write(u,*args)returnFalsereturnTruedefcalliffunc(f):returnhasattr(f,'__call__')andf()orfclassGtkUi(ui.ui):''' PyGtk enabled mercurial.ui subclass. All this code will be running in a background thread, so it cannot directly call into Gtk. Instead, it places output and dialog requests onto queues for the main thread to pickup. '''def__init__(self,src=None,outputq=None,dialogq=None,responseq=None,parentui=None):ifparentui:src=parentuisuper(GtkUi,self).__init__(src)ifsrc:self.outputq=src.outputqself.dialogq=src.dialogqself.responseq=src.responseqelse:self.outputq=outputqself.dialogq=dialogqself.responseq=responseqself.setconfig('ui','interactive','on')defwrite(self,*args):ifuiwrite(self,args):forainargs:self.outputq.put(str(a))defwrite_err(self,*args):forainargs:self.outputq.put('*** '+str(a))defflush(self):passdefprompt(self,msg,pat=None,default="y"):importreifnotcalliffunc(self.interactive):returndefaultwhileTrue:try:# send request to main thread, await responseself.dialogq.put((msg,True,default))r=self.responseq.get(True)ifrisNone:raiseEOFErrorifnotr:returndefaultifnotpatorre.match(pat,r):returnrelse:self.write(_('unrecognized response\n'))exceptEOFError:raiseutil.Abort(_('response expected'))defgetpass(self,prompt=None,default=None):# send request to main thread, await responseself.dialogq.put((promptor_('password: '),False,default))r=self.responseq.get(True)ifrisNone:raiseutil.Abort(_('response expected'))returnrdefprint_exc(self):traceback.print_exc()returnTrueclassHgThread(thread2.Thread):''' Run an hg command in a background thread, implies output is being sent to a rendered text buffer interactively and requests for feedback from Mercurial can be handled by the user via dialog windows. '''def__init__(self,args=[],postfunc=None,parent=None):self.outputq=Queue.Queue()self.dialogq=Queue.Queue()self.responseq=Queue.Queue()self.ui=GtkUi(None,self.outputq,self.dialogq,self.responseq)self.args=argsself.ret=Noneself.postfunc=postfuncself.parent=parentthread2.Thread.__init__(self)defgetqueue(self):returnself.outputqdefreturn_code(self):''' None - command is incomplete, possibly exited with exception 0 - command returned successfully else an error was returned '''returnself.retdefprocess_dialogs(self):'''Polled every 10ms to serve dialogs for the background thread'''try:(prompt,visible,default)=self.dialogq.get_nowait()self.dlg=entry_dialog(self.parent,prompt,visible,default,self.dialog_response)exceptQueue.Empty:passdefdialog_response(self,widget,response_id):ifresponse_id==gtk.RESPONSE_OK:text=self.dlg.entry.get_text()else:text=Noneself.dlg.destroy()self.responseq.put(text)defrun(self):try:ret=Noneifhasattr(self.ui,'copy'):# Mercurial 1.3ret=dispatch._dispatch(self.ui,self.args)else:# Mercurial 1.2 # Some commands create repositories, and thus must create
# new ui() instances. For those, we monkey-patch ui.ui()
# as briefly as possible.
+ origui = None if self.args[0] in ('clone', 'init'):
origui = ui.ui
ui.ui = GtkUi
try:ret=thgdispatch(self.ui,None,self.args)finally:iforigui:ui.ui=origuiifret:self.ui.write(_('[command returned code %d]\n')%int(ret))else:self.ui.write(_('[command completed successfully]\n'))self.ret=retor0ifself.postfunc:self.postfunc(ret)exceptRepoError,e:self.ui.write_err(str(e))exceptutil.Abort,e:self.ui.write_err(str(e))ifself.ui.traceback:self.ui.print_exc()excepturllib2.HTTPError,e:self.ui.write_err(str(e)+'\n')exceptException,e:self.ui.write_err(str(e))self.ui.print_exc()def_earlygetopt(aliases,args):"""Return list of values for an option (or aliases). The values are listed in the order they appear in args. The options and values are removed from args. """try:argcount=args.index("--")exceptValueError:argcount=len(args)shortopts=[optforoptinaliasesiflen(opt)==2]values=[]pos=0whilepos<argcount:ifargs[pos]inaliases:ifpos+1>=argcount:# ignore and let getopt report an error if there is no valuebreakdelargs[pos]values.append(args.pop(pos))argcount-=2elifargs[pos][:2]inshortopts:# short option can have no following space, e.g. hg log -Rfoovalues.append(args.pop(pos)[2:])argcount-=1else:pos+=1returnvalues_loaded={}defthgdispatch(ui,path=None,args=[],nodefaults=True):''' Replicate functionality of mercurial dispatch but force the use of the passed in ui for all purposes '''# clear all user-defined command defaultsifnodefaults:fork,vinui.configitems('defaults'):ui.setconfig('defaults',k,'')# read --config before doing anything else# (e.g. to change trust settings for reading .hg/hgrc)config=_earlygetopt(['--config'],args)ifconfig:forsection,name,valueindispatch._parseconfig(config):self.setconfig(section,name,value)# check for cwdcwd=_earlygetopt(['--cwd'],args)ifcwd:os.chdir(cwd[-1])# read the local repository .hgrc into a local ui objectpath=rootpath(path)or""ifpath:try:ui.readconfig(os.path.join(path,".hg","hgrc"))exceptIOError:pass# now we can expand paths, even ones in .hg/hgrcrpath=_earlygetopt(["-R","--repository","--repo"],args)ifrpath:path=ui.expandpath(rpath[-1])extensions.loadall(ui)ifnothasattr(extensions,'extensions'):extensions.extensions=lambda:()# pre-0.9.5, loadall did belowforname,moduleinextensions.extensions():ifnamein_loaded:continue# setup extensionsextsetup=getattr(module,'extsetup',None)ifextsetup:extsetup()cmdtable=getattr(module,'cmdtable',{})overrides=[cmdforcmdincmdtableifcmdincommands.table]ifoverrides:ui.warn(_("extension '%s' overrides commands: %s\n")%(name," ".join(overrides)))commands.table.update(cmdtable)_loaded[name]=1# check for fallback encodingfallback=ui.config('ui','fallbackencoding')iffallback:_fallbackencoding=fallbackfullargs=argscmd,func,args,options,cmdoptions=dispatch._parse(ui,args)ifoptions["encoding"]:_encoding=options["encoding"]ifoptions["encodingmode"]:_encodingmode=options["encodingmode"]ifoptions['verbose']oroptions['debug']oroptions['quiet']:ui.setconfig('ui','verbose',str(bool(options['verbose'])))ui.setconfig('ui','debug',str(bool(options['debug'])))ui.setconfig('ui','quiet',str(bool(options['quiet'])))ifoptions['traceback']:ui.setconfig('ui','traceback','on')ifoptions['noninteractive']:ui.setconfig('ui','interactive','off')ifoptions['help']:returncommands.help_(ui,cmd,options['version'])elifoptions['version']:returncommands.version_(ui)elifnotcmd:returncommands.help_(ui,'shortlist')repo=Noneifcmdnotincommands.norepo.split():try:repo=hg.repository(ui,path=path)repo.ui=uiui.setconfig("bundle","mainreporoot",repo.root)ifnotrepo.local():raiseutil.Abort(_("repository '%s' is not local")%path)exceptRepoError:ifcmdnotincommands.optionalrepo.split():ifnotpath:raiseRepoError(_('There is no Mercurial repository here'' (.hg not found)'))raised=lambda:func(ui,repo,*args,**cmdoptions)else:d=lambda:func(ui,*args,**cmdoptions)# run pre-hook, and abort if it failsret=hook.hook(ui,repo,"pre-%s"%cmd,False,args=" ".join(fullargs))ifret:returnret# Run actual commandtry:ret=d()exceptTypeError:# was this an argument error?tb=traceback.extract_tb(sys.exc_info()[2])iflen(tb)!=2:# noraiseraiseParseError(cmd,_('invalid arguments'))# run post-hook, passing command resulthook.hook(ui,repo,"post-%s"%cmd,False,args=" ".join(fullargs),result=ret)returnretdefhgcmd_toq(path,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()returnthgdispatch(u,path,list(args))defdisplaytime(date):returnutil.datestr(date,'%Y-%m-%d %H:%M:%S %1%2')
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.