4 from git_remote_helpers
.util
import check_call
, check_output
7 class GitImporter(object):
8 """An importer for testgit repositories.
10 This importer simply delegates to git fast-import.
13 def __init__(self
, repo
):
14 """Creates a new importer for the specified repo.
19 def get_refs(self
, gitdir
):
20 """Returns a dictionary with refs.
22 Note that the keys in the returned dictionary are byte strings as
25 args
= ["git", "--git-dir=" + gitdir
, "for-each-ref", "refs/heads"]
26 lines
= check_output(args
).strip().split('\n'.encode('ascii'))
29 value
, name
= line
.split(' '.encode('ascii'))
30 name
= name
.strip('commit\t'.encode('ascii'))
34 def do_import(self
, base
):
35 """Imports a fast-import stream to the given directory.
37 Simply delegates to git fast-import.
40 dirname
= self
.repo
.get_base_path(base
)
42 gitdir
= self
.repo
.gitpath
44 gitdir
= os
.path
.abspath(os
.path
.join(dirname
, '.git'))
45 path
= os
.path
.abspath(os
.path
.join(dirname
, 'testgit.marks'))
47 if not os
.path
.exists(dirname
):
50 refs_before
= self
.get_refs(gitdir
)
52 args
= ["git", "--git-dir=" + gitdir
, "fast-import", "--quiet", "--export-marks=" + path
]
54 if os
.path
.exists(path
):
55 args
.append("--import-marks=" + path
)
59 refs_after
= self
.get_refs(gitdir
)
63 for name
, value
in refs_after
.iteritems():
64 if refs_before
.get(name
) == value
: