Commit Graph

646 Commits

Author SHA1 Message Date
Durham Goode
4834302703 merge: add file ancestor linknode to mergestate
During a merge, each file has a current commitnode+filenode, an other
commitnode+filenode, and an ancestor commitnode+filenode. The ancestor
commitnode is not stored though, and we rely on the ability for the filectx() to
look up the commitnode by using the filenode's linkrev. In alternative backends
(like remotefilelog), linkrevs may have restriction that prevent arbitrary
linkrev look up given a filenode.

This patch accounts for that by storing the ancestor commitnode in
the merge state so that it is available later at resolve time.

This results in some test changes because the ancestor commitnode we're using at
resolve time changes slightly. Before, we used the linkrev commit, which is the
earliest commit that introduced that particular filenode (which may not be the
latest common ancestor of the commits being merged). Now we use the latest
common ancestor of the merged commits as the commitnode. This is fine though,
because that commit contains the same filenode as the linkrev'd commit.
2016-02-05 10:22:14 -08:00
Durham Goode
791a4231ef merge: add state extras merge state data
In future commits we will want to store more data related to each file in the
merge state. This patch adds an optional record for storing a dictionary of
extras for each file.
2016-02-05 10:15:28 -08:00
Siddharth Agarwal
bfbbb007c7 merge: don't try to merge subrepos twice (issue4988)
In my patch series ending with rev c3f2eede6938 I switched most change/delete
conflicts to be handled at the resolve layer. .hgsubstate was the one file that
we weren't able to handle, so we kept the old code path around for it.

The old code path added .hgsubstate to one of the other lists as the user
specifies, including possibly the 'g' list.

Now since we did this check after converting the actions from being keyed by
file to being keyed by action type, there was nothing that actually removed
.hgsubstate from the 'cd' or 'dc' lists. This meant that the file would
eventually make its way into the 'mergeactions' list, now freshly augmented
with 'cd' and 'dc' actions.

We call subrepo.submerge for both 'g' actions and merge actions.

This means that if the resolution to an .hgsubstate change/delete conflict was
to add it to the 'g' list, subrepo.submerge would be called twice. It turns out
that this doesn't cause any adverse effects on Linux due to caching, but
apparently breaks on other operating systems including Windows.

The fix here moves this to before we convert the actions over. This ensures
that it .hgsubstate doesn't make its way into multiple lists.

The real fix here is going to be:
(1) move .hgsubstate conflict resolution into the resolve layer, and
(2) use a real data structure for the actions rather than shuffling data around
    between lists and dictionaries: we need a hash (or prefix-based) index by
    file and a list index by action type.

There's a very tiny behavior change here: collision detection on
case-insensitive systems will happen after this is resolved, not before. I think
this is the right change -- .hgsubstate could theoretically collide with other
files -- but in any case it makes no practical difference.

Thanks to Yuya Nishihara for investigating this.
2016-01-29 14:19:29 -08:00
Bryan O'Sullivan
ff05835c28 with: use context manager in merge update 2016-01-15 13:14:49 -08:00
Siddharth Agarwal
46071bce0e merge: split up checks for unknown and ignored files that differ
In some real-world cases it is preferable to allow overwriting ignored files
while continuing to abort on unknown files. This primarily happens when we're
replacing build artifacts (which are ignored) with checked in files, but
continuing to abort on differing files that aren't ignored.

We're redefining merge.checkunknown to only control the behavior for files
that aren't ignored. That's fine because this config was only very recently
introduced and has not made its way into any Mercurial releases yet.
2016-01-12 18:38:49 -08:00
Siddharth Agarwal
0914e3c659 merge: determine what untracked conflicts cause warns and aborts separately
This is written in a somewhat weird style, but it's designed for code reuse in
an upcoming patch.
2016-01-12 18:17:07 -08:00
Siddharth Agarwal
03971ff0e5 merge: factor out code to get checkunknown config
We're going to reuse this code shortly.
2016-01-12 18:12:35 -08:00
Siddharth Agarwal
093e742c00 merge: add options to warn or ignore on colliding unknown files
A 'colliding unknown file' is a file that meets all of the following
conditions:

- is untracked or ignored on disk
- is present in the changeset being merged or updated to
- has different contents

Previously, we would always abort whenever we saw such files. With this config
option we can choose to warn and back the unknown files up instead, or even
forgo the warning entirely and silently back the unknown files up.

