git_remote_helpers / git / exporter.pyon commit gitweb: Handle invalid regexp in regexp search (36612e4)
   1import os
   2import subprocess
   3import sys
   4
   5
   6class GitExporter(object):
   7    """An exporter for testgit repositories.
   8
   9    The exporter simply delegates to git fast-export.
  10    """
  11
  12    def __init__(self, repo):
  13        """Creates a new exporter for the specified repo.
  14        """
  15
  16        self.repo = repo
  17
  18    def export_repo(self, base):
  19        """Exports a fast-export stream for the given directory.
  20
  21        Simply delegates to git fast-epxort and pipes it through sed
  22        to make the refs show up under the prefix rather than the
  23        default refs/heads. This is to demonstrate how the export
  24        data can be stored under it's own ref (using the refspec
  25        capability).
  26        """
  27
  28        dirname = self.repo.get_base_path(base)
  29        path = os.path.abspath(os.path.join(dirname, 'testgit.marks'))
  30
  31        if not os.path.exists(dirname):
  32            os.makedirs(dirname)
  33
  34        print "feature relative-marks"
  35        if os.path.exists(os.path.join(dirname, 'git.marks')):
  36            print "feature import-marks=%s/git.marks" % self.repo.hash
  37        print "feature export-marks=%s/git.marks" % self.repo.hash
  38        sys.stdout.flush()
  39
  40        args = ["git", "--git-dir=" + self.repo.gitpath, "fast-export", "--export-marks=" + path]
  41
  42        if os.path.exists(path):
  43            args.append("--import-marks=" + path)
  44
  45        args.append("HEAD")
  46
  47        p1 = subprocess.Popen(args, stdout=subprocess.PIPE)
  48
  49        args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
  50
  51        child = subprocess.Popen(args, stdin=p1.stdout)
  52        if child.wait() != 0:
  53            raise CalledProcessError