comparison hggit/git_handler.py @ 260:6977263c4d80

Merge with abderrahim.
author Augie Fackler <durin42@gmail.com>
date Sun, 25 Oct 2009 10:55:12 -0500
parents git_handler.py@1590c97d7af0 git_handler.py@505d7cdca198
children 29e5072ddaab
comparison
equal deleted inserted replaced
259:8b9fc1b1cc40 260:6977263c4d80
31 else: 31 else:
32 self.gitdir = self.repo.join('git') 32 self.gitdir = self.repo.join('git')
33 33
34 self.paths = ui.configitems('paths') 34 self.paths = ui.configitems('paths')
35 35
36 self.init_if_missing()
37 self.load_git()
38 self.load_map() 36 self.load_map()
39 self.load_tags() 37 self.load_tags()
40 38
41 # make the git data directory 39 # make the git data directory
42 def init_if_missing(self): 40 def init_if_missing(self):
43 if not os.path.exists(self.gitdir): 41 if os.path.exists(self.gitdir):
42 self.git = Repo(self.gitdir)
43 else:
44 os.mkdir(self.gitdir) 44 os.mkdir(self.gitdir)
45 Repo.init_bare(self.gitdir) 45 self.git = Repo.init_bare(self.gitdir)
46
47 def load_git(self):
48 self.git = Repo(self.gitdir)
49 46
50 ## FILE LOAD AND SAVE METHODS 47 ## FILE LOAD AND SAVE METHODS
51 48
52 def map_set(self, gitsha, hgsha): 49 def map_set(self, gitsha, hgsha):
53 self._map_git[gitsha] = hgsha 50 self._map_git[gitsha] = hgsha
174 171
175 ## CHANGESET CONVERSION METHODS 172 ## CHANGESET CONVERSION METHODS
176 173
177 def export_git_objects(self): 174 def export_git_objects(self):
178 self.ui.status(_("importing Hg objects into Git\n")) 175 self.ui.status(_("importing Hg objects into Git\n"))
176 self.init_if_missing()
177
179 nodes = [self.repo.lookup(n) for n in self.repo] 178 nodes = [self.repo.lookup(n) for n in self.repo]
180 export = [node for node in nodes if not hex(node) in self._map_hg] 179 export = [node for node in nodes if not hex(node) in self._map_hg]
181 total = len(export) 180 total = len(export)
182 if total: 181 if total:
183 magnitude = int(math.log(total, 10)) + 1 182 magnitude = int(math.log(total, 10)) + 1
350 349
351 yield f, blobid, mode 350 yield f, blobid, mode
352 351
353 def import_git_objects(self, remote_name=None, refs=None): 352 def import_git_objects(self, remote_name=None, refs=None):
354 self.ui.status(_("importing Git objects into Hg\n")) 353 self.ui.status(_("importing Git objects into Hg\n"))
354 self.init_if_missing()
355
355 # import heads and fetched tags as remote references 356 # import heads and fetched tags as remote references
356 todo = [] 357 todo = []
357 done = set() 358 done = set()
358 convert_list = {} 359 convert_list = {}
359 360