5 from git_remote_helpers
.util
import check_call
8 class GitExporter(object):
9 """An exporter for testgit repositories.
11 The exporter simply delegates to git fast-export.
14 def __init__(self
, repo
):
15 """Creates a new exporter for the specified repo.
20 def export_repo(self
, base
, refs
=None):
21 """Exports a fast-export stream for the given directory.
23 Simply delegates to git fast-epxort and pipes it through sed
24 to make the refs show up under the prefix rather than the
25 default refs/heads. This is to demonstrate how the export
26 data can be stored under it's own ref (using the refspec
29 If None, refs defaults to ["HEAD"].
35 dirname
= self
.repo
.get_base_path(base
)
36 path
= os
.path
.abspath(os
.path
.join(dirname
, 'testgit.marks'))
38 if not os
.path
.exists(dirname
):
41 print "feature relative-marks"
42 if os
.path
.exists(os
.path
.join(dirname
, 'git.marks')):
43 print "feature import-marks=%s/git.marks" % self
.repo
.hash
44 print "feature export-marks=%s/git.marks" % self
.repo
.hash
47 args
= ["git", "--git-dir=" + self
.repo
.gitpath
, "fast-export", "--export-marks=" + path
]
49 if os
.path
.exists(path
):
50 args
.append("--import-marks=" + path
)
54 p1
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
)
56 args
= ["sed", "s_refs/heads/_" + self
.repo
.prefix
+ "_g"]
58 check_call(args
, stdin
=p1
.stdout
)