Common use cases for this configuration include a large scale transition of
formerly ignored unknown files to tracked files. In some cases the files can be
given new names, but in other cases, external "convention over configuration"
constraints have determined that the file must retain the same name as before.
2016-01-02 03:11:52 -08:00
Siddharth Agarwal
027b946b48 batchget: add support for backing up files
We're going to use this in an upcoming feature.
2016-01-02 03:21:01 -08:00
Siddharth Agarwal
2584b69484 merge: add a new 'backup' argument to get actions
We're going to use this in an upcoming patch to back untracked files up when
they're replaced by tracked ones.
2016-01-02 03:02:57 -08:00
Siddharth Agarwal
54dd91b4db _checkunknownfiles: turn 'conflicts' into a set
We'll check for membership in this set in an upcoming patch.
2016-01-02 03:02:57 -08:00
Siddharth Agarwal
3e662143bb checkunknownfiles: make control flow clearer
In particular, make it clear that we only check for and abort on conflicts if
force is not true.
2016-01-02 03:02:57 -08:00
Siddharth Agarwal
6ff835640d _checkunknownfiles: rename 'aborts' to 'conflicts'
In upcoming patches we'll be able to do more useful things than aborting.
2016-01-02 03:02:57 -08:00
Matt Mackall
d7ec07e23e merge with stable 2016-01-02 02:13:56 +01:00
Siddharth Agarwal
a6934b01c3 merge: while checking for unknown files don't follow symlinks (issue5027)
Previously, we were using Python's native 'os.path.isfile' method which follows
symlinks. In this case, since we're operating on repo contents, we don't want
to follow symlinks.

There's a behaviour change here, as shown by the second part of the added test.
Consider a symlink 'f' pointing to a file containing 'abc'. If we try and
replace it with a file with contents 'abc', previously we would have let it
though. Now we don't. Although this breaks naive inspection with tools like
'cat' and 'diff', on balance I believe this is the right change.
2015-12-28 22:51:37 -08:00
Augie Fackler
1b827711c9 manifestmerge: have manifest do matching before diffing
This means that the diff code does less work, potentially
significantly less in the case of treemanifests. It also should ease
implementation with narrowed clone cases (such as narrowhg) when we
don't always have the entire set of treemanifest revlogs locally.

As far as I can tell, this codepath is currently only used by record,
so it'll probably die in the near future, and then narrowhg won't have
to worry about composing with some unknown matching system.
2015-12-14 20:57:21 -05:00
Augie Fackler
86f88ad861 merge: improve clarity of table in update docstring 2015-10-23 06:06:22 -04:00
Siddharth Agarwal
307771ef0d merge.applyupdates: call driverconclude after performing merge actions
This will be a chance for the merge driver to finish resolving or generating
any driver-resolved files.

As before, having a separate error state from 'unresolved' is too big a
refactoring for now, so we hack around it by setting unresolved to a positive
value when necessary.
2015-10-15 01:22:01 -07:00
Siddharth Agarwal
671581b397 merge.applyupdates: call driverpreprocess before starting merge actions
We also need to update our internal state to whatever state driverpreprocess
leaves it in.

Adding an error state separate from the unresolved count is too big a
refactoring for now, so we hack around it by setting it to a positive value to
indicate an error state.
2015-10-15 01:19:10 -07:00
Siddharth Agarwal
93aaae5f6a merge: add stubs for preprocess and conclude steps of merge driver
The exact semantics for what should happen (particularly with respect to error
handling) are still a bit hard to pin down, so I think it's better to
experiment with it as an extension for now. For now this stub will act as a
convenient point for extensions to hook on.
2015-10-15 01:17:29 -07:00
Siddharth Agarwal
fe759d6960 merge.mergestate: set merge driver state to 's' if there's none present
This allows mergestate.mdstate() to return 's' if there's nothing to be done on
the merge driver end.
2015-10-15 01:06:29 -07:00
Siddharth Agarwal
793db02056 merge.mergestate: only check for merge driver when property is accessed
Otherwise 'hg update --clean', 'hg rebase --abort' etc wouldn't work.
2015-10-15 01:04:46 -07:00
Siddharth Agarwal
f4dc777bce merge.mergestate: add a way to get the merge driver state
This will be useful to check what the status of the merge driver is.
2015-10-15 00:57:56 -07:00
Siddharth Agarwal
0eb994cb79 merge.mergestate: add a way to get the other side of the merge
It's surprising there was no API at all for this until now. In any case this
will be needed from custom merge drivers.
2015-10-15 00:49:07 -07:00
FUJIWARA Katsunori
75f4bab4a5 merge: make in-memory changes visible to external update hooks
c67339617276 (while 3.4 code-freeze) made all 'update' hooks run after
releasing wlock for visibility of in-memory dirstate changes. But this
breaks paired invocation of 'preupdate' and 'update' hooks.

