Commit Graph

537 Commits

Author SHA1 Message Date
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
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
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
Angel Ezquerra
88cbab7845 localrepo: remove all external users of localrepo.opener
This change touches every module in which repository.opener was being used, and
changes it for the equivalent repository.vfs. This is meant to make it easier
to split the repository.vfs into several separate vfs.

It should now be possible to remove localrepo.opener.
2015-01-15 23:17:12 +01:00
Martin von Zweigbergk
e5d2c961b1 merge: move checking of unknown files out of manifestmerge()
This moves most reading of filelogs out of manifestmerge, making it
easy for a narrow clone extension to filter out or translate unwanted
actions before any filelogs are read. The only call left is inside of
copies.mergecopies(), which can be overridden separately at a lower
level.
2014-12-18 09:22:09 -08:00
Martin von Zweigbergk
9855f121f2 merge: extract method for checking for conflicting untracked file
Now that the functionality is collected in one place, let's extract it
to a method.
2014-12-13 23:52:22 -08:00
Martin von Zweigbergk
8c5b45ee44 merge: create 'cm' action for 'get or merge' case
We still have one case of a call to _checkunknownfile() in
manifestmerge(): when force=True and branchmerge=True and the remote
side has a file that the local side doesn't. This combination of
arguments is used by 'hg merge --force', but also by rebase and
unshelve. In this scenario, we try to create the file from the
contents from the remote, but if there is already a local untracked
file in place, we merge it instead.
2014-12-15 16:45:19 -08:00
Martin von Zweigbergk
a78e57ed87 merge: don't overwrite untracked file at directory rename target
When a directory was renamed and a new untracked file was added in the
new directory and the remote directory added a file by the same name
in the old directory, the local untracked file gets overwritten, as
demonstrated by the broken test case in test-rename-dir-merge.

Fix by checking for unknown files for 'dg' actions too. Since
_checkunknownfile() currently expects the same filename in both
contexts, we need to add a new parameter for the remote filename to
it.
2014-12-12 23:18:36 -08:00
Martin von Zweigbergk
a397b486a4 merge: remove constant tuple element from 'aborts'
The second element of the tuples in the 'aborts' list is always 'ud',
so let's remove it.
2014-11-18 20:29:25 -08:00
Martin von Zweigbergk
e31b8e4514 merge: collect checking for unknown files at end of manifestmerge()
The 'c' and 'dc' actions include creating a file on disk and we need
to check that no conflicting file exists unless force=True. Move two
of the calls to _checkunknownfile() to a single place at the end of
manifestmerge(). This removes some of the reading of filelogs from the
heart of manifestmerge() and collects it in one place close to where
its output (entries in the 'aborts' list) is used.

Note that this removes the unnecessary call to _checkunknownfile()
when force=True in one of the code paths.
2014-11-19 11:51:31 -08:00
Martin von Zweigbergk
05f68a2661 merge: introduce 'c' action like 'g', but with additional safety
_checkunknownfile() reads the filelog of the remote side's file. For
narrow clones, the filelog will not exist for all files and we need a
way to avoid reading them. While it would be easier for the narrow
extension to just override _checkunknownfile() and make it ignore
files outside the narrow clone, it seems cleaner to have
manifestmerge() not care about filelogs (considering its
name).

In order to move the calls to _checkunknownfile() out, we need to be
able to tell in which cases we should check for unknown files. Let's
start by introducing a new action distinct from 'g' for this
purpose. Specifically, the new action will be just like 'g' except
that it will check that for conflicting unknown files first. For now,
just add the new action type and convert it to 'g'.
2014-11-19 11:48:30 -08:00
Martin von Zweigbergk
589fe422b9 merge: structure 'remote created' code to match table
This does duplicate the call to _checkunknownfile(), but it will
simplify future patches.
2014-11-19 11:44:00 -08:00