hgext/convert/git.py
changeset 4760 07efcce17d28
parent 4759 20ec5cc02f18
child 4767 2d0a823cbba5
equal deleted inserted replaced
4759:20ec5cc02f18 4760:07efcce17d28
     3 import os
     3 import os
     4 
     4 
     5 from common import NoRepo, commit, converter_source
     5 from common import NoRepo, commit, converter_source
     6 
     6 
     7 class convert_git(converter_source):
     7 class convert_git(converter_source):
     8     def __init__(self, ui, path):
     8     def __init__(self, ui, path, rev=None):
     9         if os.path.isdir(path + "/.git"):
     9         if os.path.isdir(path + "/.git"):
    10             path += "/.git"
    10             path += "/.git"
    11         if not os.path.exists(path + "/objects"):
    11         if not os.path.exists(path + "/objects"):
    12             raise NoRepo("couldn't open GIT repo %s" % path)
    12             raise NoRepo("couldn't open GIT repo %s" % path)
    13 
    13 
    14         self.path = path
    14         self.path = path
    15         self.ui = ui
    15         self.ui = ui
       
    16         self.rev = rev
    16         self.encoding = 'utf-8'
    17         self.encoding = 'utf-8'
    17 
    18 
    18     def getheads(self):
    19     def getheads(self):
    19         fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path)
    20         rev = self.rev or 'HEAD'
       
    21         fh = os.popen("GIT_DIR=%s git-rev-parse --verify %s" % (self.path, rev))
    20         return [fh.read()[:-1]]
    22         return [fh.read()[:-1]]
    21 
    23 
    22     def catfile(self, rev, type):
    24     def catfile(self, rev, type):
    23         if rev == "0" * 40: raise IOError()
    25         if rev == "0" * 40: raise IOError()
    24         fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null"
    26         fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null"