For example, 'hg backout --merge' for TARGET revision, which isn't
parent of CURRENT, consists of steps below:

  1. update from CURRENT to TARGET
  2. commit BACKOUT revision, which backs TARGET out
  3. update from BACKOUT to CURRENT
  4. merge TARGET into CURRENT

Then, we expects hooks to run in the order below:

  - 'preupdate' on CURRENT for (1)
  - 'update'    on TARGET  for (1)
  - 'preupdate' on BACKOUT for (3)
  - 'update'    on CURRENT for (3)
  - 'preupdate' on TARGET  for (4)
  - 'update'    on CURRENT/TARGET for (4)

But hooks actually run in the order below:

  - 'preupdate' on CURRENT for (1)
  - 'preupdate' on BACKOUT for (3)
  - 'preupdate' on TARGET  for (4)
  - 'update'    on TARGET  for (1), but actually on CURRENT/TARGET
  - 'update'    on CURRENT for (3), but actually on CURRENT/TARGET
  - 'update'    on CURRENT for (4), but actually on CURRENT/TARGET

Root cause of the issue focused by c67339617276 is that external
'update' hook process can't view in-memory changes (especially, of
dirstate), because they aren't written out until the end of
transaction (or wlock).

Now, hooks can be invoked just after updating, because previous
patches made in-memory changes visible to external process.

This patch may break backward compatibility from the point of view of
"scheduling hook execution", but should be reasonable because 'update'
hooks had been executed in this order before 3.4.

This patch tests "hg backout" and "hg unshelve", because the former
activates the transaction before 'update' hook invocation, but the
former doesn't.
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
e65ca7df8c merge.mergestate: add a generator for driver-resolved files
Just like for unresolved files above, we need to be able to tell what files are
driver-resolved.
2015-10-14 15:01:07 -07:00
Augie Fackler
b184da51f2 merge: rework manifestmerge to use a matcher
This opens the door to working slightly more closely with the manifest
type and letting it optimize out some of the diff comparisons for us,
and also makes life significantly easier for narrowhg.
2015-12-14 20:47:22 -05:00
Augie Fackler
a84cc516e7 merge: restate calculateupdates in terms of a matcher
Once we get a matcher down into manifestmerge, we can make narrowhg
work more easily and potentially let manifest.match().diff() do less
work in manifestmerge.
2015-12-14 20:37:41 -05:00
Augie Fackler
0a19647501 merge: have merge.update use a matcher instead of partial fn
This is relatively rarely used functionality, but migrating this to a
matcher will make future work on narrow clones more feasible.
2015-12-14 18:54:03 -05:00
Martin von Zweigbergk
8e7f0fdda8 merge: refuse update/merge if there are unresolved conflicts (BC)
We currently allow updating and merging (with --force) when there are
unresolved merge conflicts, as long as there is only one parent of the
working copy. Even worse, when updating to another revision
(linearly), if one of the unresolved files (including any conflict
markers in the working copy) can now be merged cleanly with the target
revision, the file becomes marked as resolved.

While we could potentially allow updates that affect only files that
are not in the set of unresolved files, that's considerably more work,
and we don't have a use case for it anyway. Instead, let's keep it
simple and refuse any merge or update (without -C) when there are
unresolved conflicts.

Note that test-merge-local.t explicitly checks for conflict markers
that get carried over on update. It's unclear if that was intentional
or not, but it seems bad enough that we should forbid it. The simplest
way of fixing the test case is to leave the conflict markers in place
and just mark the files resolved, so let's just do that for now.
2015-12-07 20:43:24 -08:00
Andrew Halberstadt
f18899ffa6 merge.graft: add option to keep second parent
Currently merge.graft re-writes the dirstate so only a single
parent is kept. For some cases, like evolving a merge commit,
this behaviour is not desired. More specifically, this is
needed to fix issue4389.
2015-12-03 23:01:59 -05:00
Siddharth Agarwal
106338a190 merge: move almost all change/delete conflicts to resolve phase (BC) (API)
We have finally laid all the groundwork to make this happen.

The only change/delete conflicts that haven't been moved are .hgsubstate
conflicts. Those are trickier to deal with and well outside the scope of this
series.

We add comprehensive testing not just for the initial selections but also for
re-resolves and all possible dirstate transitions caused by merge tools. That
testing managed to shake out several bugs in the way we were handling dirstate
transitions.

