Esempio n. 1
0
def read_one_line(repo):
    """Reads and processes one command.
    """

    line = sys.stdin.readline()

    cmdline = line

    if not cmdline:
        warn("Unexpected EOF")
        return False

    cmdline = cmdline.strip().split()
    if not cmdline:
        # Blank line means we're about to quit
        return False

    cmd = cmdline.pop(0)
    debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))

    if cmd not in COMMANDS:
        die("Unknown command, %s", cmd)

    func = COMMANDS[cmd]
    func(repo, cmdline)
    sys.stdout.flush()

    return True
Esempio n. 2
0
    def read_one_line(self, repo):
        """Reads and processes one command.
        """

        sleepy = os.environ.get("GIT_REMOTE_TESTGIT_SLEEPY")
        if sleepy:
            debug("Sleeping %d sec before readline" % int(sleepy))
            time.sleep(int(sleepy))

        line = sys.stdin.readline()

        cmdline = line

        if not cmdline:
            warn("Unexpected EOF")
            return False

        cmdline = cmdline.strip().split()
        if not cmdline:
            # Blank line means we're about to quit
            return False

        cmd = cmdline.pop(0)
        debug("Got command '%s' with args '%s'", cmd, " ".join(cmdline))

        if cmd not in self.commands:
            die("Unknown command, %s", cmd)

        func = self.commands[cmd]
        func(repo, cmdline)
        sys.stdout.flush()

        return True
Esempio n. 3
0
def main(args):
    """Starts a new remote helper for the specified repository.
    """

    if len(args) != 3:
        die("Expecting exactly three arguments.")
        sys.exit(1)

    if os.getenv("GIT_DEBUG_TESTGIT"):
        import git_remote_helpers.util
        git_remote_helpers.util.DEBUG = True

    alias = sanitize(args[1])
    url = sanitize(args[2])

    if not alias.isalnum():
        warn("non-alnum alias '%s'", alias)
        alias = "tmp"

    args[1] = alias
    args[2] = url

    repo = get_repo(alias, url)

    debug("Got arguments %s", args[1:])

    more = True

    while (more):
        more = read_one_line(repo)
Esempio n. 4
0
def read_one_line(repo):
    """Reads and processes one command.
    """

    sleepy = os.environ.get("GIT_REMOTE_TESTGIT_SLEEPY")
    if sleepy:
        debug("Sleeping %d sec before readline" % int(sleepy))
        time.sleep(int(sleepy))

    line = sys.stdin.readline()

    cmdline = line

    if not cmdline:
        warn("Unexpected EOF")
        return False

    cmdline = cmdline.strip().split()
    if not cmdline:
        # Blank line means we're about to quit
        return False

    cmd = cmdline.pop(0)
    debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))

    if cmd not in COMMANDS:
        die("Unknown command, %s", cmd)

    func = COMMANDS[cmd]
    func(repo, cmdline)
    sys.stdout.flush()

    return True
Esempio n. 5
0
def get_repo(alias, url):
    """Returns a git repository object initialized for usage.
    """

    repo = GitRepo(url)
    repo.get_revs()
    repo.get_head()

    hasher = _digest()
    hasher.update(repo.path)
    repo.hash = hasher.hexdigest()

    repo.get_base_path = lambda base: os.path.join(
        base, 'info', 'fast-import', repo.hash)

    prefix = 'refs/testgit/%s/' % alias
    debug("prefix: '%s'", prefix)

    repo.gitdir = ""
    repo.alias = alias
    repo.prefix = prefix

    repo.exporter = GitExporter(repo)
    repo.importer = GitImporter(repo)
    repo.non_local = NonLocalGit(repo)

    return repo
Esempio n. 6
0
def main(args):
    """Starts a new remote helper for the specified repository.
    """

    if len(args) != 3:
        die("Expecting exactly three arguments.")
        sys.exit(1)

    if os.getenv("GIT_DEBUG_TESTGIT"):
        import git_remote_helpers.util
        git_remote_helpers.util.DEBUG = True

    alias = sanitize(args[1])
    url = sanitize(args[2])

    if not alias.isalnum():
        warn("non-alnum alias '%s'", alias)
        alias = "tmp"

    args[1] = alias
    args[2] = url

    repo = get_repo(alias, url)

    debug("Got arguments %s", args[1:])

    more = True

    while (more):
        more = read_one_line(repo)
