##// END OF EJS Templates
Fill in the uncompressed size during revlog.addgroup...
mason@suse.com -
r2078:441ea218 default
parent child Browse files
Show More
@@ -192,4 +192,5 b' def patch(a, bin):'
192 192 return mpatch.patches(a, [bin])
193 193
194 194 patches = mpatch.patches
195 patchedsize = mpatch.patchedsize
195 196 textdiff = bdiff.bdiff
@@ -354,8 +354,44 b' cleanup:'
354 354 return result;
355 355 }
356 356
357 /* calculate size of a patched file directly */
358 static PyObject *
359 patchedsize(PyObject *self, PyObject *args)
360 {
361 long orig, start, end, len, outlen = 0, last = 0;
362 int patchlen;
363 char *bin, *binend;
364 char decode[12]; /* for dealing with alignment issues */
365
366 if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen))
367 return NULL;
368
369 binend = bin + patchlen;
370
371 while (bin < binend) {
372 memcpy(decode, bin, 12);
373 start = ntohl(*(uint32_t *)decode);
374 end = ntohl(*(uint32_t *)(decode + 4));
375 len = ntohl(*(uint32_t *)(decode + 8));
376 bin += 12 + len;
377 outlen += start - last;
378 last = end;
379 outlen += len;
380 }
381
382 if (bin != binend) {
383 if (!PyErr_Occurred())
384 PyErr_SetString(mpatch_Error, "patch cannot be decoded");
385 return NULL;
386 }
387
388 outlen += orig - last;
389 return Py_BuildValue("l", outlen);
390 }
391
357 392 static PyMethodDef methods[] = {
358 393 {"patches", patches, METH_VARARGS, "apply a series of patches\n"},
394 {"patchedsize", patchedsize, METH_VARARGS, "calculed patched size\n"},
359 395 {NULL, NULL}
360 396 };
361 397
@@ -342,8 +342,40 b' class revlog(object):'
342 342 if self.version != 0:
343 343 return self.ngoffset(self.index[rev][0])
344 344 return self.index[rev][0]
345
345 346 def end(self, rev): return self.start(rev) + self.length(rev)
346 347
348 def size(self, rev):
349 """return the length of the uncompressed text for a given revision"""
350 l = -1
351 if self.version != 0:
352 l = self.index[rev][2]
353 if l >= 0:
354 return l
355
356 t = self.revision(self.node(rev))
357 return len(t)
358
359 # alternate implementation, The advantage to this code is it
360 # will be faster for a single revision. But, the results are not
361 # cached, so finding the size of every revision will be slower.
362 """
363 if self.cache and self.cache[1] == rev:
364 return len(self.cache[2])
365
366 base = self.base(rev)
367 if self.cache and self.cache[1] >= base and self.cache[1] < rev:
368 base = self.cache[1]
369 text = self.cache[2]
370 else:
371 text = self.revision(self.node(base))
372
373 l = len(text)
374 for x in xrange(base + 1, rev + 1):
375 l = mdiff.patchedsize(l, self.chunk(x))
376 return l
377 """
378
347 379 def length(self, rev):
348 380 if rev < 0:
349 381 return 0
@@ -904,7 +936,7 b' class revlog(object):'
904 936 node = None
905 937
906 938 base = prev = -1
907 start = end = measure = 0
939 start = end = textlen = 0
908 940 if r:
909 941 end = self.end(t)
910 942
@@ -949,8 +981,9 b' class revlog(object):'
949 981 if chain == prev:
950 982 tempd = compress(delta)
951 983 cdelta = tempd[0] + tempd[1]
984 textlen = mdiff.patchedsize(textlen, delta)
952 985
953 if chain != prev or (end - start + len(cdelta)) > measure * 2:
986 if chain != prev or (end - start + len(cdelta)) > textlen * 2:
954 987 # flush our writes here so we can read it in revision
955 988 if dfh:
956 989 dfh.flush()
@@ -960,12 +993,12 b' class revlog(object):'
960 993 chk = self.addrevision(text, transaction, link, p1, p2)
961 994 if chk != node:
962 995 raise RevlogError(_("consistency error adding group"))
963 measure = len(text)
996 textlen = len(text)
964 997 else:
965 998 if self.version == 0:
966 999 e = (end, len(cdelta), base, link, p1, p2, node)
967 1000 else:
968 e = (self.offset_type(end, 0), len(cdelta), -1, base,
1001 e = (self.offset_type(end, 0), len(cdelta), textlen, base,
969 1002 link, self.rev(p1), self.rev(p2), node)
970 1003 self.index.append(e)
971 1004 self.nodemap[node] = r
General Comments 0
You need to be logged in to leave comments. Login now