The other test changes are because we now treat change/delete conflicts as
proper merges, and increment the 'merged' counter rather than the 'updated'
counter. I believe this is the right approach here.

For third-party extensions, if they're interacting with filemerge code they
might have to deal with an absentfilectx rather than a regular filectx.

Still to come:
- add a 'leave unresolved' option to merges
- change the default for non-interactive change/delete conflicts to be 'leave
  unresolved'
- add debug output to go alongside debug outputs for binary and symlink file
  merges
2015-11-25 14:25:33 -08:00
Siddharth Agarwal
ed64d46a37 merge.recordupdates: mark 'a' files as added unconditionally
See the previous patch for why we do this.
2015-11-24 15:26:51 -08:00
Siddharth Agarwal
3a27c524dc merge: add a new action type representing files to add/mark as modified
This is somewhat different from the currently existing 'a' action, for the
following case:

- dirty working copy, with file 'fa' added and 'fm' modified
- hg merge --force with a rev that neither has 'fa' nor 'fm'
- for the change/delete conflicts we pick 'changed' for both 'fa' and 'fm'.

In this case 'branchmerge' is true, but we need to distinguish between 'fa',
which should ultimately be marked added, and 'fm', which should be marked
modified.

Our current strategy is to just not touch the dirstate at all. That works for
now, but won't work once we move change/delete conflicts to the resolve phase.
In that case we may perform repeated re-resolves, some of which might mark the
file removed or remove the file from the dirstate. We'll need to re-add the
file to the dirstate, and we need to be able to figure out whether we mark the
file added or modified. That is what the new 'am' action lets us do.
2015-11-30 10:19:39 -08:00
Siddharth Agarwal
ae700a3344 mergestate: add a cached property accessor for the local context
This is going to be useful in an upcoming patch. We make this a public accessor
because this is also going to be useful for custom merge drivers.
2015-11-30 10:03:21 -08:00
Siddharth Agarwal
71a05a4daf mergestate: raise exception if otherctx is accessed but _other isn't set
We don't want to inadvertently return the workingctx (self._repo[None]).
2015-11-30 10:05:09 -08:00
Siddharth Agarwal
c40efd7aa0 mergestate: explicitly forget 'dc' conflicts where the deleted side is picked
Once we move change/delete conflicts into the resolve phase, a 'dc' file might
first be resolved by picking the other side, then later be resolved by picking
the local side. For this transition we want to make sure that the file goes
back to not being in the dirstate.

This has no impact on conflicts during the initial merge.
2015-11-23 18:03:25 -08:00
Siddharth Agarwal
c655a316e8 merge.applyupdates: add all actions returned from merge state
At the moment this is a no-op (the only actions defined are 'r', 'a' and 'g'),
but soon we're going to add other sorts of actions to the dictionary returned
from mergestate.actions().
2015-11-23 19:06:15 -08:00
Siddharth Agarwal
06ed2cbe50 merge.applyupdates: create absentfilectxes for change/delete conflicts
At the moment no change/delete conflicts get to this point -- we're going to
make that happen in an upcoming patch.
2015-11-22 21:58:28 -08:00
Siddharth Agarwal
5b40330cf9 mergestate: add methods to queue files to remove, add or get
These are meant for use by custom merge drivers that might want to modify the
dirstate. Dirstate internal consistency rules require that all removes happen
before any adds -- this means that custom merge drivers shouldn't be modifying
the dirstate directly.
2015-11-22 21:59:52 -08:00
Siddharth Agarwal
be9444426c mergestate: add a way to record pending dirstate actions
We're going to use this in resolve in the next patch.
2015-11-20 16:55:01 -08:00
Siddharth Agarwal
76ecd9e872 merge.recordupdates: don't require action keys to be present in dict
We're going to use this function for a much smaller set of actions in the next
patch. It's easier to do this than to backfill the dict we pass in.
2015-11-15 21:55:46 -08:00
Siddharth Agarwal
d2620ef53f merge.applyupdates: extend action queues with ones returned from mergestate
These queues will always be empty at the moment -- we're going to fill them up
in upcoming patches.
2015-11-20 11:26:31 -08:00
Siddharth Agarwal
1e4024e0f1 mergestate: add a method to compute actions to perform on dirstate
We're going to use this to extend the action lists in merge.applyupdates.

