Commit Graph

675 Commits

Author SHA1 Message Date
Gregory Szorc
7fec603f86 sparse: refactor update actions filtering and call from core
merge.calculateupdates() now filters the update actions through sparse
by default.

The filtering no-ops if sparse isn't enabled or no sparse config
is defined.

The function has been refactored to behave more like a filter
instead of a wrapper of merge.calculateupdates().

We should arguably take sparse into account earlier in
merge.calculateupdates(). This patch preserves the old behavior
of applying sparse at the end of update calculation, which is the
simplest and safest approach.
2017-07-06 16:29:31 -07:00
Gregory Szorc
6dce563cd3 sparse: move pruning of temporary includes into core
This was our last method on the custom repo type, meaning we could
remove that custom type and inline the 2 lines of code into
reposetup().

As part of the move, instead of wrapping merge.update() from
the sparse extension, we inline the function call. The ported
function now no-ops if sparse isn't enabled, making it safe to
always call.

The call site in update() may not be the most appropriate. But
it matches the previous behavior, which is the safest thing
to do. It can be improved later.
2017-07-06 14:33:18 -07:00
Martin von Zweigbergk
1f47781cfe mergestate: implement unresolvedcount() in terms of unresolved()
This simplifies the method slightly. It does create a full list of
paths while doing so, but it's not a lot of data anyway (besides, I
would think references to strings are no larger than (references to?)
True).
2015-12-01 09:26:33 -08:00
Martin von Zweigbergk
490806f981 mergestate: make unresolved() use iteritems()
mergestate.unresolved() is a generator, so it seems better for it to
rely on iteritems() than items(), although it also seems unlikely for
it to make a noticeable difference.
2015-12-01 09:26:10 -08:00
Phil Cohen
a65f43e3e4 workingfilectx: add exists, lexists
Switch the lone call in merge.py to use it.

As with past refactors, the goal is to make wctx hot-swappable with an
in-memory context in the future. This change should be a no-op today.
2017-07-04 22:35:52 -07:00
Pierre-Yves David
ab57951fd7 obsutil: move 'foreground' to the new modules
We have a new 'obsutil' module now. We move the high level utility there to
bring 'obsolete.py' back to a more reasonable size.
2017-06-27 01:40:34 +02:00
Pulkit Goyal
35cedf7901 py3: use hex() to convert the hash to bytes 2017-06-26 17:20:46 +05:30
Phil Cohen
22861c5e86 workingfilectx: add audit() as a wrapper for wvfs.audit() 2017-06-25 22:30:14 -07:00
Phil Cohen
8b63d9e6f0 workingfilectx: add backgroundclose as a kwarg to write()
This is necessary because some callers in merge.py pass backgroundclose=True
when writing.

As with previous changes in this series, this should be a no-op.
2017-06-25 22:30:14 -07:00
Phil Cohen
67430178c3 merge: change repo.wvfs.setflags calls to a new wctx[f].setflags function
As with previous changes in this series, this should be a no-op.
2017-06-25 22:29:09 -07:00
Phil Cohen
522fc7d98c merge: convert repo.wwrite() calls to wctx[f].write()
As with the previous patch in this series, workingfilectx.write() is a direct
call to repo.wwrite(), so this change should be a no-op.
2017-06-25 17:00:15 -07:00
Phil Cohen
4a54f4253f merge: replace repo.wvfs.unlinkpath() with calls to wctx[f].remove()
The code inside workingfilectx.remove() is a straight call to
repo.wvfs.unlinkpath, so this should be a no-op.
2017-06-25 16:58:26 -07:00
Phil Cohen
c6b8b5e8d4 merge: pass wctx to batchremove and batchget
We would like to migrate direct calls of repo.wvfs/wwrite/wread/etc to a
call on the relevant workingfilectx, both as a cleanup (to reduce the number of
working copy functions on `repo`), and also to facilitate an in-memory merge
that doesn't write to the working copy.

