##// END OF EJS Templates
localrepo.commit: normalize commit message even for rawcommit....
localrepo.commit: normalize commit message even for rawcommit. This normalization consists of: - stripping trailing whitespace - always using "\n" as the line separator I think the main reason rawcommit was skipping this normalization was an attempt to preserve hashes during an hg->hg conversion. While this is a nice goal, it's not particularly interesting in practice. Since SHA-1 is so strong, the only safe way to do it is to have absolutely identical revisions. But: - if the original revision was created with a recent version of hg, the commit message will be the same, with or without that normalization - if it was created with an ancient version of hg that didn't do any normalization, even if the commit message is identical, the file list in the changelog is likely to be different (e.g. no removed files), and there were some old issues with e.g. extra file merging, which will end up changing the hash anyway - in any case, if one *really* has to preserve hashes, it's easier (and faster) to fake a partial conversion using something like: hg clone -U -r rev orig-repo new-repo hg -R new-repo log --template '#node# #node#\n' > new-repo/.hg/shamap Additionally, we've had some reports of problems arising from this lack of normalization - e.g. issue871, and a user that was wondering why hg export/hg import was not preserving hashes when there was nothing unusual going on (it was just import doing the normalization that had been skipped). This also means that it's even more unlikely to get identical revisions when going $VCS->hg->$VCS.

File last commit:

r3369:4bad6329 default
r6254:3667b6e4 default
Show More
base85.c
155 lines | 3.2 KiB | text/x-c | CLexer
Brendan Cully
Add a base85 codec
r3283 /*
base85 codec
Copyright 2006 Brendan Cully <brendan@kublai.com>
This software may be used and distributed according to the terms of
the GNU General Public License, incorporated herein by reference.
Largely based on git's implementation
*/
#include <Python.h>
static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
static char b85dec[256];
static void
b85prep(void)
{
int i;
memset(b85dec, 0, sizeof(b85dec));
for (i = 0; i < sizeof(b85chars); i++)
b85dec[(int)(b85chars[i])] = i + 1;
}
static PyObject *
b85encode(PyObject *self, PyObject *args)
{
const unsigned char *text;
PyObject *out;
char *dst;
int len, olen, i;
unsigned int acc, val, ch;
Brendan Cully
Handle odd-sized base85 input and output
r3288 int pad = 0;
Brendan Cully
Add a base85 codec
r3283
Alexis S. L. Carvalho
python2.5 PyArg_ParseTuple fix...
r3369 if (!PyArg_ParseTuple(args, "s#|i", &text, &len, &pad))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Brendan Cully
Handle odd-sized base85 input and output
r3288 if (pad)
olen = ((len + 3) / 4 * 5) - 3;
else {
olen = len % 4;
if (olen)
olen++;
olen += len / 4 * 5;
}
if (!(out = PyString_FromStringAndSize(NULL, olen + 3)))
Brendan Cully
Add a base85 codec
r3283 return NULL;
dst = PyString_AS_STRING(out);
Brendan Cully
Handle odd-sized base85 input and output
r3288 while (len) {
Brendan Cully
Add a base85 codec
r3283 acc = 0;
for (i = 24; i >= 0; i -= 8) {
ch = *text++;
acc |= ch << i;
if (--len == 0)
break;
}
for (i = 4; i >= 0; i--) {
val = acc % 85;
acc /= 85;
dst[i] = b85chars[val];
}
dst += 5;
}
Brendan Cully
Handle odd-sized base85 input and output
r3288 if (!pad)
_PyString_Resize(&out, olen);
Brendan Cully
Add a base85 codec
r3283 return out;
}
static PyObject *
b85decode(PyObject *self, PyObject *args)
{
PyObject *out;
const char *text;
char *dst;
Brendan Cully
Handle odd-sized base85 input and output
r3288 int len, i, j, olen, c, cap;
Brendan Cully
Add a base85 codec
r3283 unsigned int acc;
Alexis S. L. Carvalho
python2.5 PyArg_ParseTuple fix...
r3369 if (!PyArg_ParseTuple(args, "s#", &text, &len))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Brendan Cully
Handle odd-sized base85 input and output
r3288 olen = len / 5 * 4;
i = len % 5;
if (i)
olen += i - 1;
Brendan Cully
Add a base85 codec
r3283 if (!(out = PyString_FromStringAndSize(NULL, olen)))
return NULL;
dst = PyString_AS_STRING(out);
Brendan Cully
Handle odd-sized base85 input and output
r3288 i = 0;
while (i < len)
Brendan Cully
Add a base85 codec
r3283 {
acc = 0;
Brendan Cully
Handle odd-sized base85 input and output
r3288 cap = len - i - 1;
if (cap > 4)
cap = 4;
for (j = 0; j < cap; i++, j++)
Brendan Cully
Add a base85 codec
r3283 {
c = b85dec[(int)*text++] - 1;
if (c < 0)
return PyErr_Format(PyExc_ValueError, "Bad base85 character at position %d", i);
acc = acc * 85 + c;
}
Brendan Cully
Handle odd-sized base85 input and output
r3288 if (i++ < len)
Brendan Cully
Add a base85 codec
r3283 {
c = b85dec[(int)*text++] - 1;
if (c < 0)
return PyErr_Format(PyExc_ValueError, "Bad base85 character at position %d", i);
Brendan Cully
Handle odd-sized base85 input and output
r3288 /* overflow detection: 0xffffffff == "|NsC0",
* "|NsC" == 0x03030303 */
if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
return PyErr_Format(PyExc_ValueError, "Bad base85 sequence at position %d", i);
acc += c;
Brendan Cully
Add a base85 codec
r3283 }
Brendan Cully
Handle odd-sized base85 input and output
r3288 cap = olen < 4 ? olen : 4;
olen -= cap;
for (j = 0; j < 4 - cap; j++)
acc *= 85;
if (cap && cap < 4)
acc += 0xffffff >> (cap - 1) * 8;
for (j = 0; j < cap; j++)
Brendan Cully
Add a base85 codec
r3283 {
acc = (acc << 8) | (acc >> 24);
Brendan Cully
Handle odd-sized base85 input and output
r3288 *dst++ = acc;
Brendan Cully
Add a base85 codec
r3283 }
}
return out;
}
static char base85_doc[] = "Base85 Data Encoding";
static PyMethodDef methods[] = {
Brendan Cully
Handle odd-sized base85 input and output
r3288 {"b85encode", b85encode, METH_VARARGS,
"Encode text in base85.\n\n"
"If the second parameter is true, pad the result to a multiple of "
"five characters.\n"},
{"b85decode", b85decode, METH_VARARGS, "Decode base85 text.\n"},
Brendan Cully
Add a base85 codec
r3283 {NULL, NULL}
};
PyMODINIT_FUNC initbase85(void)
{
Py_InitModule3("base85", methods, base85_doc);
b85prep();
}