The somewhat funky return value is to make passing this dict directly into
recordactions easier. We're going to exploit that in an upcoming patch.
2015-11-20 16:43:25 -08:00
Siddharth Agarwal
b86e19fd45 merge.applyupdates: use counters from mergestate
This eliminates a whole bunch of duplicate code and allows us to update the
removed count for change/delete conflicts where the delete action was chosen.
2015-11-20 16:37:39 -08:00
Siddharth Agarwal
f919bd4f7b mergestate: add a function to return the number of unresolved files
Note that unlike the other functions, this is based on the persistent
mergestate.
2015-11-20 16:18:51 -08:00
Siddharth Agarwal
8dd9d0304c mergestate: add a method to return updated/merged/removed counts
This will not only allow us to remove a bunch of duplicate code in applyupdates
in an upcoming patch, it will also allow the resolve interface to be a lot
simpler: it doesn't need to return the dirstate action to applyupdates.
2015-11-20 16:17:54 -08:00
Siddharth Agarwal
dd58f25087 mergestate._resolve: don't return the action any more
This is a partial backout of an earlier diff -- now that we're storing the
results in a dict, we don't actually need this any more.
2015-11-20 16:32:47 -08:00
Siddharth Agarwal
aaac3ed514 mergestate._resolve: store return code and action for each file
We're going to need this to compute (a) updated/merged/unresolved counts, and
(b) actions to perform on the dirstate.
2015-11-20 16:08:22 -08:00
Siddharth Agarwal
5d6cb7e78f mergestate.add: store absentfilectxes as nullhex
This is the most natural way to represent these files. We also need to make
sure we don't try to store these files in the merge store.
2015-11-14 00:07:11 -08:00
Siddharth Agarwal
328287680c mergestate._resolve: handle change/delete conflicts
We will represent a deleted file as 'nullhex' in the in-memory and on-disk
merge states. We need to be able to create absentfilectxes in that case, and
delete the file from disk rather than try to write it out.
2015-11-20 01:14:15 -08:00
Siddharth Agarwal
f5fc173bec merge.mergestate: compute dirstate action
In upcoming patches we're going to queue these actions up to be applied to the
dirstate at the end.
2015-11-19 10:50:02 -08:00
Siddharth Agarwal
4904ded295 filemerge: return whether the file was deleted
This is required for change/delete conflict resolution -- see previous patches
for more details.
2015-11-18 14:22:52 -08:00
Siddharth Agarwal
c5b488f2d2 mergestate: allow storing and retrieving change/delete conflicts
We introduce a new record type, 'C', to indicate change/delete conflicts. This
is a separate record type because older versions of Mercurial will not be able
to handle these conflicts.

We aren't actually storing any change/delete conflicts yet -- that will come in
future patches.
2015-11-18 15:46:45 -08:00
Siddharth Agarwal
4a78a436f9 mergestate: handle additional record types specially
This works around a bug in older Mercurial versions' handling of the v2 merge
state.

We also add a bunch of tests that make sure that
(1) we correctly abort when the merge state has an unsupported record type
(2) aborting the merge, rebase or histedit continues to work and clears out the
    merge state.
2015-11-18 15:46:45 -08:00
Siddharth Agarwal
a19a04c7f9 mergestate: move binary format documentation into _readrecordsv2
This is too low-level to be the top-level documentation for mergestate. We're
restricting the top-level documentation to only be about what consumers of the
mergestate and anyone extending it need to care about.
2015-11-18 16:39:30 -08:00
Siddharth Agarwal
0d7932e904 mergestate.commit: factor out making the list of records
Will aid in testing.
2015-11-17 14:23:26 -08:00
Siddharth Agarwal
9f1990c72b mergestate: move _read() call to read constructor
With this patch, mergestate.clean() will no longer abort when it encounters an
unsupported merge type. However we hold off on testing it until backwards
compatibility is in place.
2015-11-17 14:04:56 -08:00
Siddharth Agarwal
99a292eb8d mergestate: add a constructor that reads state from disk
At the moment it's the same as just creating a new mergestate, but we'll soon
move the _read call out of __init__ and in here.
2015-11-17 13:55:30 -08:00
Siddharth Agarwal
866f1a0d13 merge.applyupdates: switch to mergestate.clean()
See the previous patches for why we're doing this.
2015-11-17 17:04:53 -08:00
Siddharth Agarwal
7f86d75731 mergestate: add a constructor that sets up a clean merge state
Eventually, we'll move the read call out of the constructor. This will:
- avoid unnecessary reads when we're going to nuke the merge state anyway
- avoid raising an exception if there's an unsupported merge record

'clean' seems like a good name for it because I wanted to avoid anything with
the word 'new' in it, and 'reset' is more an action performed on a merge state
than a way to get a new merge state.

