Commit Graph

340 Commits

Author SHA1 Message Date
Sean Farley
6f4798a10d basectx: move sub from changectx 2013-08-05 18:40:36 -05:00
Sean Farley
e090a5106f basectx: move flags from changectx 2013-08-05 18:28:54 -05:00
Sean Farley
2cd511aaf5 basectx: move filenode from changectx 2013-08-05 18:28:40 -05:00
Sean Farley
7d373f2849 basectx: move _fileinfo from changectx 2013-08-05 18:28:23 -05:00
Sean Farley
6af5ffc183 basectx: move p2 from changectx 2013-08-05 18:26:54 -05:00
Sean Farley
5d4918976c basectx: move p1 from changectx 2013-08-05 18:26:15 -05:00
Sean Farley
4d440ce0c1 basectx: move parents from changectx 2013-08-05 18:19:38 -05:00
Sean Farley
0767e83eed basectx: move mutable from changectx 2013-08-05 18:19:19 -05:00
Sean Farley
cfa3733573 basectx: move phasestr from changectx 2013-08-05 18:19:04 -05:00
Sean Farley
9944871a46 basectx: move manifest from changectx 2013-08-05 17:22:49 -05:00
Sean Farley
11dddf4758 basectx: move __iter__ from changectx 2013-08-05 17:22:18 -05:00
Sean Farley
61511fb277 basectx: move __getitem__ from changectx 2013-08-05 17:22:05 -05:00
Sean Farley
8e476c8cae basectx: move __contains__ from changectx 2013-08-05 17:21:38 -05:00
Sean Farley
647fcb2041 basectx: move substate from changectx 2013-08-05 17:21:23 -05:00
Sean Farley
023d601420 basectx: move __ne__ from changectx 2013-08-05 17:00:32 -05:00
Sean Farley
22e31d9ce0 basectx: move __eq__ from changectx
We also add type checking for extra protection.
2013-08-05 17:00:09 -05:00
Sean Farley
c271e20c45 basectx: move __repr__ from changectx
We change the hardcoded 'changectx' to instead use type(self).__name__ so that
objects that inherit from basectx in the future will be able to use the same
representation.
2013-08-02 18:24:08 -05:00
Sean Farley
a6645dbc9c basectx: move __int__ from changectx 2013-08-02 16:52:13 -05:00
Sean Farley
818788f1ff basectx: change _node to node() in hex
This allows a child class to overload the node() function and still share the
same code for hex().
2013-08-02 16:50:13 -05:00
Sean Farley
3113ec1337 basectx: move hex from changectx 2013-08-02 16:49:01 -05:00
Sean Farley
3531329b72 basectx: move node from changectx 2013-08-02 16:48:19 -05:00
Sean Farley
57662a823e basectx: move rev from changectx 2013-08-02 19:09:06 -05:00
Sean Farley
71b2479bed basectx: move __str__ from changectx 2013-08-02 16:46:23 -05:00
Sean Farley
576828ddf4 changectx: if passing a basectx then exit __init__ immediately 2013-08-06 16:42:41 -05:00
Sean Farley
7c95c6b91c basectx: return a copied context if changeid is already a basectx
This implements a copy constructor so that we can pass a basectx-derived object
in future refactorings.
2013-08-06 15:50:28 -05:00
Sean Farley
8bfc82b32e basectx: add an empty class that will be used as a parent of all contexts
At the moment, there is no simple way to check if an object is a context
because there is no common parent class. If there were, we could use
'isinstance' everywhere. Simply having memctx inherit from workingctx or
changectx would allow the use of 'isinstance' but that could lead to some
confusing situations of reading the code since we have three distinct concepts
of a context:

- changectx represents a changeset *already* in the repo, and is therefore immutable
- workingctx represents changes on disk in the working directory
- memctx represents changes solely in memory which may or may not be on disk

