Commit Graph

749 Commits

Author SHA1 Message Date
Siddharth Agarwal
51c7d417b5 annotate: add a new experimental --skip option to skip revs
This option is most useful for mechanical code modifications, especially ones
that retain the same number of lines.
2017-05-24 19:39:33 -07:00
Siddharth Agarwal
259f128038 annotate: add core algorithm to skip a rev
The core algorithm is inspired by git hyper-blame, implemented at
https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/master/git_hyper_blame.py.

The heuristic is as documented in the comments.
2017-05-24 19:07:14 -07:00
Siddharth Agarwal
19daf128b1 annotate: make pair take all parents to pair against
In upcoming patches we'll need to be aware of all parents at the same time.

This also exposes a potential bug: if a line can be annotated with both parents
of a merge commit, it'll always be annotated with p2, not p1. I'm not sure if
that's what we want, but at least the code makes it clear now.
2017-05-24 17:40:08 -07:00
Siddharth Agarwal
136c8f6192 annotate: move pair function to top level
We'll want to make this more complicated and have unit tests for it in upcoming
patches.
2017-05-24 17:38:28 -07:00
Boris Feld
b66380af61 devel: add a config field to force dates to timestamp 0
Add a new config field named default-date under the devel section to force all
implicits date to a specific value. If a explicit date is passed, it will
override the default.

This patch only affect changesets. Other usages (blackbox, obsmarkers) are
updated in later patchs.

The test runner is setting a bunch of alias to force the '--date' argument. We
will replace theses aliases in a later patch.
2017-05-19 12:18:25 +02:00
Martin von Zweigbergk
722dff8abb match: replace icasefsmatch() function by flag to regular match()
match() will soon gain more logic and we don't want to duplicate that
in icasefsmatch(), so merge the two functions instead and use a flag
to get case-insensitive behavior.
2017-05-18 22:20:59 -07:00
Martin von Zweigbergk
ab0ee38146 match: replace match class by match function (API)
The matcher class is getting hard to understand. It will be easier to
follow if we can break it up into simpler matchers that we then
compose. I'm hoping to have one matcher that accepts regular
(non-include) patterns, one for exact file matches, one that always
matches (and maybe one that never does) and then compose them by
intersection and difference.

This patch takes a simple but important step towards that goal by
making match.match() a function (and renaming the matcher class itself
from "match" to "matcher"). The new function will eventually be
responsible for creating the simple matchers and composing them.

icasefsmatcher similarly gets a factory function (called
"icasefsmatch"). I also moved the other factory functions nearby.
2017-05-12 23:11:41 -07:00
Augie Fackler
f75f070546 context: migrate to context manager for changing dirstate parents 2017-05-18 17:11:07 -04:00
Jun Wu
384e554e79 filectx: add an overlayfilectx class
The end goal is to make it possible to avoid potential expensive fctx.data()
when unnecessary.

While memctx is useful for creating new file contexts, there are many cases
where we could reuse an existing raw file revision (amend, histedit, rebase,
process a revision constructed by a remote peer, etc). The overlayfilectx
class is made to support such reuse cases. Together with a later patch, hash
calculation and expensive flag processor could be avoided.
2017-05-09 20:23:21 -07:00
Jun Wu
eeacfd5a3b filectx: remove __new__
It does not seem to be used anywhere, and breaks a later patch.
2017-05-09 19:16:48 -07:00
Jun Wu
832b866521 filectx: add a rawflags method
The new method returns the low-level revlog flag. We already have "rawdata"
so a "rawflags" makes sense.

Both "rawflags" and "rawdata" will be used in a later patch.
2017-05-09 16:34:12 -07:00
Jun Wu
f131743929 filectx: move size to basefilectx
See previous patch for context - avoid code duplication.
2017-05-09 19:53:31 -07:00
Jun Wu
a24f7109e4 filectx: make renamed a property cache
See previous patch for context - mainly to avoid code duplication.
2017-05-09 19:48:57 -07:00
Jun Wu
fbe796f9ab filectx: make flags a property cache
Make basefilectx._flags a property cache, so basefilectx.flags() could be
reasonably reused. This avoids code duplication between memfilectx and a
class added in a later patch.
2017-05-09 19:23:28 -07:00
Pulkit Goyal
9039b3baeb py3: use raw strings while accessing class.__dict__
The keys of class.__dict__ are unicodes on Python 3.
2017-04-28 01:13:07 +05:30
Denis Laxalde
d7d47fec65 context: optimize linkrev adjustment in blockancestors() (issue5538)
We set parent._descendantrev = child.rev() when walking parents in
blockancestors() so that, when linkrev adjustment is perform for these, it
starts from a close descendant instead of possibly topmost introrev. (See
`self._adjustlinkrev(self._descendantrev)` in filectx._changeid().)