Thanks to Martin von Zweigbergk for feedback about naming this.
2015-11-17 17:00:54 -08:00
Siddharth Agarwal
a9244bf2d6 mergestate: raise structured exception for unsupported merge records
We're going to catch this exception in 'hg summary' to print a better error
message.

This code is pretty untested, so there are no changes to test output. In
upcoming patches we're going to test the output more thoroughly.
2015-11-17 14:11:52 -08:00
Siddharth Agarwal
c6faeb67e1 merge.applyupdates: don't return early if merge driver's conclude failed
Somewhat silly oversight -- this prevented the progress bar from being reset.
2015-11-15 22:45:20 -08:00
Pierre-Yves David
3ca3ce920a update: "deprecate" call to 'merge.update' without a destination
Now that all internal callers pre-compute and set a destination at a higher level
it feels like we can kill this API. This will allow us to simplify this
function. However I feel like this is a bit too central and critical to break
now. I'm adding a devel warning to let extension make catch this in the next
cycle.
2015-10-05 21:42:09 -07:00
Mads Kiilerich
b919454f81 merge: abort on file/directory case folding collisions (issue4892)
File/directory case folding collisions cannot be represented on case folding
systems and have to fail.

To detect this and abort early, utilize that for file/directory collisions, a
sorted list of case folded manifest names will have the colliding directory
right after the file.

(This could perhaps be optimized, but this way of doing it also has
directory/directory case folding in mind ... which however not is handled yet.)
2015-10-13 00:16:25 +02:00
Siddharth Agarwal
3b737ce486 merge.mergedriver: don't try resolving files marked driver-resolved
The driver is expected to take care of these.
2015-09-30 19:43:51 -07:00
Siddharth Agarwal
7cd68f9b50 merge.mergestate: add support for persisting driver-resolved files
A driver-resolved file is a file that's handled specially by the driver. A
common use case for this state would be autogenerated files, the generation of
which should happen only after all source conflicts are resolved.

This is done with an uppercase letter because older versions of Mercurial will
not know how to treat such files at all.
2015-09-28 18:34:06 -07:00
Siddharth Agarwal
5d14dbc5df merge.mergestate: add support for persisting a custom merge driver
A 'merge driver' is a coordinator for the overall merge process. It will be
able to control:

- tools for individual files, much like the merge-patterns configuration does
  today
- tools that can work across groups of files
- the ordering of file resolution
- resolution of automatically generated files
- adding and removing additional files to and from the dirstate

Since it is a critical part of the merge process, it really is part of the
merge state.

This is a lowercase character (i.e. optional) because ignoring this is fine for
older versions of Mercurial -- however, if there are any files that are
specially treated by the driver, we should abort. That will happen in upcoming
patches.

There is a potential security issue with storing the merge driver in the merge
state. See the inline comments for more details.
2015-09-30 21:42:52 -07:00
Pierre-Yves David
d22b16ba8c destupdate: also include bookmark related logic
For the same reason, we move the bookmark related update logic into the
'destupdate' function. This requires to extend the returns of the function to
include the bookmark that needs to move (more or less) and the bookmark to
activate at the end of the function. See function documentation for details on
this returns.
2015-09-29 01:03:26 -07:00
Siddharth Agarwal
c97c4cf7f6 merge.mergestate: perform all premerges before any merges (BC)
We perform all that we can non-interactively before prompting the user for input
via their merge tool. This allows for a maximally consistent state when the user
is first prompted.

The test output changes indicate the actual behavior change happening.
2015-10-11 21:56:39 -07:00
Siddharth Agarwal
8b2a429453 merge: introduce a preresolve function
The section of code that writes out the version of the file cached in the merge
state should only be run at preresolve time. This is so that if the premerge
keeps around conflict markers, those don't get overwritten before the main
merge.
2015-10-11 20:12:12 -07:00
Siddharth Agarwal
cbb558b9d7 merge.mergestate._resolve: also return completed status
We'll need this for a new 'preresolve' function we're adding.
2015-10-11 18:37:54 -07:00
Siddharth Agarwal
2826ed841f merge.mergestate: add a wrapper around resolve
The resolve function will be broken up into separate pre-resolve and resolve
steps.
2015-10-11 18:29:50 -07:00
Siddharth Agarwal
88da24240c filemerge: break overall filemerge into separate premerge and merge steps
This means that in ms.resolve we must call merge after calling premerge. This
doesn't yet mean that all premerges happen before any merges -- however, this
does get us closer to our goal.