In order to do that, the first step is to ensure we pass the target wctx around
and perform our writes and reads on it. Later, this object might become a
memctx.
2017-06-25 16:56:49 -07:00
Pulkit Goyal
de83c26a54 py3: replace dict.iterkeys() with iter(dict)
dict.iterkeys() does not exists on Python 3.
2017-06-16 01:46:47 +05:30
Yuya Nishihara
6194f1a680 merge: use scmutil.intrev() to sort ctx objects
This moves wctx to the last, but that shouldn't matter. Only the order of
stored revisions is important.
2017-06-03 19:01:19 +09:00
Pulkit Goyal
3708dfc09e py3: convert bool variables to bytes before passing into ui.debug()
We can't pass unicodes to ui.debug() and hence we need to convert things to
bytes before passing them.
2017-06-01 02:14:26 +05:30
Pulkit Goyal
4e870f314a py3: replace None with -1 to sort an integer array
In Python 2:

>>> ls = [4, 2, None]
>>> sorted(ls)
[None, 2, 4]

In Python 3:

>>> ls = [4, 2, None]
>>> sorted(ls)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()

Therefore we replaced None with -1, and the safe part is that, None and -1 are
only the keys which are used for sorting so we don't need to convert the -1's
back to None.
2017-05-31 23:48:52 +05:30
Martin von Zweigbergk
5e8aba2103 merge: use intersectmatchers() in "m2-vs-ma optimization"
It doesn't seem like this can actually happen, but seems like cleaner
anyway.
2017-05-12 16:33:33 -07:00
Augie Fackler
d3c24043bb merge: migrate to context manager for changing dirstate parents 2017-05-18 17:11:24 -04:00
Phil Cohen
f313a0b236 merge: use repo.wvfs.setflags() instead of util.setflags()
Most merge.py code goes through the vfs instead of maniulating
files directly, so let's do the same here.
2017-05-11 18:38:43 -07:00
Durham Goode
4f79467143 rebase: use matcher to optimize manifestmerge
The old merge code would call manifestmerge and calculate the complete diff
between the source to the destination. In many cases, like rebase, the vast
majority of differences between the source and destination are irrelevant
because they are differences between the destination and the common ancestor
only, and therefore don't affect the merge. Since most actions are 'keep', all
the effort to compute them is wasted.

Instead, let's compute the difference between the source and the common ancestor
and only perform the diff of those files against the merge destination. When
using treemanifest, this lets us avoid loading almost the entire tree when
rebasing from a very old ancestor. This speeds up rebase of an old stack of 27
commits by 20x.

In mozilla-central, without treemanifest, when rebasing a commit from
default~100000 to default, this speeds up the manifestmerge step from 2.6s to
1.2s.  However, the additional diff adds an overhead to all manifestmerge calls,
especially for flat manifests. When rebasing a commit from default~1 to default
it appears to add 100ms in mozilla-central. While we could put this optimization
behind a flag, I think the fact that it makes merge O(number of changes being
applied) instead of O(number of changes between X and Y) justifies it.
2017-05-03 10:43:59 -07:00
Jun Wu
f331a9612f merge: use ProgrammingError 2017-03-26 16:55:56 -07:00
Durham Goode
30b5b6d685 merge: remove unnecessary matcher checks
As part of changing manifest.diff to accept a matcher, a previous patch added
matcher calls to each location in merge.manifestmerge that tested if 'x in mf'
to maintain the same behavior as before. After analyzing it further, this
matcher call isn't needed, and in fact hurts future patches ability to use the
matcher here.

Basically, all these 'if x in mf' checks were checking if a matched file's copy
source was in the matcher as well. This meant if you passed a matcher for just
file foo, it would not return file bar even if foo was a copy of bar. Since
manifestmerge cares about copy information, let's allow all lookups of copy
sources.

We also update one spot with a 'is not None' check, since it wasn't obvious that
the value could sometimes be None before, which broke when we called
matcher(None).

