diff options
Diffstat (limited to 'git-remote-testgit.py')
-rw-r--r-- | git-remote-testgit.py | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/git-remote-testgit.py b/git-remote-testgit.py index df9d512f1a..5f3ebd244d 100644 --- a/git-remote-testgit.py +++ b/git-remote-testgit.py @@ -1,5 +1,18 @@ #!/usr/bin/env python +# This command is a simple remote-helper, that is used both as a +# testcase for the remote-helper functionality, and as an example to +# show remote-helper authors one possible implementation. +# +# This is a Git <-> Git importer/exporter, that simply uses git +# fast-import and git fast-export to consume and produce fast-import +# streams. +# +# To understand better the way things work, one can activate debug +# traces by setting (to any value) the environment variables +# GIT_TRANSPORT_HELPER_DEBUG and GIT_DEBUG_TESTGIT, to see messages +# from the transport-helper side, or from this example remote-helper. + # hashlib is only available in python >= 2.5 try: import hashlib @@ -9,6 +22,7 @@ except ImportError: _digest = sha.new import sys import os +import time sys.path.insert(0, os.getenv("GITPYTHONLIB",".")) from git_remote_helpers.util import die, debug, warn @@ -35,7 +49,7 @@ def get_repo(alias, url): prefix = 'refs/testgit/%s/' % alias debug("prefix: '%s'", prefix) - repo.gitdir = "" + repo.gitdir = os.environ["GIT_DIR"] repo.alias = alias repo.prefix = prefix @@ -70,9 +84,19 @@ def do_capabilities(repo, args): print "import" print "export" - print "gitdir" print "refspec refs/heads/*:%s*" % repo.prefix + dirname = repo.get_base_path(repo.gitdir) + + if not os.path.exists(dirname): + os.makedirs(dirname) + + path = os.path.join(dirname, 'testgit.marks') + + print "*export-marks %s" % path + if os.path.exists(path): + print "*import-marks %s" % path + print # end capabilities @@ -121,8 +145,24 @@ def do_import(repo, args): if not repo.gitdir: die("Need gitdir to import") + ref = args[0] + refs = [ref] + + while True: + line = sys.stdin.readline() + if line == '\n': + break + if not line.startswith('import '): + die("Expected import line.") + + # strip of leading 'import ' + ref = line[7:].strip() + refs.append(ref) + repo = update_local_repo(repo) - repo.exporter.export_repo(repo.gitdir) + repo.exporter.export_repo(repo.gitdir, refs) + + print "done" def do_export(repo, args): @@ -132,32 +172,15 @@ def do_export(repo, args): if not repo.gitdir: die("Need gitdir to export") - dirname = repo.get_base_path(repo.gitdir) - - if not os.path.exists(dirname): - os.makedirs(dirname) - - path = os.path.join(dirname, 'testgit.marks') - print path - if os.path.exists(path): - print path - else: - print "" - sys.stdout.flush() - update_local_repo(repo) - repo.importer.do_import(repo.gitdir) - repo.non_local.push(repo.gitdir) + changed = repo.importer.do_import(repo.gitdir) + if not repo.local: + repo.non_local.push(repo.gitdir) -def do_gitdir(repo, args): - """Stores the location of the gitdir. - """ - - if not args: - die("gitdir needs an argument") - - repo.gitdir = ' '.join(args) + for ref in changed: + print "ok %s" % ref + print COMMANDS = { @@ -165,7 +188,6 @@ COMMANDS = { 'list': do_list, 'import': do_import, 'export': do_export, - 'gitdir': do_gitdir, } @@ -183,6 +205,11 @@ 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 @@ -237,6 +264,7 @@ def main(args): more = True + sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0) while (more): more = read_one_line(repo) |