The output differences are because we recompute the merge tool. The only
user-visible difference caused by this patch is that if the tool is missing
we'll print the warning twice. Not a huge deal, though.
2015-10-11 20:47:14 -07:00
Siddharth Agarwal
82f2aec334 filemerge: also return whether the merge is complete
In future patches, we'll pause merges after the premerge step. After the
premerge step we'll return complete = False.
2015-10-11 12:56:21 -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
Pierre-Yves David
a92a70c3bd merge: get the default update destination from the function
There is no value in using the revset instead of the extracted function.
2015-09-28 22:11:23 -07:00
Pierre-Yves David
24004c0b3e merge: drop special parent assignment in the obsolete case
We can safely drop this because the very same assignment is enforcement later in
the function. Dropping it will make it simpler to extract the default
destination logic in its own function.
2015-10-05 01:47:33 -07:00
Siddharth Agarwal
7c5424c31f merge.mergestate: factor out code to validate v1/v2 records
We're going to need this in another place in upcoming patches.
2015-09-30 21:22:31 -07:00
timeless@mozdev.org
bbe814936e merge: fix mergestate comment 2015-09-25 00:54:20 -04:00
Matt Mackall
b73f713c00 bidmerge: choose shortest list of diverge and rename/delete warnings
Slightly less arbitrary than choosing the first set.
2015-08-19 14:05:42 -05:00
Pierre-Yves David
182447758e update: move default destination into a revset
This is another step toward having "default" destination more clear and unified.
Not all the logic is there because some bookmark related computation happened
elsewhere. It will be moved later.

The function is private because as for the other ones, cleanup is needed before
we can proceed.
2015-09-18 17:23:10 -07:00
Siddharth Agarwal
79718846d0 merge: move merge step to the end
Resolving other conflicts before merge ones is better because the state before
the merge is as consistent as possible. It will also help with future work
involving automatic resolution of merge conflicts with an external merge
driver.

There are no ordering issues here because it is easy to verify that the same
file is never in both the dg/dm and the m sets.
2015-09-16 12:36:21 -07:00
Siddharth Agarwal
5d41145967 merge: make 'cd' and 'dc' actions store the same arguments as 'm'
We're going to treat these conflicts similarly to merge conflicts, and this
change to the way we store things in memory makes future code a lot simpler.
2015-11-13 22:43:09 -08:00
Siddharth Agarwal
13a33ed9b5 merge: stop emptying out 'cd' and 'dc' actions
(1) These aren't currently read from anywhere, so emptying this out is
    pointless.
(2) These *will* be read from later in upcoming patches, and not emptying
    them out will be important then.
2015-11-13 14:24:22 -08:00
Martin von Zweigbergk
3d33120c8b merge: move messages about possible conflicts a litte earlier
I actually wanted to reduce the amount of code around the call to
applyupdates(), so I tried moving these warnings a little earlier, and
I think it makes the output make a little more sense (see changes to
test cases).
2015-11-12 13:14:03 -08:00
Siddharth Agarwal
b2610217fb merge.applyupdates: only attempt to merge files in mergeactions
This only makes a difference when a merge driver is active -- in that case we
don't want to try and merge all the files, just the ones still unresolved after
the merge driver's preprocess step is over.
2015-11-12 14:29:02 -08:00
Siddharth Agarwal
11e83e49ad merge.mergestate: update docstrings for preresolve and resolve
Add a docstring for preresolve, and update the one for resolve.
2015-11-04 23:44:51 -08:00
Gregory Szorc
6fdc777e04 merge: use absolute_import 2015-08-08 19:41:25 -07:00
Matt Mackall
1f2f7de9a3 merge: make merge.preferancestor type and default consistent
(and mark it)
2015-06-25 17:54:55 -05:00
Matt Mackall
e4b3f099ef merge: mark ancient debugging option 2015-06-25 17:53:16 -05:00
FUJIWARA Katsunori
f4c8983b72 merge: remove useless dirstate.normallookup() invocation in applyupdates()
Explicit 'dirstate.normallookup()' invocation via 'dirtysubstate()' in
'applyupdates()' is useless now, because previous patch fixed the
relevant issue by writing in-memory dirstate changes out at the end of
dirty check.