Therefore, I propose refactoring context.py to have all three contexts inherit
from a parent class 'basectx'.
2013-07-13 19:59:21 -05:00
Durham Goode
539b1f606b filectx: remove dependencies on filerev
Removing dependencies on filectx.filerev() makes it easier to create a filelog
implementation that doesn't have rev numbers.
2013-05-30 19:29:21 -07:00
Durham Goode
94d98a2fbb annotate: simplify annotate parent function
The annotate algorithm used a custom parents() function to try to reuse
filectx and filelogs. I simplified it a bit to rely more heavily on the
self.parents() which makes it work well with alternative filectx
implementations. I tested performance on a file with 5000+ revisions
but no renames, and on a file with 500 revisions repeating a series of
4 edits+renames and saw zero performance hit.  In fact, it was reliably a
couple milliseconds faster now.

Added the perfannotate command to contrib/perf.py for future use.
2013-05-30 19:29:03 -07:00
Durham Goode
bbcab6cdef filectx: refactor filectx.rev() to use filectx._changeid
The code in filectx.rev() was identical to filectx._changeid. Fixing this
allows alternative filectx implementations to only override _changeid.
2013-05-30 17:49:37 -07:00
Durham Goode
41d830bbb8 filecontext: use 'is not None' to check for filelog existence
Previously we used 'if filelog:' to check if the filelog existed. If the
instance did exist, this pattern then calls len() on the filelog to see
if it is empty. I'm developing a filelog replacement that doesn't have
len() implemented, so it's better to do an explicit 'is not None' check
here instead.

Also change _changeid() to return the _changeid attribute if it has it.
Previously it would try to obtain it from the _changectx(), and if that
did not exist it would construct the _changectx() using the linkrev. In
the extension I'm working on, filectx's don't have easy access to linkrevs
so avoiding this when possible is better.
2013-05-01 10:42:03 -07:00
FUJIWARA Katsunori
387c38ed85 annotate: discard refcount of discarded annotation for memory efficiency
Before this patch, refcount (managed in "needed") of the annotation
result is kept as 1, even if corresponding annotation result is
discarded from "hist", because it isn't decreased and discarded.

In the history tree including merging revision, the most recent common
ancestor of merged revisions is scanned twice. Refcount of such
ancestor never becomes 0, because refcount is started from 1 at the
second scanning.

This prevents annotation results of merging revision in "hist" from
being discarded, and decreases memory efficiency.

This patch discards refcount of the annotation result, when the
corresponding annotation is discarded from "hist".
2013-04-18 19:50:04 +09:00
FUJIWARA Katsunori
3a71637352 annotate: increase refcount of each revisions correctly (issue3841)
Before this patch, refcount (managed in "needed") of parents of each
revisions in "visit" is increased, only when parent is not annotated
yet (examined by "p not in hist").

But this causes less refcount of the revision like "A" in the tree
below ("A" is assumed as the second parent of "C"):

    A --- B --- C
      \       /
       \-----/

Steps of annotation for "C" in this case are shown below:

  1. for "C"
    1.1 increase refcount of "B"
    1.2 increase refcount of "A" (=> 1)
    1.3 defer annotation for "C"

  2. for "A"
    2.1 annotate for "A" (=> put result into "hist[A]")
    2.2 clear "pcache[A]" ("pcache[A] = []")

  3. for "B"
    3.1 not increase refcount of "A", because "A not in hist" is False
    3.2 annotate for "B"
    3.3 decrease refcount of "A" (=> 0)
    3.4 delete "hist[A]", even though "A" is still needed by "C"
    3.5 clear "pcache[B]"

  4. for "C", again
    4.1 not increase refcount of "B", because "B not in hist" is False
    4.2 increase refcount of "A" (=> 1)
    4.3 defer annotation for "C"

  5. for "A", again
    5.1 annotate for "A" (=> put result into "hist[A]", again)
    5.2 clear "pcache[A]"

  6. for "C", once again
    6.1 not increase refcount of "B", because "B not in hist" is False
    6.2 not increase refcount of "A", because "A not in hist" is False
    6.3 annotate for "C"
    6.4 decrease refcount of "A", and delete "hist[A]"
    6.5 decrease refcount of "B", and delete "hist[B]"
    6.6 clear "pcache[C]"

At step (5.1), annotation for "A" mis-recognizes that all lines are
created at "A", because "pcache[A]" already cleared at step (2.2)
prevents from scanning ancestors of "A".

So, annotation for "C" or its descendants loses information about "A"
or its ancestors.

The root cause of this problem is that refcount of "A" is decreased at
step (3.3), even though it isn't increased at step (3.1).

To increase refcount correctly, this patch increases refcount of each
parents of each revisions:

  - regardless of "p not in hist" or not, and
  - only once for each revisions in "visit" (by "not pcached")

In fact, this problem should occur only on legacy repositories in
which a filelog includes the merging between the revision and its
ancestor (as the second parent), because:

  - tree is scanned in depth-first

    without such merging, revisions in "visit" refer different
    revisions as parent each other

  - recent Mercurial doesn't allow such merging

    changelog and manifest can include such merging someway, but
    filelogs can't, because "localrepository._filecommit()" converts
    such merging request to linear history.

This patch tests merging cases below: these cases are from filelog of
"mercurial/commands.py" in the repository of Mercurial itself.

  - both parents are same

        10 --- 11 --- 12
                  \_/

        filelogrev: changesetid:
          10          526aca6bcb38
          11          05098100ff44
          12          2d4f4cfa81d6

  - the second parent is also ancestor of the first one

        37 --- 38 --- 39 --- 40
                  \________/

        filelogrev: changesetid:
          37          033dc4170fe6
          38          5ff1a23ce38c
          39          661a47367859
          40          a2ba99fd026f
2013-03-29 22:57:16 +09:00
FUJIWARA Katsunori
8355d1b7f6 annotate: reuse already calculated annotation
Before this patch, annotation is re-calculated even if it is already
calculated. This may cause unexpected annotation, because already
cleared "pcache" ("pcache[f] = []") prevents from scanning ancestors.

This patch reuses already calculated annotation if it is available.

In fact, "reusable" situation should be seen only on legacy
repositories in which a filelog include the merging between the
revision and its ancestor, because:

  - tree is scanned in depth-first

    without such merging, annotation result should be released soon

  - recent Mercurial doesn't allow such merging

    changelog and manifest can include such merging someway, but
    filelogs can't, because "localrepository._filecommit()" converts
    such merging request to linear history.
2013-03-29 22:57:15 +09:00
Bryan O'Sullivan
4a3a46aff6 ancestor: a new algorithm that is faster for nodes near tip
Instead of walking all the way to the root of the DAG, we generate
a set of candidate GCA revs, then figure out which ones will win
the race to the root (usually without needing to traverse all the
way to the root).

In the common case of nodes that are close to each other in both
revision number and topology, this is usually a big win: it makes
"hg --time debugancestors" up to 9 times faster than the more general
ancestor function when measured on heads of the linux-2.6 hg repo.

Victory is not assured, however. The older function can still win
by a large margin if one node is much closer to the root than the
other, or by a much smaller amount if one is an ancestor of the
other.

For now, we've also got a small paranoid harness function that calls
both ancestor functions on every input and ensures that they give
equivalent answers.

Even without the checker function, the old ancestor function needs
to stay alive for the time being, as its generality is used by
context.filectx.merge.
2013-04-16 10:08:18 -07:00
Mads Kiilerich
a8db98ea05 spelling: fix typos and spelling errors 2013-04-15 01:37:23 +02:00
Bryan O'Sullivan
4a4a5dde94 scmutil: use new dirs class in dirstate and context
The multiset-of-directories code was open coded in each of these
modules; this change gets rid of the duplication.
2013-04-10 15:08:26 -07:00
Bryan O'Sullivan
82ca6ed101 merge with mpm 2013-04-02 08:58:42 -07:00
Takumi IINO
94c0d6fcb6 hgweb: show correct error message for i18n environment
If exception is error.LookupError and running in i18n environment,
below condition is always true.
Because msg is translated and dosen't contain 'manifest'.

    if util.safehasattr(err, 'name') and 'manifest' not in msg:

This patch creates a new exception class and uses it instead of
string match.
2013-02-15 18:07:14 +09:00
Pierre-Yves David
093fc83eab changectx: fix the handling of tip
We can not use `len(repo,changelog)`, it may be a filtered revision. We now use
`repo,changelog.tip()` to fetch this information.

The `tip` command is also fixed and tested

Thanks goes to Idan Kamara for the initial report.
2013-01-22 11:39:14 +01:00
David Schleimer
1dc36ff74c commit: factor out post-commit cleanup into workingctx
This pulls some of the logic for the cleanup that needs to happen
after a commit has been made otu of localrepo.commit and into
workingctx.  This is part of a larger refactoring effort that will
eventually allow us to perform some types of merges in-memory.
2013-02-08 05:36:08 -08:00
Mads Kiilerich
5787baee50 spelling: fix some minor issues found by spell checker 2013-02-10 18:24:29 +01:00
Pierre-Yves David
6c68029a60 clfilter: stronger detection of filtered changeset in changectx.__init__
We previously let some IndexError spill out of this function.

A new tests is added to check the command that spotted the error.
2013-01-16 05:21:11 +01:00
Kevin Bullock
93f9cb7f25 filtering: rename filters to their antonyms
Now that changelog filtering is in place, it's become evident that
naming the filters according to the set of revs _not_ included in the
filtered changelog is confusing. This is especially evident in the
collaborative branch cache scheme.

This changes the names of the filters to reflect the revs that _are_
included:

  hidden -> visible
  unserved -> served
  mutable -> immutable
  impactable -> base

repoview.filteredrevs is renamed to filterrevs, so that callers read a
bit more sensibly, e.g.:

  filterrevs('visible') # filter revs according to what's visible
2013-01-13 01:39:16 -06:00
Mads Kiilerich
2d6545f8b6 subrepos: process subrepos in sorted order
Add sorted() in places found by testing with PYTHONHASHSEED=random and code
inspection.

An alternative to sprinkling sorted() all over would be to change substate to a
custom dict with sorted iterators...
2012-12-12 02:38:14 +01:00
Pierre-Yves David
b7230b8249 context: retrieve hidden from filteredrevs
This prepare the dropping of the repo.hiddenrevs property
2013-01-03 18:51:16 +01:00
Pierre-Yves David
704a17970c clfilter: fallback to unfiltered version when linkrev point to filtered history
On `filectx`, linkrev may point to any revision in the repository. When the
repository is filtered this may lead to `filectx` trying to build `changectx`
for filtered revision. In such case we fallback to creating `changectx` on the
unfiltered version of the reposition. This fallback should not be an issue
because `changectx` from `filectx` are not used in complex operation that
care about filtering. It is complicated to work around the issue in a
clearer way as code raising such `filectx` rarely have access to the
repository directly.

Linkrevs create a lot of issue with filtering. It is stored in revlog entry at
creation time and never changed. Nothing prevent the changeset revision pointed
to become filtered. Several bogus behavior emerge from such situation. Those
bugs are complex to solve and not part of the current effort to install
filtering. This changeset is simple hack that prevent plain crash in favor on
minor misbehavior without visible effect.

This "hack" is longly documented in to code itself to help people that would
look at it in the future.
2012-12-29 00:40:18 +01:00
Pierre-Yves David
0571efafd8 obsolete: introduce a troubles method on context
A troubled changeset may be affected by multiple trouble at the same time. This
new method returns a list of all troubles affecting a changes.
2012-12-17 15:17:54 +01:00
Pierre-Yves David
c1a745d834 obsolete: introduce a troubled method on context
Allows to quickly check if a changeset is affected by any troubles.
(troubles are: unstable, bumped and divergent)
2012-12-17 15:06:15 +01:00
Pierre-Yves David
985f5be6c5 clfilter: ensure context raise RepoLookupError when the revision is filtered
Currently the code path of `changectx(filteredrepo, rev)` call
`filteredrepo.changelog.node(rev)`. When `rev` is filtered this raise an
unhandled `IndexError`. This case now raise a `RepoLookupError` as other
error case do.
2012-12-17 18:09:41 +01:00
Pierre-Yves David
38afff41e0 obsolete: add a divergent method on context
The same we have `unstable` and `bumped`. Convenient method to access troubles
information in general may land later.

This get actual use and testing in the next changesets.
2012-12-12 03:20:49 +01:00