Exemplo n.º 1
0
def hg_readactive(repo):
    if hg_version() >= '3.7': 
        return _readactive(repo,repo._bookmarks) 
    elif hg_version() >= '3.5' and hg_version() < '3.7': 
        return readactive(repo) 
    else: 
        return readcurrent(repo) 
Exemplo n.º 2
0
    def __init__(self, alias, url):
        if hg.islocal(url.encode("utf-8")):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            remote_name = os.path.basename(sys.argv[0]).replace("git-remote-", "")
            cmd = ["git", "config", "remote.%s.url" % alias, "%s::%s" % (remote_name, url)]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        if hg_version() >= "4.0.1":
            d = digester(["md5", "sha1"])
            d.update(url.encode("utf-8"))
            self.uuid = d["sha1"]
        else:
            self.uuid = sha1(url.encode("utf-8")).hexdigest()

        gitdir = p(os.environ["GIT_DIR"].decode("utf-8"))
        self.remotedir = gitdir.joinpath("hg", self.uuid)
        self.marks_git_path = self.remotedir.joinpath("marks-git")
        self.marks_hg_path = self.remotedir.joinpath("marks-hg")
        self.marks = HGMarks(self.marks_hg_path)
        self.git_marks = GitMarks(self.marks_git_path)
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = "refs/hg/%s" % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
Exemplo n.º 3
0
def hg_sha1(url):
    encoded = url.encode('utf-8')

    if hg_version() >= '3.2':
        d = digester(['md5', 'sha1'])
        d.update(encoded)
        return d['sha1']
    else:
        return sha1(encoded).hexdigest()
Exemplo n.º 4
0
def hg_strip(repo, processed_nodes):
    class dummyui(object):
        def debug(self, msg):
            pass

    if StrictVersion(hg_version()) >= StrictVersion('2.8'):
        stripext = extensions.load(dummyui(), 'strip', '')
        return stripext.strip(dummyui(), repo, processed_nodes)
    else:
        return repo.mq.strip(repo, processed_nodes)
Exemplo n.º 5
0
def handle_deleted_file():
    if hg_version() >= '3.2':
        return
    else:
        raise IOError
Exemplo n.º 6
0
def hg_memfilectx(repo, path, data, is_link=False, is_exec=False, copied=None):
    if hg_version() >= '3.1':
        return memfilectx(repo, path, data, is_link, is_exec, copied)
    else:
        return memfilectx(path, data, is_link, is_exec, copied)
Exemplo n.º 7
0
from mercurial.context import memctx, memfilectx
from mercurial.util import version as hg_version
from distutils.version import StrictVersion
from mercurial import extensions

# Conditional imports depending on Mercurial version
if hg_version() >= '3.7': 
    from mercurial.bookmarks import _readactive 
elif hg_version() >= '3.5' and hg_version() < '3.7': 
    from mercurial.bookmarks import readactive
else:
    from mercurial.bookmarks import readcurrent

if hg_version() >= '3.2':
    from mercurial.util import digester 
else:
    from mercurial.util import sha1

if hg_version() >= '3.0':
    from mercurial import exchange
else:
    from mercurial.localrepo import localrepository as exchange
 
# Functions wrapping the Mercurial API. They follow the naming convention of
# hg_[function name]

def hg_pull(repo, peer, heads=None, force=False):
    return exchange.pull(repo, peer, heads=heads, force=force)

def hg_push(repo, peer, force=False, newbranch=None):
    return exchange.push(repo, peer, force=force, newbranch=newbranch)
Exemplo n.º 8
0
from mercurial.node import hex as hghex  # What idiot overroad a builtin?
from mercurial.node import short as hgshort
from mercurial.bookmarks import pushbookmark
from mercurial.scmutil import revsingle
from mercurial.util import version as hg_version

from distutils.version import StrictVersion

from .util import (die, output, git_to_hg_spaces, hgmode, branch_tip,
    ref_to_name_reftype, BRANCH, BOOKMARK, TAG, user_config)

class dummyui(object):
    def debug(self, msg):
        pass