This is similar to changeset 8758896efb1c, which added a "f._changeid"
instruction in annotate() for the same purpose.
However, here, we set _descendantrev explicitly instead of relying on the
'_changeid' cached property being accessed (with effect to set _changeid
attribute) so that, in _parentfilectx() (called from parents()), we go through
`if '_changeid' in vars(self) [...]` branch in which instruction
`fctx._descendantrev = self.rev()` finally appears and does what we want.

With this, we can roughly get a 3x speedup (including in example of issue5538
from mozilla-central repository) on usage of followlines revset (and
equivalent hgweb request).
2017-04-24 18:33:23 +02:00
Denis Laxalde
7cc06d2fbf context: start walking from "introrev" in blockancestors()
Previously, calling blockancestors() with a fctx not touching file would
sometimes yield this filectx first, instead of the first "block ancestor",
because when compared to its parent it may have changes in specified line
range despite not touching the file at all.

Fixing this by starting the algorithm from the "base" filectx obtained using
fctx.introrev() (as done in annotate()).

In tests, add a changeset not touching file we want to follow lines of to
cover this case. Do this in test-annotate.t for followlines revset tests and
in test-hgweb-filelog.t for /log/<rev>/<file>?linerange=<from>:<to> tests.
2017-04-20 21:40:28 +02:00
Pierre-Yves David
d03144db9c hidden: extract the code generating "filtered rev" error for wrapping
The goal is to help experimentation in extensions (ie: evolve) around more
advance messages.
2017-04-15 18:13:10 +02:00
Denis Laxalde
631e6988ca context: possibly yield initial fctx in blockdescendants()
If initial 'fctx' has changes in line range with respect to its parents, we
yield it first. This makes 'followlines(..., descend=True)' consistent with
'descendants()' revset which yields the starting revision.

We reuse one iteration of blockancestors() which does exactly what we want.

In test-annotate.t, adjust 'startrev' in one case to cover the situation where
the starting revision does not touch specified line range.
2017-04-14 14:25:06 +02:00
Denis Laxalde
559326afdb context: add an assertion checking linerange consistency in blockdescendants()
If this assertion fails, this indicates a flaw in the algorithm. So fail fast
instead of possibly producing wrong results.

Also extend the target line range in test to catch a merge changeset with all
its parents.
2017-04-14 14:09:26 +02:00
Denis Laxalde
761577866a context: follow all branches in blockdescendants()
In the initial implementation of blockdescendants (and thus followlines(...,
descend=True) revset), only the first branch encountered in descending
direction was followed.

