Code

Merge branch 'jn/maint-fast-import-empty-ls' into maint
[git.git] / git_remote_helpers / git / exporter.py
1 import os
2 import subprocess
3 import sys
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.
12     """
14     def __init__(self, repo):
15         """Creates a new exporter for the specified repo.
16         """
18         self.repo = 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
27         capability).
29         If None, refs defaults to ["HEAD"].
30         """
32         if not refs:
33             refs = ["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):
39             os.makedirs(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
45         sys.stdout.flush()
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)
52         args.extend(refs)
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)