Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG1198c86beb73: fastannotate: fix isinstance checks to be against bytes instead of str
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| pulkit |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| return result | return result | ||||
| def annotatedirectly(self, f, showpath, showlines): | def annotatedirectly(self, f, showpath, showlines): | ||||
| """like annotate, but when we know that f is in linelog. | """like annotate, but when we know that f is in linelog. | ||||
| f can be either a 20-char str (node) or a fctx. this is for perf - in | f can be either a 20-char str (node) or a fctx. this is for perf - in | ||||
| the best case, the user provides a node and we don't need to read the | the best case, the user provides a node and we don't need to read the | ||||
| filelog or construct any filecontext. | filelog or construct any filecontext. | ||||
| """ | """ | ||||
| if isinstance(f, str): | if isinstance(f, bytes): | ||||
| hsh = f | hsh = f | ||||
| else: | else: | ||||
| hsh = f.node() | hsh = f.node() | ||||
| llrev = self.revmap.hsh2rev(hsh) | llrev = self.revmap.hsh2rev(hsh) | ||||
| if not llrev: | if not llrev: | ||||
| raise faerror.CorruptedFileError('%s is not in revmap' | raise faerror.CorruptedFileError('%s is not in revmap' | ||||
| % node.hex(hsh)) | % node.hex(hsh)) | ||||
| if (self.revmap.rev2flag(llrev) & revmapmod.sidebranchflag) != 0: | if (self.revmap.rev2flag(llrev) & revmapmod.sidebranchflag) != 0: | ||||
| raise faerror.CorruptedFileError('%s is not in revmap mainbranch' | raise faerror.CorruptedFileError('%s is not in revmap mainbranch' | ||||
| % node.hex(hsh)) | % node.hex(hsh)) | ||||
| self.linelog.annotate(llrev) | self.linelog.annotate(llrev) | ||||
| result = [(self.revmap.rev2hsh(r), l) | result = [(self.revmap.rev2hsh(r), l) | ||||
| for r, l in self.linelog.annotateresult] | for r, l in self.linelog.annotateresult] | ||||
| return self._refineannotateresult(result, f, showpath, showlines) | return self._refineannotateresult(result, f, showpath, showlines) | ||||
| def _refineannotateresult(self, result, f, showpath, showlines): | def _refineannotateresult(self, result, f, showpath, showlines): | ||||
| """add the missing path or line contents, they can be expensive. | """add the missing path or line contents, they can be expensive. | ||||
| f could be either node or fctx. | f could be either node or fctx. | ||||
| """ | """ | ||||
| if showpath: | if showpath: | ||||
| result = self._addpathtoresult(result) | result = self._addpathtoresult(result) | ||||
| if showlines: | if showlines: | ||||
| if isinstance(f, str): # f: node or fctx | if isinstance(f, bytes): # f: node or fctx | ||||
| llrev = self.revmap.hsh2rev(f) | llrev = self.revmap.hsh2rev(f) | ||||
| fctx = self._resolvefctx(f, self.revmap.rev2path(llrev)) | fctx = self._resolvefctx(f, self.revmap.rev2path(llrev)) | ||||
| else: | else: | ||||
| fctx = f | fctx = f | ||||
| lines = mdiff.splitnewlines(fctx.data()) | lines = mdiff.splitnewlines(fctx.data()) | ||||
| if len(lines) != len(result): # linelog is probably corrupted | if len(lines) != len(result): # linelog is probably corrupted | ||||
| raise faerror.CorruptedFileError() | raise faerror.CorruptedFileError() | ||||
| result = (result, lines) | result = (result, lines) | ||||