if StrictVersion(hg_version()) >= StrictVersion('2.8'):
    stripext = extensions.load(dummyui(), 'strip', '')
    def strip_revs(repo, processed_nodes):
        stripext.strip(dummyui(), repo, processed_nodes)
else:
    def strip_revs(repo, processed_nodes):
        repo.mq.strip(repo, processed_nodes)

class GitExporter(object):

    '''A processor when the remote receives a git-remote `export` command.
    Provides export information to push commits from git to the mercurial
    repository.'''

    NULL_PARENT = '\0' * 20
Exemplo n.º 9
0
def log_versions(level="DEBUG"):
    log("gitifyhg version %s" % version(), level=level)
    log("Mercurial version %s" % hg_version(), level=level)
    log("Python version %s" % (sys.version.replace("\n", "")), level=level)
Exemplo n.º 10
0
    def do_list(self, parser):
        """List all references in the mercurial repository. This includes
        the current head, all branches, tags, and bookmarks."""

        current_branch = self.repo.dirstate.branch()

        # Update the head reference
        if hg_version() >= "4.0.1":
            head = _readactive(self.repo, self.repo._bookmarks)
        else:
            head = readcurrent(self.repo)

        if head:
            node = self.repo[head]
        else:
            # If there is no bookmark for head, mock one
            head = current_branch
            node = self.repo["."]
            # I think this means an initial clone occured and we haven't
            # hg updated yet in the local clone
            if not node:
                if "default" in self.repo:
                    node = self.repo["default"]
                else:  # empty repository or head is at 0 commit
                    output()
                    return
            head = head if head != "default" else "master"
            # self.bookmarks[head] = node

        self.headnode = (head, node)

        # Update the bookmark references
        for bookmark, node in listbookmarks(self.repo).iteritems():
            self.bookmarks[bookmark] = self.repo[node]

        # update the named branch references
        for branch in self.repo.branchmap():
            # FIXME: Probably a git config instead of an env var would make
            # people happier here.
            clone_closed = os.environ.get("GITIFYHG_ALLOW_CLOSED_BRANCHES") != None
            heads = self.repo.branchheads(branch, closed=clone_closed)
            if heads:
                self.branches[branch] = heads

        # list the head reference
        output("@refs/heads/%s HEAD" % self.headnode[0])

        # list the named branch references
        for branch in self.branches:
            output(
                "%s %s"
                % (self._change_hash(branch_head(self, branch)), name_reftype_to_ref(hg_to_git_spaces(branch), BRANCH))
            )

        # list the bookmark references
        for bookmark, changectx in self.bookmarks.items():
            if bookmark != "master":
                output(
                    "%s %s" % (self._change_hash(changectx), name_reftype_to_ref(hg_to_git_spaces(bookmark), BOOKMARK))
                )

        # list the tags
        for tag, node in self.repo.tagslist():
            if tag != "tip":
                output("%s %s" % (self._change_hash(self.repo[node]), name_reftype_to_ref(hg_to_git_spaces(tag), TAG)))

        output()
Exemplo n.º 11
0
import sys
import os
import re
import optparse
import subprocess
from path import path as p

# Enable "plain" mode to make us resilient against changes to the locale, as we
# rely on parsing certain messages produced by Mercurial. See issue #26.
os.environ["HGPLAIN"] = "1"
# Disable loading of the user's $HOME/.hgrc as extensions can cause weird
# interactions and it's better to run in a known state.
os.environ["HGRCPATH"] = ""

# Version specific libraries from the Mercurial API
if hg_version() >= "4.0.1":
    from mercurial.util import digester
    from mercurial.bookmarks import _readactive
else:
    from mercurial.util import sha1
    from mercurial.bookmarks import readcurrent

from mercurial import hg
from mercurial.bookmarks import listbookmarks
from mercurial.ui import ui
from mercurial.error import Abort, RepoError
from mercurial.util import version as hg_version

from .util import (
    log,
    die,
Exemplo n.º 12
0
def log_versions(level="DEBUG"):
    log("gitifyhg version %s" % version(), level=level)
    log("Mercurial version %s" % hg_version(), level=level)
    log("Python version %s" % (sys.version.replace("\n", "")), level=level)