Mercurial > hg
comparison hgext/convert/git.py @ 21868:3420346174b1 stable
convert: detect removal of ".gitmodules" at git source revisions correctly
Before this patch, all operations applied on ".gitmodules" at git
source revisions are treated as modification, even if they are
actually removal of it.
If removal of ".gitmodules" is treated as modification unexpectedly,
"hg convert" is aborted by the exception raised in
"retrievegitmodules()" for ".gitmodules" at the git source revision
removing it, because that revision doesn't have any information of
".gitmodules".
This patch detects removal of ".gitmodules" at git source revisions
correctly.
If ".gitmodules" is removed at the git source revision, this patch
records "hex(nullid)" as the contents hash value for ".hgsub" and
".hgsubstate" at the destination revision.
This patch makes "getfile()" raise IOError also for ".hgstatus" and
".hgsubstate" if the contents hash value is "hex(nullid)", and this
tells removal of ".hgstatus" and ".hgsubstate" at the destination
revision to "localrepository.commitctx()" correctly.
For files other than ".hgstatus" and ".hgsubstate", checking the
contents hash value in "getfile()" may be redundant, because
"catfile()" for them also does so.
But this patch chooses writing it only once at the beginning of
"getfile()", to avoid writing same code twice both for ".hgsub" and
".hgsubstate" separately.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 14 Jul 2014 23:33:59 +0900 |
parents | e8203629371b |
children | cf599f8a2da8 |
comparison
equal
deleted
inserted
replaced
21867:829f2dd99f5c | 21868:3420346174b1 |
---|---|
102 if ret: | 102 if ret: |
103 raise util.Abort(_('cannot read %r object at %s') % (type, rev)) | 103 raise util.Abort(_('cannot read %r object at %s') % (type, rev)) |
104 return data | 104 return data |
105 | 105 |
106 def getfile(self, name, rev): | 106 def getfile(self, name, rev): |
107 if rev == hex(nullid): | |
108 raise IOError | |
107 if name == '.hgsub': | 109 if name == '.hgsub': |
108 data = '\n'.join([m.hgsub() for m in self.submoditer()]) | 110 data = '\n'.join([m.hgsub() for m in self.submoditer()]) |
109 mode = '' | 111 mode = '' |
110 elif name == '.hgsubstate': | 112 elif name == '.hgsubstate': |
111 data = '\n'.join([m.hgsubstate() for m in self.submoditer()]) | 113 data = '\n'.join([m.hgsubstate() for m in self.submoditer()]) |
153 fh = self.gitopen("git diff-tree -z --root -m -r %s" % version) | 155 fh = self.gitopen("git diff-tree -z --root -m -r %s" % version) |
154 changes = [] | 156 changes = [] |
155 seen = set() | 157 seen = set() |
156 entry = None | 158 entry = None |
157 subexists = False | 159 subexists = False |
160 subdeleted = False | |
158 for l in fh.read().split('\x00'): | 161 for l in fh.read().split('\x00'): |
159 if not entry: | 162 if not entry: |
160 if not l.startswith(':'): | 163 if not l.startswith(':'): |
161 continue | 164 continue |
162 entry = l | 165 entry = l |
169 p = (entry[1] == "100755") | 172 p = (entry[1] == "100755") |
170 s = (entry[1] == "120000") | 173 s = (entry[1] == "120000") |
171 | 174 |
172 if f == '.gitmodules': | 175 if f == '.gitmodules': |
173 subexists = True | 176 subexists = True |
174 changes.append(('.hgsub', '')) | 177 if entry[4] == 'D': |
178 subdeleted = True | |
179 changes.append(('.hgsub', hex(nullid))) | |
180 else: | |
181 changes.append(('.hgsub', '')) | |
175 elif entry[1] == '160000' or entry[0] == ':160000': | 182 elif entry[1] == '160000' or entry[0] == ':160000': |
176 subexists = True | 183 subexists = True |
177 else: | 184 else: |
178 self.modecache[(f, h)] = (p and "x") or (s and "l") or "" | 185 self.modecache[(f, h)] = (p and "x") or (s and "l") or "" |
179 changes.append((f, h)) | 186 changes.append((f, h)) |
180 entry = None | 187 entry = None |
181 if fh.close(): | 188 if fh.close(): |
182 raise util.Abort(_('cannot read changes in %s') % version) | 189 raise util.Abort(_('cannot read changes in %s') % version) |
183 | 190 |
184 if subexists: | 191 if subexists: |
185 self.retrievegitmodules(version) | 192 if subdeleted: |
186 changes.append(('.hgsubstate', '')) | 193 changes.append(('.hgsubstate', hex(nullid))) |
194 else: | |
195 self.retrievegitmodules(version) | |
196 changes.append(('.hgsubstate', '')) | |
187 return (changes, {}) | 197 return (changes, {}) |
188 | 198 |
189 def getcommit(self, version): | 199 def getcommit(self, version): |
190 c = self.catfile(version, "commit") # read the commit hash | 200 c = self.catfile(version, "commit") # read the commit hash |
191 end = c.find("\n\n") | 201 end = c.find("\n\n") |