X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-remote-testgit.py;h=3dc4851cfc70a2804b23a8eca4dac7702ae93c87;hb=f99f4b3667a83f870565bb140711f0e585999108;hp=92539222c57d1966f847a641c976754f1941dc2b;hpb=c7f874e405a52f93d486094034d886fc140961c9;p=git.git diff --git a/git-remote-testgit.py b/git-remote-testgit.py index 92539222c..3dc4851cf 100644 --- a/git-remote-testgit.py +++ b/git-remote-testgit.py @@ -1,6 +1,25 @@ #!/usr/bin/env python -import hashlib +# 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 + _digest = hashlib.sha1 +except ImportError: + import sha + _digest = sha.new import sys import os sys.path.insert(0, os.getenv("GITPYTHONLIB",".")) @@ -19,7 +38,7 @@ def get_repo(alias, url): repo.get_revs() repo.get_head() - hasher = hashlib.sha1() + hasher = _digest() hasher.update(repo.path) repo.hash = hasher.hexdigest() @@ -29,7 +48,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 @@ -64,9 +83,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 @@ -115,8 +144,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): @@ -126,29 +171,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 - print path if os.path.exists(path) else "" - sys.stdout.flush() - update_local_repo(repo) - repo.importer.do_import(repo.gitdir) - repo.non_local.push(repo.gitdir) - - -def do_gitdir(repo, args): - """Stores the location of the gitdir. - """ + changed = repo.importer.do_import(repo.gitdir) - if not args: - die("gitdir needs an argument") + if not repo.local: + repo.non_local.push(repo.gitdir) - repo.gitdir = ' '.join(args) + for ref in changed: + print "ok %s" % ref + print COMMANDS = { @@ -156,7 +187,6 @@ COMMANDS = { 'list': do_list, 'import': do_import, 'export': do_export, - 'gitdir': do_gitdir, }