Esempio n. 7
0
    def main(self, args):
        """Starts a new remote helper for the specified repository.
        """

        if len(args) != 3:
            die("Expecting exactly three arguments.")
            sys.exit(1)

        if os.getenv("GIT_REMOTE_HELPER_DEBUG"):
            import git_remote_helpers.util

            git_remote_helpers.util.DEBUG = True

        alias = self.sanitize(args[1])
        url = self.sanitize(args[2])

        if not alias.isalnum():
            warn("non-alnum alias '%s'", alias)
            alias = "tmp"

        args[1] = alias
        args[2] = url

        repo = self.get_repo(alias, url)

        debug("Got arguments %s", args[1:])

        more = True

        sys.stdin = os.fdopen(sys.stdin.fileno(), "r", 0)
        while more:
            more = self.read_one_line(repo)
Esempio n. 8
0
def read_one_line(repo):
    """Reads and processes one command.
    """

    line = sys.stdin.readline()

    cmdline = line

    if not cmdline:
        warn("Unexpected EOF")
        return False

    cmdline = cmdline.strip().split()
    if not cmdline:
        # Blank line means we're about to quit
        return False

    cmd = cmdline.pop(0)
    debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))

    if cmd not in COMMANDS:
        die("Unknown command, %s", cmd)

    func = COMMANDS[cmd]
    func(repo, cmdline)
    sys.stdout.flush()

    return True
Esempio n. 9
0
def get_repo(alias, url):
    """Returns a git repository object initialized for usage.
    """

    repo = GitRepo(url)
    repo.get_revs()
    repo.get_head()

    hasher = _digest()
    hasher.update(repo.path)
    repo.hash = hasher.hexdigest()

    repo.get_base_path = lambda base: os.path.join(base, 'info', 'fast-import',
                                                   repo.hash)

    prefix = 'refs/testgit/%s/' % alias
    debug("prefix: '%s'", prefix)

    repo.gitdir = ""
    repo.alias = alias
    repo.prefix = prefix

    repo.exporter = GitExporter(repo)
    repo.importer = GitImporter(repo)
    repo.non_local = NonLocalGit(repo)

    return repo
Esempio n. 10
0
def get_repo(alias, url):
    """Returns a hg.repository object initialized for usage.
    """

    try:
        from mercurial import hg, ui
    except ImportError:
        die("Mercurial python libraries not installed")

    ui = ui.ui()
    source, revs = hg.parseurl(ui.expandpath(url), ['tip'])
    repo = hg.repository(ui, source)

    prefix = 'refs/hg/%s/' % alias
    debug("prefix: '%s'", prefix)

    repo.hg = hg
    repo.gitdir = ""
    repo.alias = alias
    repo.prefix = prefix
    repo.revs = revs

    repo.git_hg = GitHg(warn)
    exporter = GitExporter(repo.git_hg, repo, 'hg.marks', 'git.marks', prefix)
    non_local = NonLocalHg(repo, alias)

    repo.exporter = exporter
    repo.non_local = non_local

    return repo
def main(args):
    """Starts a new remote helper for the specified repository.
    """

    if len(args) != 3:
        die("Expecting exactly three arguments.")
        sys.exit(1)

    if os.getenv("GIT_DEBUG_TESTGIT"):
        import git_remote_helpers.util
        git_remote_helpers.util.DEBUG = True

    alias = sanitize(args[1])
    url = sanitize(args[2])

    if not alias.isalnum():
        warn("non-alnum alias '%s'", alias)
        alias = "tmp"

    args[1] = alias
    args[2] = url

    repo = get_repo(alias, url)

    debug("Got arguments %s", args[1:])

    more = True

    # Use binary mode since Python 3 does not permit unbuffered I/O in text
    # mode.  Unbuffered I/O is required to avoid data that should be going
    # to git-fast-import after an "export" command getting caught in our
    # stdin buffer instead.
    sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
    while (more):
        more = read_one_line(repo)
Esempio n. 12
0
    def main(self, args):
        """Starts a new remote helper for the specified repository.
        """

        if len(args) != 3:
            die("Expecting exactly three arguments.")
            sys.exit(1)

        if os.getenv("GIT_REMOTE_HELPER_DEBUG"):
            import git_remote_helpers.util
            git_remote_helpers.util.DEBUG = True

        alias = self.sanitize(args[1])
        url = self.sanitize(args[2])

        if not alias.isalnum():
            warn("non-alnum alias '%s'", alias)
            alias = "tmp"

        args[1] = alias
        args[2] = url

        repo = self.get_repo(alias, url)

        debug("Got arguments %s", args[1:])

        more = True

        sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
        while (more):
            more = self.read_one_line(repo)