A future patch adds matcher optimizations to manifestmerge which causes this
code path to get covered by existing tests.
2017-03-19 11:42:17 -07:00
Martin von Zweigbergk
31bb49fb7d merge: also allow 'e' action with experimental.updatecheck=noconflict
With experimental.updatecheck=noconflict set, if one checks out
e1870a31325e (tests: add execute bit and fix shbang line, 2015-12-22)
and then try to check out its parent, hg will complain about
conflicting changes, even though the working directory is clean. We
need to also allow the 'e' action in merge.py. The 'e' action is used
when moving to a commit where the only change to the file is to its
executable flag, so it's just an optimized 'g' action.

Doesn't seem to be worth writing a test for, since the existing setup
in test-update-branches.t does not set any flags.
2017-03-13 21:58:43 -07:00
Mads Kiilerich
ea3cfbc6fb merge: check current wc branch for 'nothing to merge', not its p1
The working directory will usually be clean or very clean, and wc will usually
have the same branch as its parent. This change will thus usually not make any
difference and is done as a separate change to show that. It will be used in a
later change.
2017-03-12 16:41:46 -07:00
Pierre-Yves David
98f81e8c4f merge: directly use repo.vfs.join
The 'repo.join' method is about to be deprecated.
2017-03-08 16:53:32 -08:00
Mads Kiilerich
01ac38526d merge: use repo.wvfs.unlinkpath 2015-01-14 01:15:26 +01:00
Mads Kiilerich
a936a7f3a7 vfs: use repo.wvfs.unlinkpath 2015-01-14 01:15:26 +01:00
Durham Goode
5d0340324a merge: remove uses of manifest.matches
This gets rid of the manifest.matches calls in merge.py in favor of the new api.
This is part of getting rid of manifest.matches since it is O(manifest).
2017-03-07 18:38:20 -08:00
Martin von Zweigbergk
4ad88a61e0 update: for "noconflict" updates, print "conflicting changes" on conflict
With experimental.updatecheck=noconflict, if the update is aborted
because of conlicts, "uncommitted changes" is not quite
accurate. Let's use "conflicting changes" instead. Also fix the hint
to recomment --clean, not --merge, since that's what we do for other
failed updates.
2017-03-06 23:21:27 -08:00
Martin von Zweigbergk
066bf0dbb3 update: allow setting default update check to "noconflict"
The new value allows update (linear or not) as long as they don't
result in file merges.

I'm hoping that this value can some day become the default.
2017-02-13 00:05:55 -08:00
Martin von Zweigbergk
5b3eb48725 update: accept --merge to allow merging across topo branches (issue5125) 2017-02-13 12:58:37 -08:00
Martin von Zweigbergk
4904a44779 merge: combine the "merge" cases in docstring table 2017-02-27 15:09:19 -08:00
Martin von Zweigbergk
dbab66ea10 merge: combine "dirty" cases in docstring table 2017-02-27 15:07:01 -08:00
Martin von Zweigbergk
f2dcab33cd merge: clarify non-linear default updates in docstring table
Non-linear updates won't happen by default, regardless of -c/-C.
2017-02-27 15:29:34 -08:00
Martin von Zweigbergk
2230022a53 merge: combine the two "can't happen" cases in docstring table 2017-02-27 15:02:36 -08:00
Martin von Zweigbergk
2b1e4cc1c6 merge: move "incompatible options" case first in docstring table 2017-02-27 15:00:13 -08:00
Martin von Zweigbergk
a3d141c00e merge: make "linear" an input in docstring table
Instead of having two ouputs, it seem simpler to have an addition
input. This will allow further simplification.
2017-02-27 14:58:53 -08:00
Martin von Zweigbergk
1d7591a0e3 merge: drop redundant column in docstring table
The "same" and "cross" columns now have the same values, so let's
combine them into "non-linear".
2017-02-27 14:33:17 -08:00
Martin von Zweigbergk
7fa2f6b954 merge: drop obsolete non-linear cases from docstring table
Since 5a430b57b16e (update: change default destination to tipmost
descendant (issue4673) (BC), 2016-02-02), non-linear updates can no
longer happen if the user doesn't specify a destination, so we can
drop these case from the table in the docstring of merge.update().
2017-02-27 14:27:22 -08:00
Martin von Zweigbergk
7e61f1a33b destutil: remove duplicate check and leave it to merge.update()
The check is done in merge.update() already and the next few patches
will add more checks there. Some of the additional checks will need
information about the merge that will not be available in destutil.

