Commit Graph

1516 Commits

Author SHA1 Message Date
Augie Fackler
4e03270f68 localrepo: remove clone method by hoisting into hg.py
hg.py was the only remaining caller of localrepo.clone(), so it's time
to move some more behavior out of localrepo.
2015-11-11 19:47:49 -05:00
Gregory Szorc
b8f3c3b570 localrepo: improve docstring for revset methods
revs() doesn't return a list. Also document what its arguments do.

Also clarify that set() is just a convenience wrapper around revs().
2015-11-21 11:07:30 -08:00
Laurent Charignon
85b8e6613d localrepo: put bookmark move following commit in one transaction
Before this patch, making a commit on a local repo could move a bookmark and
both operations would not be grouped as one transaction. This patch makes both
operations part of one transaction. This is necessary to switch to the new api
to save bookmarks repo._bookmarks.recordchange if we don't want to change the
current behavior of rollback.

Dirstate change happening after the commit is done is now part of the
transaction mentioned above. This leads to a change in the expected output of
several tests.

The change to test-fncache happens because both lock are now released in the
same finally clause. The lock release is made explicitly buggy in this test.
Previously releasing lock would crash triggering release of wlock that crashes
too. Now lock release crash does not directly result in the release of wlock.
Instead wlock is released at garbage collection time and the error raised at
that time "confuses" python.
2015-11-18 01:36:58 -08:00
Siddharth Agarwal
b5cb4f4050 localrepo.commit: switch to mergestate.read()
See previous patches for why we're doing this.
2015-11-17 13:58:50 -08:00
Siddharth Agarwal
7e0e958b67 localrepo: switch to mergestate.clean()
See the previous patches for why we're doing this.
2015-11-17 17:04:32 -08:00
Pierre-Yves David
c8b7676e04 format: introduce 'format.usegeneraldelta`
This option will make repositories created as general delta by default but will
not make Mercurial aggressively recompute deltas for all incoming bundle.
Instead, the delta contained in the bundle will be used. This will allow us to
start having general delta repositories created everywhere without triggering
massive recomputation costs for all new clients cloning from old servers.
2015-11-02 15:59:12 +00:00
Pierre-Yves David
474dfeda7e scmutil: extract general delta config handling in a function
General delta is currently controlled by a single option, we will introduce a
new one in the next changeset.

We extract the logic in a function while it is simple.
2015-11-02 16:52:34 +00:00
FUJIWARA Katsunori
f850c84e84 localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.

    def __delete__(self, obj):
        try:
            del obj.__dict__[self.name]
        except KeyError:
            raise AttributeError(self.name)

If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.

Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:

  1. start a command execution

  2. 'changelog.delayupdate()' is invoked in a transaction scope

     This replaces own 'opener' by '_divertopener()' for additional
     accessing to '00changelog.i.a' (aka "pending file").

  3. transaction is aborted, and command (1) execution is ended

     After 'repo.invalidate()' at releasing store lock, changelog
     object above (= 'opener' of it is still replaced) is deleted from
     'repo.__dict__', but still kept in 'repo._filecache'.

  4. start next command execution with same 'repo'

  5. referring 'repo.changelog' may reuse changelog object kept in
     'repo._filecache' according to timestamp of '00changelog.i'

     '00changelog.i' is truncated at transaction failure (even though
     this truncation is unintentional one, as described later), and
     'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
     resolution to always detect this truncation, and invalid
     changelog object kept in 'repo._filecache' is reused
     occasionally.

     Then, "No such file or directory" error occurs for
     '00changelog.i.a', which is already removed at (3).

This patch discards objects in '_filecache' other than dirstate at
transaction failure.

Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'

'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.

This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.

  - "always discard objects in filecache at unlocking" may cause
    serious performance problem for subsequent procedures at normal
    execution

  - but it is impossible to "discard objects in filecache at unlocking
    only at failure", because 'releasefn' of lock can't know whether a
    lock scope is terminated normally or not

    BTW, using "with" statement described in PEP343 for lock may
    resolve this ?

After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.

Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.

This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 18:58:57 +09:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
Siddharth Agarwal
dedaa4b3f5 localrepo.commit: abort if merge driver's conclude step hasn't been run yet
This case also requires 'hg resolve --all' to be run before continuing.
2015-10-15 01:02:32 -07:00
FUJIWARA Katsunori
8f93d72f88 hook: centralize passing HG_PENDING to external hook process
This patch centralizes passing HG_PENDING to external hook process
into '_exthook()'. To make in-memory changes visible to external hook
process, this patch does:

  - write (or schedule to write) in-memory dirstate changes, and
  - set HG_PENDING environment variable, if:
    - a transaction is running, and
    - there are in-memory changes to be visible

This patch tests some commands with some hooks, because transaction
activity of a same hook differs from each other ("---": "not tested").

    ======== ========= ========= ============
    command  preupdate precommit pretxncommit
    ======== ========= ========= ============
    unshelve   o        ---       ---
    backout    x        ---       ---
    import     ---       o         o
    qrefresh   ---       x         o
    ======== ========= ========= ============

Each hooks are examined separately to prevent in-memory changes from
being visible to external process accidentally by side effect of hooks
previously invoked.
2015-10-17 01:15:34 +09:00
FUJIWARA Katsunori
106983607a dirstate: make dirstate.write() callers pass transaction object to it
Now, 'dirstate.write(tr)' delays writing in-memory changes out, if a
transaction is running.

This may cause treating this revision as "the first bad one" at
bisecting in some cases using external hook process inside transaction
scope, because some external hooks and editor process are still
invoked without HG_PENDING and pending changes aren't visible to them.

'dirstate.write()' callers below in localrepo.py explicitly use 'None'
as 'tr', because they can assume that no transaction is running:

  - just before starting transaction
  - at closing transaction, or
  - at unlocking wlock
2015-10-17 01:15:34 +09:00
Siddharth Agarwal
7164a1a80a localrepo.commit: disallow commit when driver-resolved files exist
This code will not currently be activated because there's no code to mark
files as driver-resolved in core. This point is also somewhat hard to plug into
from extensions.
2015-10-14 16:04:43 -07:00
Augie Fackler
a6bb3f0de9 localrepo: use cg?unpacker.apply() instead of changegroup.addchangegroup()
This is in localpeer, so it lives. Had it been in localrepo instead, I
would have tried to exterminate it.
2015-10-13 17:14:07 -04:00
FUJIWARA Katsunori
2ef2ab5d6d dirstate: make writing in-memory changes aware of transaction activity
This patch delays writing in-memory changes out, if transaction is
running.

'_getfsnow()' is defined as a function, to hook it easily for
ambiguous timestamp tests (see also fakedirstatewritetime.py)

'if tr:' code path in this patch is still disabled at this revision,
because there is no client invoking 'dirstate.write()' with repo
object.

BTW, this patch changes 'dirstate.invalidate()' semantics around
'dirstate.write()' in a transaction scope:

  before:
    with repo.transaction():
        dirstate.CHANGE('A')
        dirstate.write() # change for A is written out here
        dirstate.CHANGE('B')
        dirstate.invalidate() # discards only change for B

  after:
    with repo.transaction():
        dirstate.CHANGE('A')
        dirstate.write() # change for A is still kept in memory
        dirstate.CHANGE('B')
        dirstate.invalidate() # discards changes for A and B

Fortunately, there is no code path expecting the former, at least, in
Mercurial itself, because 'dirstateguard' was introduced to remove
such 'dirstate.invalidate()'.
2015-10-14 02:49:17 +09:00
FUJIWARA Katsunori
344e42ce00 localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").

After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.

    https://mercurial.selenic.com/wiki/DirstateTransactionPlan

Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g.  "hg update" to
another branch after "hg commit" or so, then "hg rollback").

To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".

  before:
    b1. restore dirstate explicitly, if "parent-gone"

  after:
    a1. save dirstate before actual rollbacking via dirstateguard
    a2. restore dirstate via 'transaction.rollback()'
    a3. if "parent-gone"
        - discard backup (a1)
        - restore dirstate from 'undo.dirstate'
    a4. otherwise, restore dirstate from backup (a1)

Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:

  - it isn't ensured that 'dirstate.write()' was invoked at least once
    while transaction running

    If not, '.hg/dirstate' isn't restored at (a2).

    In addition to it, rude 3rd party extension invoking
    'dirstate.write()' without 'repo' while transaction running (see
    subsequent patches for detail) may break consistency of a file
    backup-ed by transaction.

  - this patch mainly focuses on changes for DirstateTransactionPlan

    Restoring dirstate at (a3) itself should be cheaper enough than
    rollbacking itself. Redundancy will be removed in next step.

Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 12:25:43 -07:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
FUJIWARA Katsunori
45bfdb573e localrepo: execute appropriate actions for dirstate at releasing transaction
Before this patch, in-memory dirstate changes are still kept over a
transaction scope boundary regardless of the result of it.

For "all or nothing" policy of the transaction, in-memory dirstate
changes should be:

  - written out at successful closing a transaction, because
    subsequent 'dirstate.invalidate()' can lose them

  - discarded at failure of a transaction, because outer
    'wlock.release()' or so may write them out

To discard all changes in a transaction completely, this patch also
restores '.hg/dirstate' by '.hg/journal.dirstate' at failure, because
'transaction' itself does nothing for files related to '.hg/journal.*'
in such case (therefore, renaming in this patch is safe enough).

This is a part of preparations for "transactional dirstate". See also
the wiki page below for detail about it.

    https://mercurial.selenic.com/wiki/DirstateTransactionPlan

This patch also removes redundant 'dirstate.invalidate()' just before
aborting a transaction for shelve/unshelve.
2015-10-09 03:53:46 +09:00
Siddharth Agarwal
b91b05d624 localrepo: prevent wlock from being inherited when a transaction is running
Review feedback from Pierre-Yves David. A separate line of work is working to
ensure that dirstate writes are written to a separate 'pending' file while a
transaction is active. Lock inheritance currently conflicts with that, so dodge
the issue by simply preventing inheritance while a transaction is running.

Custom merge drivers aren't going to run inside a transaction, so this doesn't
affect that.
2015-10-06 13:19:05 -07:00
Siddharth Agarwal
faa305db27 localrepo: add a way to get the current wlock if it's held
This will be useful to pass around a reference to the lock to some functions
we're going to add to scmutil. We don't want those functions to live in
localrepo to avoid bloat.
2015-10-05 14:27:37 -07:00
Siddharth Agarwal
02ed78a388 localrepo: add a way to get the current lock if it's held
We'll use this in upcoming patches to return a reference to the wlock if it's
held.
2015-10-05 14:26:53 -07:00
Siddharth Agarwal
41ecc00849 localrepo: allow wlock to be inherited
This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.

When allowed, the parent process will pass down requisite information to the
child process by way of this environment variable.
2015-09-25 12:39:23 -07:00
Siddharth Agarwal
f2504bdbc2 localrepo: add a note about parentenvvar
Review feedback from Pierre-Yves David.
2015-10-04 19:28:43 -07:00
Gregory Szorc
13e503977f exchange: move stream clone logic into pull code path
Stream clones are a special case of clones. Clones are a special case of
pull. Most of the logic for deciding what to do at pull time is in
exchange.py. It makes sense for the stream clone determination to live
there as well.

This patch moves the calling of the stream clone code into pull(). The
checks in streamclone.canperformstreamclone() ensure that we don't
perform a stream clone unless it is possible.

A future patch will convert maybeperformstreamclone() to accept a
pullop to make it consistent with everything else in pull(). It will
also grow some functionality (in case you doubted the necessity of a 4
line function).
2015-10-02 23:04:52 -07:00
Gregory Szorc
7d658837f3 exchange: teach pull about requested stream clones
An upcoming patch will move the invocation of stream cloning logic to
the normal pull code path (from localrepository.clone). In preparation
for this, we teach pull() and pulloperation about whether a streaming
clone is requested.

The return logic in localrepository.clone() has been reformatted
slightly because of line length issues.
2015-10-02 22:16:34 -07:00
Gregory Szorc
db39558e0c streamclone: move streaming clone logic from localrepo
This is the last remnants of streaming clone code in localrepo.py.

This is a mostly mechanical transplant of code to a new file. Only a
rewrite of "self" to "repo" was performed. The code will be
significantly refactored in upcoming patches. So don't scrutinize it too
closely.
2015-10-02 21:39:04 -07:00
Gregory Szorc
e5b1fcee2d streamclone: move stream_in() from localrepo
Another basic content move. The underscore from the function name was
removed to comply with naming standards.
2015-10-02 15:58:24 -07:00
Gregory Szorc
afd8c0b560 streamclone: move applystreamclone() from localrepo.py
Upcoming patches will modernize the streaming clone code. Streaming
clone data and code kind of lives in its own world. exchange.py is
arguably the most appropriate existing location for it. However, over
a dozen patches from now it became apparent that there was a lot of code
related to streaming clones and that having it contained within its own
module would make it easier to comprehend. So, we establish
streamclone.py.

It's worth noting that streamclone.py existed a long time ago, last seen
in the 1.6 release. It was removed in 2cd3dd86758c.

The function was renamed as part of the move because its old name was
redundant with the new module name. The only other content change was
"self" was renamed to "repo" and minor grammar in the docstring was
updated.
2015-10-02 15:51:32 -07:00
Siddharth Agarwal
9dcb32964d localrepo: allow creating inherited locks
This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.
2015-09-25 12:28:12 -07:00
Matt Mackall
011d3e76a5 merge with stable 2015-09-29 14:33:31 -05:00
Yuya Nishihara
902720a104 localrepo: recreate phasecache if changelog was modified (issue4855)
Because _phaserevs and _phasesets cache revision numbers, they must be
invalidated if there are new commits or stripped revisions. We could do
that by calling _phasecache.invalidate(), but it wasn't simple to be
integrated with the filecache mechanism.

So for now, phasecache will be recreated after repo.invalidate() if
00changelog.i was modified before.
2015-09-29 21:57:08 +09:00
Yuya Nishihara
4ffbdfca20 localrepo: recreate phasecache if changelog was modified (issue4855)
Because _phaserevs and _phasesets cache revision numbers, they must be
invalidated if there are new commits or stripped revisions. We could do
that by calling _phasecache.invalidate(), but it wasn't simple to be
integrated with the filecache mechanism.

So for now, phasecache will be recreated after repo.invalidate() if
00changelog.i was modified before.
2015-09-29 21:57:08 +09:00
Pierre-Yves David
d40a9362d5 tag: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs. We
just added support of None for the underlying function, so nothing else the
required.
2015-09-24 00:56:30 -07:00
Pierre-Yves David
b866453be7 commit: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 00:56:18 -07:00
Siddharth Agarwal
0edaba580a lock: move acquirefn call to inside the lock
We're going to need to call it again as part of reinitialization after a
subprocess inherits the lock.
2015-09-22 14:09:42 -07:00
Siddharth Agarwal
f272abff39 localrepo: call lock.lock with releasefn as a keyword arg
We'll be adding an acquirefn argument soon, and this makes that clearer.
2015-09-22 13:25:41 -07:00
Yuya Nishihara
a3529f51c1 localrepo: refresh filecache stats only if transaction finished successfully
If commit is aborted by pretxncommit hook, in-memory changelog and manifest
have entries that would be added. So they must be discarded on invalidate().

But the mechanism introduced by 071f71da2fe2 doesn't handle this case well.
It tries to mitigate the penalty of invalidate() by marking in-memory cache
as "clean" on unlock assuming that they are identical to the stored data.
But this assumption is wrong if stored data are rolled back by tr.abort().

This patch moves the hook to post-close action so that it will never be
triggered on abort.

This bug was originally reported to thg, which is only reproducible in
command-server process on unix, evolve disabled.

