comparison hgfastimport/hgimport.py @ 55:a88f0dd05e92

Adapt to Mercurial 1.6 API change. Convertor source method getmode() has been merged into getfile().
author Greg Ward <greg-hg@gerg.ca>
date Wed, 10 Nov 2010 21:31:23 -0500
parents 38fe4f98a3ff
children e827bffa5fc5 76bd0ea8add3
comparison
equal deleted inserted replaced
54:9608f415ebe8 55:a88f0dd05e92
21 """ 21 """
22 22
23 import os 23 import os
24 import shutil 24 import shutil
25 25
26 from hgext.convert import common 26 from hgext.convert import common, hg as converthg
27 27
28 from fastimport import processor, parser 28 from fastimport import processor, parser
29
30 # convertor source objects had a getmode() method up to Mercurial 1.5,
31 # but in 1.6 it was merged with getfile()
32 HAVE_GETMODE = hasattr(converthg.mercurial_source, 'getmode')
29 33
30 class fastimport_source(common.converter_source): 34 class fastimport_source(common.converter_source):
31 """Interface between the fastimport processor below and Mercurial's 35 """Interface between the fastimport processor below and Mercurial's
32 normal conversion infrastructure. 36 normal conversion infrastructure.
33 """ 37 """
51 allheads = [] 55 allheads = []
52 for branchheads in self.processor.branchmap.values(): 56 for branchheads in self.processor.branchmap.values():
53 allheads.extend(branchheads) 57 allheads.extend(branchheads)
54 return allheads 58 return allheads
55 59
56 def getfile(self, name, fileid): 60 # Mercurial <= 1.5
57 """Return file contents as a string. rev is the identifier returned 61 if HAVE_GETMODE:
58 by a previous call to getchanges(). 62 def getfile(self, name, fileid):
59 """ 63 """Return file contents as a string. rev is the identifier returned
60 if fileid is None: # deleted file 64 by a previous call to getchanges().
61 raise IOError 65 """
62 return self.processor.getblob(fileid) 66 if fileid is None: # deleted file
63 67 raise IOError
64 def getmode(self, name, fileid): 68 return self.processor.getblob(fileid)
65 """Return file mode, eg. '', 'x', or 'l'. rev is the identifier 69
66 returned by a previous call to getchanges(). 70 def getmode(self, name, fileid):
67 """ 71 """Return file mode, eg. '', 'x', or 'l'. rev is the identifier
68 return self.processor.getmode(name, fileid) 72 returned by a previous call to getchanges().
73 """
74 return self.processor.getmode(name, fileid)
75
76 # Mercurial >= 1.6
77 else:
78 def getfile(self, name, fileid):
79 if fileid is None: # deleted file
80 raise IOError
81 return (self.processor.getblob(fileid),
82 self.processor.getmode(name, fileid))
69 83
70 def getchanges(self, commitid): 84 def getchanges(self, commitid):
71 """Returns a tuple of (files, copies). 85 """Returns a tuple of (files, copies).
72 86
73 files is a sorted list of (filename, id) tuples for all files 87 files is a sorted list of (filename, id) tuples for all files