def annotatealllines(self, rev, showpath=False, showlines=False): """(rev : str) -> [(node : str, linenum : int, path : str)] the result has the same format with annotate, but include all (including deleted) lines up to rev. call this after calling annotate(rev, ...) for better performance and accuracy. """ revfctx = self._resolvefctx(rev, resolverev=True, adjustctx=True) # find a chain from rev to anything in the mainbranch if revfctx not in self.revmap: chain = [revfctx] a = "" while True: f = chain[-1] pl = self._parentfunc(f) if not pl: break if pl[0] in self.revmap: a = pl[0].data() break chain.append(pl[0]) # both self.linelog and self.revmap is backed by filesystem. now # we want to modify them but do not want to write changes back to # files. so we create in-memory objects and copy them. it's like # a "fork". linelog = linelogmod.linelog() linelog.copyfrom(self.linelog) linelog.annotate(linelog.maxrev) revmap = revmapmod.revmap() revmap.copyfrom(self.revmap) for f in reversed(chain): b = f.data() blocks = list(self._diffblocks(a, b)) self._doappendrev(linelog, revmap, f, blocks) a = b else: # fastpath: use existing linelog, revmap as we don't write to them linelog = self.linelog revmap = self.revmap lines = linelog.getalllines() hsh = revfctx.node() llrev = revmap.hsh2rev(hsh) result = [(revmap.rev2hsh(r), l) for r, l in lines if r <= llrev] # cannot use _refineannotateresult since we need custom logic for # resolving line contents if showpath: result = self._addpathtoresult(result, revmap) if showlines: linecontents = self._resolvelines(result, revmap, linelog) result = (result, linecontents) return result
def _buildlinelog(self): """calculate the initial linelog based on self.content{,line}s. this is similar to running a partial "annotate". """ llog = linelog.linelog() a, alines = b"", [] for i in range(len(self.contents)): b, blines = self.contents[i], self.contentlines[i] llrev = i * 2 + 1 chunks = self._alldiffchunks(a, b, alines, blines) for a1, a2, b1, b2 in reversed(list(chunks)): llog.replacelines(llrev, a1, a2, b1, b2) a, alines = b, blines return llog
if usevec: blines = [(randint(0, rev), randint(0, maxlinenum)) for _ in range(b1, b2)] else: blines = [(rev, bidx) for bidx in range(b1, b2)] lines[a1:a2] = blines yield lines, rev, a1, a2, b1, b2, blines, usevec def ensure(condition): if not condition: raise RuntimeError("Unexpected") # init seed = random.random() log = linelog.linelog() log.clear() log.annotate(0) # how many random revisions we generate endrev = 2000 try: endrev = int(sys.argv[1]) except Exception: pass # populate linelog for lines, rev, a1, a2, b1, b2, blines, usevec in generator(seed, endrev): if usevec: log.replacelines_vec(rev, a1, a2, blines) else:
def linelog(self): if self._linelog is None: self._linelog = linelogmod.linelog(pycompat.encodeutf8(self.linelogpath)) return self._linelog
def linelog(self): if self._linelog is None: self._linelog = linelogmod.linelog(self.linelogpath) return self._linelog