https://bitbucket.org/tortoisehg/thg/issues/4285/
2015-09-15 00:32:39 +09:00
Yuya Nishihara
b265ea8243 localrepo: move closure of lock release to class
It only captures "self", so it isn't necessary to be created dynamically.
2015-09-15 21:00:28 +09:00
Siddharth Agarwal
6a6927662f localrepo: move dirstate validate function to class scope
This will allow the function to be referred to by subclasses, as required for
upcoming patches.
2015-09-02 22:05:23 -07:00
Durham Goode
be92ed2487 revlog: add an aggressivemergedelta option
This adds an option for delta'ing against both p1 and p2 when applying merge
revisions and picking whichever is smallest.

Some before and after stats on manifest.d size:

internal large repo:
before: 1.2 GB
after: 930 MB

mozilla-central:
before: 261 MB
after: 92 MB
2015-08-30 14:03:32 -07:00
FUJIWARA Katsunori
4865b28d1a localrepo: make journal.dirstate contain in-memory changes before transaction
Before this patch, in-memory dirstate changes aren't written out at
opening transaction, even though 'journal.dirstate' is created
directly from '.hg/dirstate'.

Therefore, subsequent 'hg rollback' uses incomplete 'undo.dirstate' to
restore dirstate, if dirstate is changed and isn't written out before
opening transaction.

In cases below, the condition "dirstate is changed and isn't written
out before opening transaction" isn't satisfied and this problem
doesn't appear:

  - "wlock scope" and "transaction scope" are almost equivalent

    e.g. 'commit --amend', 'import' and so on

  - dirstate changes are written out before opening transaction

    e.g. 'rebase' (via 'dirstateguard') and 'commit -A' (by separated
    wlock scopes)

On the other hand, 'backout' may satisfy the condition above.

To make 'journal.dirstate' contain in-memory changes before opening
transaction, this patch explicitly invokes 'dirstate.write()' in
'localrepository.transaction()'.

'dirstate.write()' is placed before not "writing journal files out"
but "invoking pretxnopen hooks" for visibility of dirstate changes to
external hook processes.

BTW, in the test script, 'touch -t 200001010000' and 'hg status' are
invoked to make file 'c' surely clean in dirstate, because "clean but
unsure" files indirectly cause 'dirstate.write()' at 'repo.status()'
in 'repo.commit()' (see e1d123a2ee1f for detail) and prevents from
certainly reproducing the issue.
2015-07-30 06:16:12 +09:00
Matt Mackall
1814d94dd8 bookmarks: mark internal-only option 2015-06-25 17:51:32 -05:00
Matt Mackall
d8dd457296 commit: mark internal-only option 2015-06-25 17:51:02 -05:00
Matt Mackall
6a4e277735 localrepo: mark format options 2015-06-25 17:50:27 -05:00
Yuya Nishihara
aa1f13c196 localrepo: provide workingctx by integer revision
This allows us to use the integer representation in revset. None doesn't
work well while computing revset because revset heavily depends on and
optimized for integer revisions.

Still repo[wdirrev].rev() is None, which means the canonical form of the
working-directory revision is None.

This patch doesn't add the case for the wdirid because we can't handle short
and ambiguous identifiers here. Perhaps, the wdirid will have to be handled
in the changelog layer.
2014-08-16 13:25:45 +09:00
Siddharth Agarwal
8a17b8b38b localrepo: kill off sopener (API)
sopener is deprecated since 12df7401e8cd (Mercurial 2.3). It's annoying for
extension authors to have to deal with both. Let's just kill it off.
2015-06-25 22:17:52 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Pierre-Yves David
40147b2819 devel-warn: move the develwarn function as a method of the ui object
We are going to use this feature in more and more place. Having to import
scmutil makes it an import cycle hell.
2015-06-19 11:19:45 -07:00
Matt Mackall
57fc0eca44 publishing: unconditionally trust publishing flag
Unfortunately, there are currently no tests for this behavior because
we lack a good way of testing trust.
2015-06-18 15:39:52 -05:00
Matt Mackall
e73d6537ab publishing: use new helper method 2015-06-18 15:34:22 -05:00