revlog: don't say "not found" on internal error
If index_node() returned NULL, then index_find_node() and and
nt_partialmatch() used to return -2 to signal that the node was not
found. However, we were passing in a revnum to index_node() that we
knew should exist, so the only reason it could return NULL was due to
some internal error or perhaps out of memory. Let's not use "not
found" for these cases. I suppose we never noticed this because these
error never happen in practice.
I think there are more places where we should error out instead of
reporting that the node was not found, but the cases mentioned above
were all I cared about right now (because using the same error code
for all failures simplified some future patches).
Differential Revision: https://phab.mercurial-scm.org/D3457
revlog: extract function for getting node from known-to-exist rev
Many of the calls to index_node() (which converts a rev to a nodeid)
are done with a rev that's know to exist. If the function fails,
there's something really wrong and we should just abort. This was done
in only one place. This patch starts by extracting that code to a
function that we can reuse in later patches.
Differential Revision: https://phab.mercurial-scm.org/D3456
shortest: make {shortest("
fffffffff")} work again
{shortest("
fffffffff")} should shorten it to the shortest unambiguous
prefix for the working directory. It used to do that until I broke it
in
7b2955624777 (scmutil: make shortesthexnodeidprefix() take a full
binary nodeid, 2018-04-14), when we started returning the full hex
nodeid for any working directory prefix shorter than 40 hex
digits. This patch fixes it by catching WdirUnsupported
specifically.
Differential Revision: https://phab.mercurial-scm.org/D3455
revlog: use radix tree also for matching keys shorter than 4 hex digits
I don't know what the reason for the 4-digit limit was, and I can't
think of any real disadvantages of using the radix tree also when the
requested minimum length is short. This speeds up `hg log -T
'{shortest(node,1)}\n'` from 2m16s to 4.5s by making that not fall
back to pure code.
Differential Revision: https://phab.mercurial-scm.org/D3453
context: convert to hex for error message only for 20-byte changeid
Now that 20-byte strings unambiguously mean binary (or a bug), we can
specialize the conversion to hex for that case.
Differential Revision: https://phab.mercurial-scm.org/D3452
context: clarify that only one attempt is made to interpret changeid
We can now tell what type of revision specifier we have just by
looking at it (we no longer attempt to interpret it in one way after
the other -- that's now in scmutil.revsymbol()). Let's clarify this in
the code by swithing to if/elif.
Differential Revision: https://phab.mercurial-scm.org/D3451
context: only bother looking for broken dirstate for 20-byte changeid
If we fail to look up a changeid in changectx.__init__, we check if it
exactly matches any of the dirstate parents, and if it does, we print
a more specific message ("working directory has unknown parent '...'!"
instead of "unknown revision '...'"). The dirstate parents are always
20 bytes, so there's no need to check for a match when the given
changeid is not 20 bytes. (And now that all the other allowed forms of
changeid have been moved out of the constructor, there's no risk that
a changeid that did match a dirstate parent was actually a valid
bookmark.)
Differential Revision: https://phab.mercurial-scm.org/D3450