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
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
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)
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
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
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)
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
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)
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)
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
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
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
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
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
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