Update the algorithm so that all children of a revision ('x' in code) are
considered. Accordingly, we need to prevent a child revision to be yielded
multiple times when it gets visited through different path, so we skip 'i'
when this occurs. Finally, since we now consider all parents of a possible
child touching a given line range, we take care of yielding the child if it
has a diff in specified line range with at least one of its parent (same logic
as blockancestors()).
2017-04-14 08:55:18 +02:00
Denis Laxalde
d7409a0458 context: add a blockdescendants function
This is symmetrical with blockancestors() and yields descendants of a filectx
with changes in the given line range. The noticeable difference is that the
algorithm does not follow renames (probably because filelog.descendants() does
not), so we are missing branches with renames.
2017-04-10 15:11:36 +02:00
Jun Wu
e06554212d metadataonlyctx: replace "changeset()[0]" to "manifestnode()"
As Yuya pointed out [1], "changeset()[0]" could be simplified to
"manifestnode()". I didn't notice that method earlier. It should definitely
be used - it's easier to read, and faster.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/095716.html
2017-04-07 11:02:43 -07:00
Jun Wu
faefa92b13 metadataonlyctx: speed up sanity check
Previously the sanity check will construct manifestctx for both p1 and p2.
But it only needs the "manifest node" information, which could be read from
changelog directly.
2017-03-26 12:26:35 -07:00
FUJIWARA Katsunori
aaa8db9cef misc: update descriptions about removed file for filectxfn
Since 2eef89bfd70d, filectxfn for memctx should return None for
removed file instead of raising IOError.
2017-03-24 22:13:23 +09:00
Gregory Szorc
5ca0f908bf py3: add __bool__ to every class defining __nonzero__
__nonzero__ was renamed to __bool__ in Python 3. This patch simply
aliases __bool__ to __nonzero__ for every class implementing
__nonzero__.
2017-03-13 12:40:14 -07:00
Pierre-Yves David
8561a8e8ff context: simplify call to icase matcher in 'match()'
The two function takes the very same arguments. We make this clearer and less
error prone by dispatching on the function only and having a single call point
in the code.
2017-03-15 15:38:02 -07:00
Pierre-Yves David
b9d210d680 context: explicitly tests for None
Changeset c832083e5671 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:33:24 -07:00
Gregory Szorc
b1f8fb51cd context: don't use mutable default argument value
Mutable default argument values are a Python gotcha and can
represent subtle, hard-to-find bugs. Lets rid our code base
of them.
2017-03-12 21:50:42 -07:00
Augie Fackler
d214daa434 context: use portable construction to verify int parsing 2017-03-12 00:43:47 -05:00
Augie Fackler
d44c41fe19 context: implement both __bytes__ and __str__ for Python 3
They're very similar, for obvious reasons.
2017-03-11 20:57:40 -05:00
Augie Fackler
89600a72c4 context: work around long not existing on Python 3
I can't figure out what this branch is even trying to accomplish, and
it was introduced in 387a3aa50d61 which doesn't really shed any
insight into why longs are treated differently from ints.
2017-03-11 20:57:04 -05:00
Mads Kiilerich
a936a7f3a7 vfs: use repo.wvfs.unlinkpath 2015-01-14 01:15:26 +01:00
Durham Goode
2d56462702 context: remove uses of manifest.matches
This removes the uses of manifest.matches in context.py in favor of the new
manifest.diff(match) api. This is part of removing manifest.matches since it is
O(manifest).

To drop the dependency on ctx._manifestmatches(s) we transfer responsibilty for
creating status oriented manifests over to ctx._buildstatusmanifest(s). This
already existed for workingctx, we just need to implement a simple version for
basectx. The old _manifestmatches functionality is basically identical to the
_buildstatusmanifest functionality (minus the matching part), so no behavior
should be lost.
2017-03-07 17:52:45 -08:00
Durham Goode
16ae1e05bb context: remove assumptions about manifest creation during _buildstatus
Previously we called self.manifest() in some cases to preload the
first manifest. This relied on the assumption that the later
_manifestmatches() call did not duplicate any work the original
self.manifest() call did. Let's remove that assumption, since it bit
me during my refactors of this area and is easy to remove.
2017-03-07 17:49:50 -08:00
Durham Goode
d0909f9a09 context: move _manifest from committablectx to workingctx
committablectx had a _manifest implementation that was only used by the derived
workingctx class. The other derived versions, like memctx and metadataonlyctx,
define their own _manifest functions.

Let's move the function down to workingctx, and let's break it into two parts,
the _manifest part that reads from self._status, and the part that actually
builds the new manifest. This separation will let us reuse the builder code in a
future patch to answer _buildstatus with varying status inputs, since workingctx
has special behavior for _buildstatus that the other ctx's don't have.
2017-03-07 17:56:30 -08:00
Durham Goode
31c97f4a1c status: handle more node indicators in buildstatus
There are several different node markers that indicate different working copy
states. The context._buildstatus function was only handling one of them, and
this patch makes it handle all of them (falling back to file content comparisons
when in one of these states).

This affects a future patch where we get rid of context._manifestmatches as part
of getting rid of manifest.matches(). context._manifestmatches is currently
hacky in that it uses the newnodeid for all added and modified files, which is
why the current newnodeid check is sufficient. When we get rid of this function
and use the normal manifest.diff function, we start to see the other indicators
in the nodes, so they need to be handled or else the tests fail.
2017-03-07 09:56:11 -08:00
Denis Laxalde
ca5e4eec65 context: also return ancestor's line range in blockancestors 2017-01-16 17:14:36 +01:00
Denis Laxalde
d3bcba7d25 context: add a followfirst flag to blockancestors 2017-01-16 17:08:25 +01:00
Denis Laxalde
098c0d5368 context: extract _changesinrange() out of blockancestors()
We'll need it to write a blockdescendants function in next changeset.
2017-01-16 09:22:32 +01:00
Remi Chaintron
6d11b9177b revlog: add 'raw' argument to revision and _addrevision
This patch introduces a new 'raw' argument (defaults to False) to revlog's
revision() and _addrevision() methods.
When the 'raw' argument is set to True, it indicates the revision data should be
handled as raw data by the flagprocessor.

