Changeset 8333:8b7f3b826d11


Ignore:
Timestamp:
12/01/07 20:13:13 (5 years ago)
Author:
Jonathan Hanke <jonhanke@…>
Branch:
default
Message:

Added support for hg_sage.push() and an option for a separate outgoing url/location, as well as some conveniences.

Added to HG class:

current_branch() -- Shows the current branch
list_branches() -- Lists all branches
push() -- Push to a remote repository

Here the default push() location is specified by the environment variable "SAGE_OUTGOING_SERVER".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/misc/hg.py

    r6993 r8333  
    2323######################################################################## 
    2424#       Copyright (C) 2006 William Stein <wstein@gmail.com> 
     25#                     2007 Jonathan Hanke <jonhanke@gmail.com> 
    2526# 
    2627#  Distributed under the terms of the GNU General Public License (GPL) 
     
    6263    \end{verbatim} 
    6364    """ 
    64     def __init__(self, dir, name, url, target=None, cloneable=False, obj_name=''): 
     65    def __init__(self, dir, name, pull_url, push_url, target=None, cloneable=False, obj_name=''): 
    6566        """ 
    6667        INPUT: 
    6768            dir -- directory that will contain the repository 
    6869            name -- a friendly name for the repository (only used for printing) 
    69             url -- a default URL to pull or record sends against (e.g., 
     70            pull_url -- a default URL to pull or record sends against (e.g., 
    7071                   this could be a master repository on modular.math.washington.edu) 
     72            push_url -- a default URL to push or record outgoing changes against (e.g., 
     73                   this could be a local repository on your favorite computer) 
    7174            target -- if the last part of dir is, e.g., sage-hg, 
    7275                      create a symlink from sage-hg to target. 
     
    7578        self.__dir = os.path.abspath(dir) 
    7679        self.__name = name 
    77         self.__url = url 
     80        self.__pull_url = pull_url 
     81        self.__push_url = push_url 
    7882        self.__initialized = False 
    7983        self.__target = target 
     
    8387    def __repr__(self): 
    8488        return "Hg repository '%s' in directory %s"%(self.__name, self.__dir) 
     89 
     90 
     91    def current_branch(self, print_flag=True): 
     92        """ 
     93        Lists the current branch. 
     94        """ 
     95        branch_name = branch_current_hg() 
     96        if print_flag: 
     97            print "The current branch is: " + branch_name 
     98        else: 
     99            return branch_name 
     100 
     101    def list_branches(self, print_flag=True): 
     102        """ 
     103        Print all branches in the current SAGE installation. 
     104        """ 
     105        try: 
     106            tmp_branch_list = [s[5:]  for s in os.listdir(SAGE_ROOT + "/devel")  if s.startswith("sage-")] 
     107        except: 
     108            raise RuntimeError, "Oops!  We had trouble...  Check that SAGE_ROOT gives the correct directory." 
     109 
     110        if print_flag: 
     111            print "Branches found:" 
     112            for s in tmp_branch_list: 
     113                print "    " + s 
     114        else: 
     115            return tmp_branch_list  
     116 
    85117 
    86118    def status(self): 
     
    557589        return self.__dir 
    558590 
    559     def url(self): 
     591    def pull_url(self): 
    560592        """ 
    561593        Return the default 'master url' for this repository. 
    562594        """ 
    563         return self.__url 
     595        return self.__pull_url 
     596 
     597    def push_url(self): 
     598        """ 
     599        Return the default url for uploading this repository. 
     600        """ 
     601        return self.__push_url 
    564602 
    565603 
     
    579617        Use this to find changsets that are in your branch, but not in the 
    580618        specified destination repository. If no destination is specified, the 
    581         official repository is used. 
     619        official repository is used.  By default, push_url() is used. 
    582620 
    583621        From the Mercurial documentation: 
     
    586624            a push was requested. 
    587625 
    588             See pull() for valid destination format details. 
    589  
    590         INPUT: 
    591             url:  default: self.url() -- the official repository 
     626            See push() for valid destination format details. 
     627 
     628        INPUT: 
     629            url:  default: self.push_url() -- the official repository 
    592630                   * http://[user@]host[:port]/[path] 
    593631                   * https://[user@]host[:port]/[path] 
     
    607645        """ 
    608646        if url is None: 
    609             url = self.__url 
     647            url = self.__push_url 
    610648 
    611649        if not '/' in url: 
     
    621659 
    622660        INPUT: 
    623             url:  default: self.url() -- the official repository 
     661            url:  default: self.pull_url() -- the official repository 
    624662                   * http://[user@]host[:port]/[path] 
    625663                   * https://[user@]host[:port]/[path] 
     
    652690         
    653691        if url is None: 
    654             url = self.__url 
     692            url = self.__pull_url 
    655693        if not '/' in url: 
    656694            url = '%s/devel/sage-%s'%(SAGE_ROOT, url) 
     
    665703        print "If it says use 'hg merge' above, then you should" 
    666704        print "type hg_%s.merge()."%self.__obj_name 
     705 
     706    def push(self, url=None, options=''): 
     707        """ 
     708        Push all new patches from the repository to the given destination. 
     709 
     710        INPUT: 
     711            url:  default: self.push_url() -- the official repository 
     712                   * http://[user@]host[:port]/[path] 
     713                   * https://[user@]host[:port]/[path] 
     714                   * ssh://[user@]host[:port]/[path] 
     715                   * local directory (starting with a /) 
     716                   * name of a branch (for hg_sage); no /'s 
     717            options: (default: '') 
     718                 -e --ssh        specify ssh command to use 
     719                 -f --force      run even when remote repository is unrelated 
     720                 -r --rev        a specific revision you would like to pull 
     721                 --remotecmd  specify hg command to run on the remote side 
     722 
     723        Some notes about using SSH with Mercurial: 
     724        - SSH requires an accessible shell account on the destination machine 
     725          and a copy of hg in the remote path or specified with as remotecmd. 
     726        - path is relative to the remote user's home directory by default. 
     727          Use an extra slash at the start of a path to specify an absolute path: 
     728            ssh://example.com//tmp/repository 
     729        - Mercurial doesn't use its own compression via SSH; the right thing 
     730          to do is to configure it in your ~/.ssh/ssh_config, e.g.: 
     731            Host *.mylocalnetwork.example.com 
     732              Compression off 
     733            Host * 
     734              Compression on 
     735          Alternatively specify "ssh -C" as your ssh command in your hgrc or 
     736          with the --ssh command line option. 
     737        """ 
     738        ##self._ensure_safe() 
     739         
     740        if url is None: 
     741            url = self.__push_url 
     742        if not '/' in url: 
     743            url = '%s/devel/sage-%s'%(SAGE_ROOT, url) 
     744             
     745        self('push %s %s'%(options, url)) 
     746 
    667747 
    668748    def merge(self, options=''): 
     
    854934        r""" 
    855935        Create an hg changeset bundle with the given filename against the 
    856         repository at the given url (which is by default the 
    857         'official' SAGE repository). 
     936        repository at the given url (which is by default the 'official'  
     937        SAGE repository, unless push_url() is changed in a setup file). 
    858938 
    859939        If you have internet access, it's best to just do 
     
    872952            filename -- output file in which to put bundle 
    873953            options -- pass to hg 
    874             url -- url to bundle against (default: SAGE_SERVER) 
     954            url -- url to bundle against (default: SAGE_SERVER, or push_url()) 
    875955            base -- a base changeset revision number to bundle 
    876956                    against (doesn't require internet access) 
     
    881961             
    882962        if url is None: 
    883             url = self.__url 
     963            url = self.__push_url 
    884964 
    885965        # make sure that we don't accidentally create a file ending in '.hg.hg' 
     
    917997SAGE_ROOT = misc.SAGE_ROOT 
    918998try: 
    919     SAGE_SERVER = os.environ['SAGE_HG_SERVER'].strip('/') + '/hg' 
     999    SAGE_INCOMING_SERVER = os.environ['SAGE_HG_SERVER'].strip('/') + '/hg' 
    9201000except KeyError: 
    9211001    try: 
    922         SAGE_SERVER = os.environ['SAGE_SERVER'].strip('/') + '/hg' 
     1002        SAGE_INCOMING_SERVER = os.environ['SAGE_SERVER'].strip('/') + '/hg' 
    9231003    except KeyError: 
    9241004        print "Falling back to a hard coded sage server in misc/hg.py" 
    925         SAGE_SERVER = "http://sage.math.washington.edu/sage/hg/" 
     1005        SAGE_INCOMING_SERVER = "http://sage.math.washington.edu/sage/hg/" 
     1006 
     1007SAGE_OUTGOING_SERVER = os.getenv("SAGE_OUTGOING_SERVER") 
     1008temp_branch_name = branch_current_hg()      ## Delete this eventually       <<---- TO FIX 
     1009if SAGE_OUTGOING_SERVER == None: 
     1010    SAGE_OUTGOING_SERVER = SAGE_INCOMING_SERVER 
     1011    temp_incoming_branch_name = "main"      ## Force use of the "main" branch (to avoid breaking anything for now).  <<---- TO FIX 
     1012else: 
     1013    print "Non-default server settings detected:" 
     1014    print "    Incoming Server = ", SAGE_INCOMING_SERVER 
     1015    print "    Outgoing Server = ", SAGE_OUTGOING_SERVER 
     1016    print 
    9261017 
    9271018hg_sage    = HG('%s/devel/sage'%SAGE_ROOT, 
    9281019                'SAGE Library Source Code', 
    929                 url='%s/sage-main'%SAGE_SERVER, 
     1020                pull_url='%s/sage-%s'%(SAGE_INCOMING_SERVER, temp_branch_name), 
     1021                push_url='%s/sage-%s'%(SAGE_OUTGOING_SERVER, temp_branch_name), 
     1022 
     1023                ## These are the eventual replacements for the above 2 lines (I hope!)          <<----  TO FIX 
     1024                ##pull_url='%s/sage-%s'%(SAGE_INCOMING_SERVER, branch_current_hg()), 
     1025                ##push_url='%s/sage-%s'%(SAGE_OUTGOING_SERVER, branch_current_hg()), 
     1026 
    9301027                cloneable=True, 
    9311028                obj_name='sage') 
     
    9331030hg_doc     = HG('%s/devel/doc'%SAGE_ROOT, 
    9341031                'SAGE Documentation', 
    935                 url='%s/doc-main'%SAGE_SERVER, 
     1032                pull_url='%s/doc-main'%SAGE_INCOMING_SERVER, 
     1033                push_url='%s/doc-main'%SAGE_OUTGOING_SERVER, 
    9361034                obj_name='doc') 
    9371035 
    9381036hg_scripts = HG('%s/local/bin/'%SAGE_ROOT, 
    9391037                'SAGE Scripts', 
    940                 url='%s/scripts-main'%SAGE_SERVER, 
     1038                pull_url='%s/scripts-main'%SAGE_INCOMING_SERVER, 
     1039                push_url='%s/scripts-main'%SAGE_OUTGOING_SERVER, 
    9411040                obj_name='scripts') 
    9421041 
    9431042hg_extcode = HG('%s/data/extcode'%SAGE_ROOT, 
    9441043                'SAGE External System Code (e.g., PARI, MAGMA, etc.)', 
    945                 url='%s/extcode-main'%SAGE_SERVER, 
     1044                pull_url='%s/extcode-main'%SAGE_INCOMING_SERVER, 
     1045                push_url='%s/extcode-main'%SAGE_OUTGOING_SERVER, 
    9461046                obj_name='extcode') 
    9471047 
Note: See TracChangeset for help on using the changeset viewer.