##// END OF EJS Templates
rebase: skip resolved but emptied revisions...
rebase: skip resolved but emptied revisions When rebasing, if a conflict occurs and is resolved in a way the rebased revision becomes empty, it is not skipped, unlike revisions being emptied without conflicts. The reason is: - File 'x' is merged and resolved, merge.update() marks it as 'm' in the dirstate. - rebase.concludenode() calls localrepo.commit(), which calls localrepo.status() which calls dirstate.status(). 'x' shows up as 'm' and is unconditionnally added to the modified files list, instead of being checked again. - localrepo.commit() detects 'x' as changed an create a new revision where only the manifest parents and linkrev differ. Marking 'x' as modified without checking it makes sense for regular merges. But in rebase case, the merge looks normal but the second parent is usually discarded. When this happens, 'm' files in dirstate are a bit irrelevant and should be considered 'n' possibly dirty instead. That is what the current patch does. Another approach, maybe more efficient, would be to pass another flag to merge.update() saying the 'branchmerge' is a bit of a lie and recordupdate() should call dirstate.normallookup() instead of merge(). It is also tempting to add this logic to dirstate.setparents(), moving from two to one parent is what invalidates the 'm' markers. But this is a far bigger change to make. v2: succumb to the temptation and move the logic in dirstate.setparents(). mpm suggested trying _filecommit() first but it is called by commitctx() which knows nothing about the dirstate and comes too late into the game. A second approach was to rewrite the 'm' state into 'n' on the fly in dirstate.status() which failed for graft in the following case: $ hg init repo $ cd repo $ echo a > a $ hg ci -qAm0 $ echo a >> a $ hg ci -m1 $ hg up 0 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg mv a b $ echo c > b $ hg ci -m2 created new head $ hg graft 1 --tool internal:local grafting revision 1 $ hg --config extensions.graphlog= glog --template '{rev} {desc|firstline}\n' @ 3 1 | o 2 2 | | o 1 1 |/ o 0 0 $ hg log -r 3 --debug --patch --git --copies changeset: 3:19cd7d1417952af13161b94c32e901769104560c tag: tip phase: draft parent: 2:b5c505595c9e9a12d5dd457919c143e05fc16fb8 parent: -1:0000000000000000000000000000000000000000 manifest: 3:3d27ce8d02241aa59b60804805edf103c5c0cda4 user: test date: Thu Jan 01 00:00:00 1970 +0000 extra: branch=default extra: source=a03df74c41413a75c0a42997fc36c2de97b26658 description: 1 Here, revision 3 is created because there is a copy record for 'b' in the dirstate and thus 'b' is considered modified. But this information is discarded at commit time since 'b' content is unchanged. I do not know if discarding this information is correct or not, but at this time we cannot represent it anyway. This patch therefore implements the last solution of moving the logic into dirstate.setparents(). It does not sound crazy as 'm' files makes no sense with only one parent. It also makes dirstate.merge() calls .lookupnormal() if there is one parent, to preserve the invariant. I am a bit concerned about introducing this kind of stateful behaviour to existing code which historically treated setparents() as a basic setter without side-effects. And doing that during the code freeze.

File last commit:

r13302:a4e0908c default
r16509:eab9119c stable
Show More
base85.c
180 lines | 3.3 KiB | text/x-c | CLexer
/*
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>
#include "util.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;
int pad = 0;
if (!PyArg_ParseTuple(args, "s#|i", &text, &len, &pad))
return NULL;
if (pad)
olen = ((len + 3) / 4 * 5) - 3;
else {
olen = len % 4;
if (olen)
olen++;
olen += len / 4 * 5;
}
if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3)))
return NULL;
dst = PyBytes_AsString(out);
while (len) {
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;
}
if (!pad)
_PyBytes_Resize(&out, olen);
return out;
}
static PyObject *
b85decode(PyObject *self, PyObject *args)
{
PyObject *out;
const char *text;
char *dst;
int len, i, j, olen, c, cap;
unsigned int acc;
if (!PyArg_ParseTuple(args, "s#", &text, &len))
return NULL;
olen = len / 5 * 4;
i = len % 5;
if (i)
olen += i - 1;
if (!(out = PyBytes_FromStringAndSize(NULL, olen)))
return NULL;
dst = PyBytes_AsString(out);
i = 0;
while (i < len)
{
acc = 0;
cap = len - i - 1;
if (cap > 4)
cap = 4;
for (j = 0; j < cap; i++, j++)
{
c = b85dec[(int)*text++] - 1;
if (c < 0)
return PyErr_Format(
PyExc_ValueError,
"Bad base85 character at position %d", i);
acc = acc * 85 + c;
}
if (i++ < len)
{
c = b85dec[(int)*text++] - 1;
if (c < 0)
return PyErr_Format(
PyExc_ValueError,
"Bad base85 character at position %d", i);
/* 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;
}
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++)
{
acc = (acc << 8) | (acc >> 24);
*dst++ = acc;
}
}
return out;
}
static char base85_doc[] = "Base85 Data Encoding";
static PyMethodDef methods[] = {
{"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"},
{NULL, NULL}
};
#ifdef IS_PY3K
static struct PyModuleDef base85_module = {
PyModuleDef_HEAD_INIT,
"base85",
base85_doc,
-1,
methods
};
PyMODINIT_FUNC PyInit_base85(void)
{
b85prep();
return PyModule_Create(&base85_module);
}
#else
PyMODINIT_FUNC initbase85(void)
{
Py_InitModule3("base85", methods, base85_doc);
b85prep();
}
#endif