Source

guestrepo / guestrepo / __init__.py

The default branch has multiple heads

Full commit
# Guestrepo: A Mercurial Extension for the managing of components
# Copyright (C) 2012   Schweitzer Engineering Laboratories, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Contact information:

# opensource@selinc.com

# Schweitzer Engineering Laboratories, Inc.
# 2350 NE Hopkins Court
# Pullman, WA 99163 - USA


'''handle modules and components

    Commands for managing nested repositories

    Administration
    ==============

    Guest repositories are administered using the two files .hggrmapping and
    .hgguestrepo. These files are in the INI format used by Mercurial.

    Remote Paths
    ------------

    Each guest repository must have a remote path defined in the .hggrmapping
    file to successfully push or pull.
    Remote paths are referenced by assigning a each path a unique name.
    The .hggrmapping file lists remote paths in the following INI format:

       name = remote-path

    If a remote repository is moved, the path referenced by a name can be
    updated to point to the new location.

    Example .hggrmapping file:

      remoteid  = http://host/path/to/repo

      remoteid2 = /path/to/repo2

    The .hggrmapping file used for any operation is the .hggrmapping file at
    the most recently committed head of the current branch.
    Using the most recent revision of the .hggrmapping file keeps the guests of
    previous revisions pointed to the correct location.

    The `--local` flag causes the .hggrmapping file in the working directory
    to be used.

    Guest Repository Listing
    ------------------------

    The .hgguestrepo file defines guests by specifying three things:

    :location:      The location of the guest relative to the root of the parent
                    repository.
    :remote id:     The name of a remote path defined in the .hggrmapping file.
    :changeset id:  A Mercurial identifier e.g., a tag, bookmark, changeset
                    hash, branch, or other future identifier resolvable to a
                    single changeset.

    The .hgguestrepo file lists guest repositories in the following INI format:

      location = remote-id changeset-id

    Example .hgguestrepo file:

      path/to/guest = remoteid csid

      path/to/other/guest = remoteid2 csid

    If the the directory of the guest repository exists, it must contain a
    mercurial repository.
'''

from guestrepo import pull, push, grupdate, freeze, summary, state, grout, grin

import convert
import lockedui


# reused options
# option format: (short option, option name, default value, description)
localopt = [('l', 'local', False,
           "use the .hggrmapping file in the working directory")]

threadopt = [('j', 'threads', 1,
          'number of threads to use. '
          'WARNING: ssh prompts are broken, and username and password prompts '
          'may become unordered '
          'when more than one thread is used', 'THREADS')]

# Command table for the guestrepo extension
# See the readme for a description of each command
# format: {"command-name": (function, options-list, help-string)}
cmdtable = {
   "grpull": (pull,
              localopt + threadopt,
              "hg grpull [REPO [+]] [options]"),
   "grpush": (push,
              localopt + threadopt,
              "hg grpush [REPO [+]] [options]"),
   "grupdate": (grupdate,
              localopt + threadopt,
              "hg grupdate [REPO [+]] [options]"),
   "grfreeze": (freeze,
              [],
              "hg grfreeze"),
   "grsummary": (summary,
              [("i", "id", False,
                "Print the short changeset id")],
              "hg grsummary"),
   "grstate": (state,
              [],
              "hg grstate"),
   "grout" : (grout,
              threadopt,
              "hg grout"),
   "grin" : (grin,
             threadopt,
              "hg grin"),
   "grconvert": (convert.convert,
         [('b', 'branch', False,
           "write the current branch of each subrepo instead of the changeset")
         ],
         "hg grconvert [--branch]")
   }

# hook run at mercurial startup just after ui object is created
def uisetup(ui):
    # from hgext/color.py
    # make ui's class be lockedui a subclass of the current ui class
    # think of it as inserting at the head of a linked list...
    # TODO: do this on dispatch so we can only use it for gr* commands
    if not issubclass(ui.__class__, lockedui.lockedui):
        lockedui.lockedui.__bases__ = (ui.__class__,)
        ui.__class__ = lockedui.lockedui