diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-08-01 15:00:14 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-01 15:00:14 -0700 |
commit | 59d9ba869e900bf4da9822f417e4d40a710d8063 (patch) | |
tree | 07f1a07ddcff4c61e52cb959e6e7c0eec7abeb53 /git_remote_helpers/git/importer.py | |
parent | Merge branch 'jc/maint-reset-unmerged-path' (diff) | |
parent | transport-helper: die early on encountering deleted refs (diff) | |
download | tgif-59d9ba869e900bf4da9822f417e4d40a710d8063.tar.xz |
Merge branch 'sr/transport-helper-fix'
* sr/transport-helper-fix: (21 commits)
transport-helper: die early on encountering deleted refs
transport-helper: implement marks location as capability
transport-helper: Use capname for refspec capability too
transport-helper: change import semantics
transport-helper: update ref status after push with export
transport-helper: use the new done feature where possible
transport-helper: check status code of finish_command
transport-helper: factor out push_update_refs_status
fast-export: support done feature
fast-import: introduce 'done' command
git-remote-testgit: fix error handling
git-remote-testgit: only push for non-local repositories
remote-curl: accept empty line as terminator
remote-helpers: export GIT_DIR variable to helpers
git_remote_helpers: push all refs during a non-local export
transport-helper: don't feed bogus refs to export push
git-remote-testgit: import non-HEAD refs
t5800: document some non-functional parts of remote helpers
t5800: use skip_all instead of prereq
t5800: factor out some ref tests
...
Diffstat (limited to 'git_remote_helpers/git/importer.py')
-rw-r--r-- | git_remote_helpers/git/importer.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/git_remote_helpers/git/importer.py b/git_remote_helpers/git/importer.py index 70a712729b..5c6b595e16 100644 --- a/git_remote_helpers/git/importer.py +++ b/git_remote_helpers/git/importer.py @@ -1,6 +1,8 @@ import os import subprocess +from git_remote_helpers.util import check_call, check_output + class GitImporter(object): """An importer for testgit repositories. @@ -14,6 +16,18 @@ class GitImporter(object): self.repo = repo + def get_refs(self, gitdir): + """Returns a dictionary with refs. + """ + args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"] + lines = check_output(args).strip().split('\n') + refs = {} + for line in lines: + value, name = line.split(' ') + name = name.strip('commit\t') + refs[name] = value + return refs + def do_import(self, base): """Imports a fast-import stream to the given directory. @@ -30,11 +44,23 @@ class GitImporter(object): if not os.path.exists(dirname): os.makedirs(dirname) + refs_before = self.get_refs(gitdir) + args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path] if os.path.exists(path): args.append("--import-marks=" + path) - child = subprocess.Popen(args) - if child.wait() != 0: - raise CalledProcessError + check_call(args) + + refs_after = self.get_refs(gitdir) + + changed = {} + + for name, value in refs_after.iteritems(): + if refs_before.get(name) == value: + continue + + changed[name] = value + + return changed |