Since commands.postincoming() catches UpdateAbort(), we need to change
merge.update() to raise that more specific exception.

This goes directly again c6bcc960108f (destupdate: move the check
related to the "clean" logic in the function, 2015-10-05), but it will
simplify the next few patches, and we can always move it out again
(preferably move, not copy) after if we still think it's better that
way.
2017-02-09 09:52:32 -08:00
Martin von Zweigbergk
38e7618603 update: fix typo/stale comment to match code
The comment about "obsolete.background" seems to have been about
obsolete.foreground ever since it was introduced in fbdfa64ceced
(update: allow dirty update to foreground (successors), 2013-04-16),
so let's change it.
2017-02-09 09:55:31 -08:00
Martin von Zweigbergk
04e8402860 merge: remove unused handling of default destination in merge.update()
As far as I can tell, all the callers of merge.update() have been
migrated over to use destutil to find the default destination when the
revision was not specified. So it's time to delete the code for
handling a node value of None. Let's add an assertion that node is not
None, so any extensions relying on it will not silently misbehave.
2017-02-08 23:03:33 -08:00
Martin von Zweigbergk
25855165d1 update: localize logic around which ancestor to use
The merge code works by applying the changes between an ancestor and
the working copy onto the destination. To achieve an update, it sets
the ancestor to be the parent of the working copy. To achieve a clean
update (update -C), it sets the ancestor to be the working copy itself
(so there are no changes to carry over). The logic for this was spread
out a bit. Let's move it all to one place so it's easier to follow the
reason for it. Also add some documentation.
2017-02-08 14:49:37 -08:00
Mads Kiilerich
6945cf0f5b merge: more safe detection of criss cross merge conflict between dm and r
0b5f1f2efc77 introduced handling of a crash in this case. A review comment
suggested that it was not entirely obvious that a 'dm' always would have a 'r'
for the source file.

To mitigate that risk, make the code more conservative and make less
assumptions.
2017-02-01 02:10:30 +01:00
Mads Kiilerich
120b66d101 merge: fix crash on criss cross merge with dir move and delete (issue5020)
Work around that 'dm' in the data model only can have one operation for the
target file, but still can have multiple and conflicting operations on the
source file where the other operation is a 'rm'. The move would thus fail with
'abort: No such file or directory'.

In this case it is "obvious" that the file should be removed, either before or
after moving it. We thus keep the 'rm' of the source file but drop the 'dm'.

This is not a pretty fix but quite "obviously" safe (famous last words...) as
it only touches a rare code path that used to crash. It is possible that it
would be better to swap the files for 'dm' as suggested on
https://bz.mercurial-scm.org/show_bug.cgi?id=5020#c13 but it is not entirely
obvious that it not just would create conflicts on the other file. That can be
revisited later.
2017-01-31 03:25:59 +01:00
Gábor Stefanik
b631d16eab graft: support grafting changes to new file in renamed directory (issue5436) 2016-12-05 17:40:01 +01:00
Pulkit Goyal
97f340e354 py3: use pycompat.getcwd() instead of os.getcwd()
We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.
2016-11-23 00:03:11 +05:30
Augie Fackler
a9f44c7fb0 mergemod: drop support for merge.update without a target
This was to be deleted after 3.9.
2016-11-21 21:52:19 -05:00
Durham Goode
9fc9a7cf64 merge: change modified indicator to be 20 bytes
Previously we indicated that the .hgsubstate file was dirty by adding a '+' to
the end of its hash in the wctx manifest. This made is complicated to have new
manifest implementations that rely on the node length being fixed.

In previous patches we added added and modified node placeholders, so let's use
those to indicate dirty here as well. It doesn't look like anything ever
depended on this '+' (aside from it being different to the parent), so nothing
else needed to change here.
2016-11-10 02:21:15 -08:00