Note: Given revlog.addgroup() calls are restricted to changegroup generation, we
can always set raw to True when calling revlog._addrevision() from
revlog.addgroup().
2017-01-05 17:16:07 +00:00
Denis Laxalde
7092fa95d8 context: add a blockancestors(fctx, fromline, toline) function
This yields ancestors of `fctx` by only keeping changesets touching the file
within specified linerange = (fromline, toline).

Matching revisions are found by inspecting the result of `mdiff.allblocks()`,
filtered by `mdiff.blocksinrange()`, to find out if there are blocks of type
"!" within specified line range.

If, at some iteration, an ancestor with an empty line range is encountered,
the algorithm stops as it means that the considered block of lines actually
has been introduced in the revision of this iteration. Otherwise, we finally
yield the initial revision of the file as the block originates from it.

When a merge changeset is encountered during ancestors lookup, we consider
there's a diff in the current line range as long as there is a diff between
the merge changeset and at least one of its parents (in the current line
range).
2016-12-28 23:03:37 +01:00
Jun Wu
76875fcc1b context: correct metadataonlyctx's parameter
It's "originalctx", not "path" as Yuya pointed in [1].

[1]: www.mercurial-scm.org/pipermail/mercurial-devel/2016-December/091508.html
2016-12-16 21:02:39 +00:00
Mateusz Kwapich
3de25e93ce memctx: allow the metadataonlyctx thats reusing the manifest node
When we have a lot of files writing a new manifest revision can be expensive.
This commit adds a possibility for memctx to reuse a manifest from a different
commit. This can be beneficial for commands that are creating metadata changes
without any actual files changed like "hg metaedit" in evolve extension.

I will send the change for evolve that leverages this once this is accepted.
2016-11-21 08:09:41 -08:00
Durham Goode
fb55c2fbf3 dirstate: change added/modified placeholder hash length to 20 bytes
Previously the added/modified placeholder hash for manifests generated from the
dirstate was a 21byte long string consisting of the p1 file hash plus a single
character to indicate an add or a modify. Normal hashes are only 20 bytes long.
This makes it complicated to implement more efficient manifest implementations
which rely on the hashes being fixed length.

Let's change this hash to just be 20 bytes long, and rely on the astronomical
improbability of an actual hash being these 20 bytes (just like we rely on no
hash every being the nullid).

This changes the possible behavior slightly in that the hash for all
added/modified entries in the dirstate manifest will now be the same (so simple
node comparisons would say they are equal), but we should never be doing simple
node comparisons on these nodes even with the old hashes, because they did not
accurately represent the content (i.e. two files based off the same p1 file
node, with different working copy contents would have the same hash (even with
the appended character) in the old scheme too, so we couldn't depend on the
hashes period).
2016-11-10 02:19:16 -08:00
Durham Goode
03d313b5fd dirstate: change placeholder hash length to 20 bytes
Previously the new-node placeholder hash for manifests generated from the
dirstate was a 21byte long string of "!" characters. Normal hashes are only 20
bytes long.  This makes it complicated to implement more efficient manifest
implementations which rely on the hashes being fixed length.

Let's change this hash to just be 20 bytes long, and rely on the astronomical
improbability of an actual hash being 20 "!" bytes in a row (just like we rely
on no hash ever being the nullid).

A future diff will do this for added and modified dirstate markers as well, so
we're putting the new newnodeid in node.py so there's a common place for these
placeholders.
2016-11-10 02:17:22 -08:00
Durham Goode
82152f0a38 context: add manifestctx property on changectx
This allows us to access the manifestctx for a given commit. This will be used
in a later patch to be able to copy the manifestctx when we want to make a new
commit.
2016-11-08 08:03:43 -08:00
Durham Goode
59f421f2ce manifest: remove manifest.find
As part of removing dependencies on manifest, this drops the find function and
fixes up the two existing callers to use the equivalent apis on manifestctx.
2016-11-08 08:03:43 -08:00
Jun Wu
05c17d65e5 adjustlinkrev: remove unnecessary parameters
Since adjustlinkrev has "self", and is a method of a filectx object, it does
not need path, filelog, filenode. They can be fetched from the "self"
easily.
2016-11-01 08:22:50 +00:00
Mads Kiilerich
5d3bf8a78a context: make sure __str__ works, also when there is no _changectx
Before, it could crash when trying to print the wrong kind of object at the
wrong time.
2015-03-19 22:22:50 +01:00