Esempio n. 13
0
def do_list(repo, args):
    """Lists all known references.
    """

    for ref in repo.revs:
        debug("? refs/heads/%s", ref)
        print "? refs/heads/%s" % ref

    debug("@refs/heads/tip HEAD")
    print "@refs/heads/tip HEAD"

    print # end list
Esempio n. 14
0
    def do_list(self, repo, args):
        """Lists all known references.
        """

        for ref in repo.revs_:
            debug("? refs/heads/%s", ref)
            print "? refs/heads/%s" % ref

        debug("@refs/heads/default HEAD")
        print "@refs/heads/default HEAD"

        print  # end list
Esempio n. 15
0
def read_one_line(repo):
    line = sys.stdin.readline()

    cmdline = line.strip().split()

    if not cmdline:
        return False # Blank line means we're about to quit

    cmd = cmdline.pop(0)
    debug("Got command '%s' with args '%s'", cmd, ' '.join(cmdline))

    if cmd not in COMMANDS:
        die("Unknown command, %s", cmd)

    func = COMMANDS[cmd]
    func(repo, cmdline)
    sys.stdout.flush()

    return True
Esempio n. 16
0
    def get_repo(self, alias, url):
        """Returns a git repository object initialized for usage.
        """

        repo = GitRepo(url)
        repo.get_revs()
        repo.get_head()

        prefix = 'refs/testgit/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'testgit.marks'
        repo.prefix = prefix

        self.setup_repo(repo, alias)

        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalGit(repo)

        return repo
Esempio n. 17
0
    def get_repo(self, alias, url):
        """Returns a git repository object initialized for usage.
        """

        repo = GitRepo(url)
        repo.get_revs()
        repo.get_head()

        prefix = 'refs/testgit/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'testgit.marks'
        repo.prefix = prefix

        self.setup_repo(repo, alias)

        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalGit(repo)

        return repo
Esempio n. 18
0
    def get_repo(self, alias, url):
        """Returns a hg.repository object initialized for usage.
        """

        try:
            from mercurial import hg, ui
        except ImportError:
            die("Mercurial python libraries not installed")

        remote = False

        if url.startswith("remote://"):
            remote = True
            url = "file://%s" % url[9:]

        ui = ui.ui()
        source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
        repo = hg.repository(ui, source)
        if repo.capable('branchmap'):
            revs += repo.branchmap().keys()
            revs = set(revs)

        prefix = 'refs/hg/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'git.marks'
        repo.hg = hg
        repo.prefix = prefix
        repo.revs_ = revs # must not override repo.revs()

        self.setup_repo(repo, alias)

        repo.git_hg = GitHg(warn)
        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalHg(repo)

        repo.is_local = not remote and repo.local()

        return repo
Esempio n. 19
0
    def get_repo(self, alias, url):
        """Returns a hg.repository object initialized for usage.
        """

        try:
            from mercurial import hg, ui
        except ImportError:
            die("Mercurial python libraries not installed")

        remote = False

        if url.startswith("remote://"):
            remote = True
            url = "file://%s" % url[9:]

        ui = ui.ui()
        source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
        repo = hg.repository(ui, source)
        if repo.capable('branchmap'):
            revs += repo.branchmap().keys()
            revs = set(revs)

        prefix = 'refs/hg/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'git.marks'
        repo.hg = hg
        repo.prefix = prefix
        repo.revs_ = revs  # must not override repo.revs()

        self.setup_repo(repo, alias)

        repo.git_hg = GitHg(warn)
        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalHg(repo)

        repo.is_local = not remote and repo.local()

        return repo
Esempio n. 20
0
def do_list(repo, args):
    """Lists all known references.

    Bug: This will always set the remote head to master for non-local
    repositories, since we have no way of determining what the remote
    head is at clone time.
    """

    for ref in repo.revs:
        debug("? refs/heads/%s", ref)
        print "? refs/heads/%s" % ref

    if repo.head:
        debug("@refs/heads/%s HEAD" % repo.head)
        print "@refs/heads/%s HEAD" % repo.head
    else:
        debug("@refs/heads/master HEAD")
        print "@refs/heads/master HEAD"

    print  # end list
Esempio n. 21
0
def do_list(repo, args):
    """Lists all known references.

    Bug: This will always set the remote head to master for non-local
    repositories, since we have no way of determining what the remote
    head is at clone time.
    """

    for ref in repo.revs:
        debug("? refs/heads/%s", ref)
        print "? refs/heads/%s" % ref

    if repo.head:
        debug("@refs/heads/%s HEAD" % repo.head)
        print "@refs/heads/%s HEAD" % repo.head
    else:
        debug("@refs/heads/master HEAD")
        print "@refs/heads/master HEAD"

    print # end list