'dirstate.normallookup()' invocation was introduced by 13fc4cf249d9 to
avoid occasional test failure. This is partial backout of it (added
tests are still left).
2015-07-08 17:01:09 +09: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
Augie Fackler
9c2e980a64 cleanup: use __builtins__.all instead of util.all 2015-05-16 14:34:19 -04:00
Matt Harbison
7422218b87 merge: run update hook after the last wlock release
There were 2 test failures in 3.4-rc when running test-hook.t with the
largefiles extension enabled.  For context, the first is a commit hook:

  @@ -618,9 +621,9 @@
     $ echo 'update = hg id' >> .hg/hgrc
     $ echo bb > a
     $ hg ci -ma
  -  223eafe2750c tip
  +  d3354c4310ed+
     $ hg up 0
  -  cb9a9f314b8b
  +  223eafe2750c+ tip
     1 files updated, 0 files merged, 0 files removed, 0 files unresolved

   make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui

In both cases, largefiles acquires the wlock before calling into core, which
also acquires the wlock.  The first case was fixed in 4100e338a886 by ensuring
the hook only runs after the lock has been fully released.  The full release is
important, because that is what writes dirstate to the disk, allowing external
hooks to see the result of the update.  This simply changes how the update hook
is called, so that it too is deferred until the lock is finally released.

There are many uses of mergemod.update(), but in terms of commands, it looks
like the following commands take wlock while calling mergemod.update(), and
therefore will now have their hook fired at a later time:

    backout, fetch, histedit, qpush, rebase, shelve, transplant

Unlike the others, fetch immediately unlocks after calling update(), so for all
intents and purposes, its hook invocation is not deferred (but the external hook
still sees the proper state).
2015-04-29 15:52:31 -04:00
Durham Goode
9d87aed6e4 graft: allow creating sibling grafts
Previously it was impossible to graft a commit onto it's own parent (i.e. create
a copy of the commit). This is useful when wanting to create a backup of the
commit before continuing to amend it. This patch enables that behavior.

The change to the histedit test is because histedit uses graft to apply commits.
The test in question moves a commit backwards onto an ancestor. Since the graft
logic now more explicitly supports this, it knows to simply accept the incoming
changes (since they are more recent), instead of prompting.
2015-04-05 11:55:38 -07:00
FUJIWARA Katsunori
e269967115 subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty
This patch also centralizes composing dirty reason message like
"uncommitted changes in subrepository 'xxxx'".
2015-03-25 13:55:35 +09:00
FUJIWARA Katsunori
2ad325e10a merge: mark .hgsubstate as possibly dirty before submerge for consistency
Before this patch, failure of updating subrepos may cause inconsistent
".hgsubstate". For example:

  1. dirstate entry for ".hgsubstate" of the parent repo is filled
     with valid size/date (via "hg state" or so)

  2. "hg update" is invoked at the parent repo

  3. ".hgsubstate" of the parent repo is updated on the filesystem as
     a part of "g"(et) action in "merge.applyupdates"

  4. it is assumed that size/date of ".hgsubstate" on the filesystem
     aren't changed from ones at (1)

     this is not so difficult condition, because just changing hash
     ids (every ids are same in length) in ".hgsubstate" doesn't
     change the file size of it

  5. "subrepo.submerge()" is invoked to update subrepos

  6. failure of updating in one of subrepos raises exception
     (e.g. "untracked file differs")

  7. "hg update" is aborted without updating dirstate of the parent repo

     dirstate entry for ".hgsubstate" still holds size/date at (1)

Then, ".hgsubstate" of the parent repo is treated as "CLEAN"
unexpectedly, because updating ".hgsubstate" at (3) doesn't change
size/date of it on the filesystem: see assumption at (4).

This inconsistent ".hgsubstate" status causes unexpected behavior, for
example:

  - "hg revert" forgets to revert ".hgsubstate"

  - "hg update" misunderstands that (not yet updated) subrepos diverge
    (then, it shows the prompt to confirm user's decision)

To avoid inconsistent ".hgsubstate" status above, this patch marks
".hgsubstate" as possibly dirty before "submerge" invocation.
"normallookup"-ed (= dirty) dirstate should be written out, even if
processing is aborted by failure.

This patch marks ".hgsubstate" as possibly dirty before "submerge",
also when it is removed or merged while merging, for safety. This
should prevent Mercurial from misunderstanding inconsistent
".hgsubstate" as clean.

To satisfy conditions at (1) and (4) above, this patch uses "hg status
--config debug.dirstate.delaywrite=2" (to fill valid size/date into
dirstate) and "touch" (to fix date of the file).
2015-01-30 04:59:05 +09:00
Angel Ezquerra
79698da278 localrepo: remove all external users of localrepo.wopener
This change touches every module in which repository.wopener was being used, and
changes it for the equivalent repository.wvfs.

It should now be possible to remove localrepo.wopener.
2015-01-11 01:51:52 +01:00