Commit Graph

163 Commits

Author SHA1 Message Date
Simon Farnsworth
1b7185f6d1 merge: always use other, not remote, in user prompts
Now that we store and display merge labels in user prompts (not just
conflict markets), we should rely on labels to clarify the two sides of a
merge operation (hg merge, hg update, hg rebase etc).

"remote" is not a great name here, as it conflates "remote" as in "remote
server" with "remote" as in "the side of the merge that's further away". In
cases where you're merging the "wrong way" around, remote can even be the
"local" commit that you're merging with something pulled from the remote
server.
2016-08-12 05:56:40 -07:00
Simon Farnsworth
906104f96d merge: use labels in prompts to the user
Now that we persist the labels, we can consistently use the labels in
prompts for the user without risk of confusion. This changes a huge amount
of command output:

This means that merge prompts like:
  no tool found to merge a
  keep (l)ocal, take (o)ther, or leave (u)nresolved? u
and
  remote changed a which local deleted
  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? c
become:
  no tool found to merge a
  keep (l)ocal [working copy], take (o)ther [destination], or leave (u)nresolved? u
and
  remote [source] changed a which local [dest] deleted
  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? c
where "working copy" and "destination" were supplied by the command that
requested the merge as labels for conflict markers, and thus should be
human-friendly.
2016-08-12 06:01:42 -07:00
Yuya Nishihara
b432ce21ff merge: concatenate default conflict marker at parsing phase of .py
"+" operations are unnecessary.
2015-05-05 10:51:34 +09:00
Yuya Nishihara
84a8ba9511 templater: factor out function that creates templater from string template
This function will host loading of template aliases. It is not defined at
templater, but at formatter, since formatter is the module handling ui stuff
in front of templater.
2016-04-10 17:23:09 +09:00
Yuya Nishihara
3f981af86b templater: separate function to create templater from map file (API)
New frommapfile() function will make it clear when template aliases will be
loaded. They should be applied to command arguments and templates in hgrc,
but not to map files. Otherwise, our stock styles and web templates
(i.e map-file templates) could be modified unintentionally.

Future patches will add "aliases" argument to __init__(), but not to
frommapfile().
2016-04-03 23:26:48 +09:00
timeless
81737a7154 filemerge: use revset notation for p1/p2 of local/other descriptions 2016-03-17 00:36:01 +00:00
timeless
a136072319 filemerge: indicate that local/other are p1/p2 2016-03-17 00:36:01 +00:00
Siddharth Agarwal
0efe3372e4 origpath: move from cmdutil to scmutil
This is a lower-level function so it doesn't need to be in cmdutil, and putting
it here avoids a bunch of potential import cycle issues.
2016-01-02 03:02:57 -08:00
Siddharth Agarwal
1c3dcd1546 filemerge: default change/delete conflicts to 'leave unresolved' (BC)
It makes far more sense to leave these conflicts unresolved and kick back to
the user than to just assume that the local version be chosen. There are almost
certainly buggy scripts and applications using Mercurial in the wild that do
merges or rebases non-interactively, and then assume that if the operation
succeeded there's nothing the user needs to pay attention to.

(This wasn't possible earlier because there was no way to re-resolve
change/delete conflicts -- but now it is.)
2015-12-23 12:51:45 -08:00
Siddharth Agarwal
106adbe75b filemerge: default regular prompts to 'leave unresolved' (BC)
It makes far more sense to leave these conflicts unresolved and kick back to
the user than to just assume that the local version be chosen. There are almost
certainly buggy scripts and applications using Mercurial in the wild that do
merges or rebases non-interactively, and then assume that if the operation
succeeded there's nothing the user needs to pay attention to.
2015-12-01 09:48:38 -08:00
Siddharth Agarwal
7382fa0a4e filemerge: add a 'leave unresolved' option to change/delete prompts
We're going to make this option the default in an upcoming patch.
2015-11-30 13:43:55 -08:00
Siddharth Agarwal
7be324f9ab filemerge: add a 'leave unresolved' option to regular prompts
'Regular' here means anything that isn't a change/delete prompt. We'll add this
option to change/delete prompts in a subsequent patch.
2015-11-30 11:17:18 -08:00
Siddharth Agarwal
807dab9ed1 filemerge: add debug output for whether this is a change/delete conflict
Just like binary and symlink conflicts, change/delete conflicts influence the
tool picked.
2015-11-25 14:25:26 -08:00
Siddharth Agarwal
6775160009 filemerge: in ':prompt', use ':fail' tool rather than returning directly
The ':fail' tool now knows to write out the changed side for change/delete
conflicts.

This has no impact right now but will make things better when we move
change/delete conflicts in here.
2015-11-24 10:58:35 -08:00
Siddharth Agarwal
1fc099f7ba filemerge: in ':fail' tool, write out other side if local side is deleted
We do this because we don't want to modify the dirstate for failures, and don't
just want to leave the file missing from disk. Plus it's more useful for the
user if the changed side is written out -- it is easier to delete a file than
to get it back via hg revert.
2015-11-24 10:57:01 -08:00
Siddharth Agarwal
2264cfb327 filemerge: don't try to copy files known to be absent
We set 'back' to None in this case, so we need to handle that as well.
2015-11-14 00:00:46 -08:00
Siddharth Agarwal
830ec886fc filemerge: don't try using external tools on change/delete conflicts
This is mostly for completeness' sake -- the current code shouldn't get to this
point.
2015-11-13 23:57:43 -08:00
Siddharth Agarwal
5222eee8d6 filemerge: don't attempt to premerge change/delete conflicts
This is mostly for completeness' sake -- at the moment we don't support any
tools for change/delete conflicts that would do a premerge.
2015-11-13 23:56:00 -08:00
Siddharth Agarwal
a5600d30a6 filemerge._mergecheck: add check for change/delete conflicts
Merge tools that perform an actual 3-way merge can't handle change/delete
conflicts. This adds a check for that.
2015-11-13 23:58:05 -08:00
Siddharth Agarwal
1154e3eab0 filemerge._picktool: only pick from nomerge tools for change/delete conflicts
For --tool or HGMERGE, we could have either:
(a) proceeded with the particular tool, then failed the merge.
(b) chosen to prompt regardless.

We're explicitly choosing (b) here, because it's effectively what we've been
doing so far and helps maintain an easier-to-use interface.

However, in future patches we're going to change the default selection from
'pick changed version' to 'leave unresolved'. That fixes most of the brokenness
involved with choice (b).
2015-11-15 21:40:15 -08:00
Siddharth Agarwal
dfb75ef0b1 filemerge: add support for change/delete conflicts to the ':prompt' tool
We haven't added the 'leave unresolved' option yet -- that will come in a
future patch.
2015-11-13 23:52:26 -08:00
Siddharth Agarwal
1b647216ac filemerge: add support for change/delete conflicts to the ':other' merge tool
This, along with the previous patch to the :local merge tool, covers the full
matrix of change/delete conflicts.
2015-11-18 15:41:50 -08:00
Siddharth Agarwal
b3c05df6b2 filemerge: add support for change/delete conflicts to the ':local' merge tool
This covers two of the four cases of change/delete conflicts -- in an upcoming
patch we'll make :other cover the other two.
2015-11-18 15:40:28 -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
c33d958db2 filemerge: return whether the file is deleted from all other merge tools
This is required for change/delete conflicts -- see the previous patch for more
information.
2015-11-18 13:55:31 -08:00
Siddharth Agarwal
4155f9cde2 filemerge: return whether the file is deleted for nomerge internal tools
We're going to support the filemerge code resolving change/delete conflicts in
upcoming patches. Some of these resolutions require that the dirstate be
modified. Modifying the dirstate directly from in here would be (a) a pretty
bad layering violation and (b) wrong because all dirstate removals should
happen before adds. So in this and upcoming patches we're instead going to pass
whether the file is deleted up to merge.mergestate, then in there figure out
what dirstate action needs to be taken.
2015-11-18 13:52:28 -08:00
Siddharth Agarwal
d26567458a filemerge: introduce class whose objects represent files not in a context
Most code is going to barf at the return values here (particularly from data
and size), so we restrict it to the filemerge code.

This is already somewhat supported via:

  ctx.filectx(f, fileid=nullid)

Indeed, for add/add conflicts (ancestor doesn't have the file) we use precisely
that. However, that is broken in subtle ways:
- The cmp() function in filectx returns False (identical) for such a filectx
  when compared to a zero-length file.
- size() returns 0 rather than some sort of value indicating that the file isn't
  present.
- data() returns '' rather than some sort of value indicating that the file isn't
  present.

Given the relatively niche use of such filectxes, this seems to be the simplest
way to fix all these issues.
2015-11-16 11:45:35 -08:00
Martin von Zweigbergk
b2254eccbe filemerge: remove leading space from " no tool found..."
I could not find or see a reason for the unusual formatting. The lines
following it in the test cases are not indented.
2015-11-11 10:19:11 -08:00
Siddharth Agarwal
482e3440bf filemerge: rename _symlinkcheck to _mergecheck
We're going to be adding other checks in here soon.
2015-11-11 17:34:28 -08:00
Christian Delahousse
4642f4298b filemerge: choose where .orig files are kept
Having .orig files litter your working copy is a common complaint. This patch
uses cmdutil.orig to let the user determine where those files should reside.
2015-11-10 16:25:59 -08:00
Siddharth Agarwal
32de813627 filemerge: treat EOF at prompt as fail, not abort
Previously we'd abort the merge entirely if there was an EOF at the prompt.
This is unnecessary -- it's much better to simply fail and treat the file as
unresolved instead.
2015-11-10 17:13:16 -08:00
Siddharth Agarwal
ddc0857ff8 filemerge: move :merge-local/other symlink check to precheck
In upcoming patches we're going to add more checks to the function currently
named _symlinkcheck. This consolidates all those checks.
2015-11-08 23:42:44 -08:00
Siddharth Agarwal
09431ac4f3 filemerge.prompt: separate out choice selection and action
This will make future patches cleaner.
2015-11-02 12:12:24 -08:00
Augie Fackler
32827d85c7 merge-tools: allow marking a mergetool as completely disabled
Very often in my life I'm finding that the only configured merge tool
present on the system is vimdiff[0], and it's currently impossible (as
far as I can tell) short of specifying `ui.merge = `[1] to actually
*disable* a merge tool. This allows vimdiff-haters to put:

  [merge-tools]
  vimdiff.disable = yes

in their ~/.hgrc and never see vimdiff again. I'm stopping short of
putting this as a commented out entry in the sample new user hgrc
(seen when a user runs `hg config --edit` with no ~/.hgrc) for now,
but I might come back and do that later.

0: vimdiff is at an awkward intersection: it's usually installed by
the vim package which is often installed as a vi substitute, so it's
mere presence doesn't imply me wanting it, unlike (say) kdiff3.

1: There's a related problem I ran into today where specifying
`ui.merge = :merge` failed because :merge isn't a command, which I
think is a regression. I'll try and figure that out and at least file
a bug.
2015-10-14 12:57:33 -04:00
Siddharth Agarwal
a6dc53e738 simplemerge: move conflict warning message to filemerge
The current output for a failed merge with conflict markers looks something like:

  merging foo
  warning: conflicts during merge.
  merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
  merging bar
  warning: conflicts during merge.
  merging bar incomplete! (edit conflicts, then use 'hg resolve --mark')

We're going to change the way merges are done to perform all premerges before
all merges, so that the output above would look like:

  merging foo
  merging bar
  warning: conflicts during merge.
  merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
  warning: conflicts during merge.
  merging bar incomplete! (edit conflicts, then use 'hg resolve --mark')

The 'warning: conflicts during merge' line has no context, so is pretty
confusing.

This patch will change the future output to:

  merging foo
  merging bar
  warning: conflicts while merging foo! (edit, then use 'hg resolve --mark')
  warning: conflicts while merging bar! (edit, then use 'hg resolve --mark')

The hint on how to resolve the conflicts makes this a bit unwieldy, but solving
that is tricky because we already hint that people run 'hg resolve' to retry
unresolved merges. The 'hg resolve --mark' mostly applies to conflict marker
based resolution.
2015-10-09 13:54:52 -07:00
Siddharth Agarwal
dceb171bec filemerge: clean up some dead code
We now exit early if we do a premerge, so extra checks are no longer necessary.
2015-10-11 15:04:00 -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
b1a86ac060 filemerge: only copy to backup during premerge step
The premerge might leave the original file in an unclean state. Therefore it's
important to only copy the file in the beginning.
2015-10-11 20:04:40 -07:00
Siddharth Agarwal
014002cfa1 filemerge: only print out "merging f" output at premerge step
We're soon going to call this function twice, once for premerge and once for
merge. This makes sure the "merging" output only gets printed during the
premerge step.
2015-10-11 20:02:53 -07:00
Siddharth Agarwal
76bf2a7269 filemerge: deindent the parts of filemerge outside the try block
It is no longer necessary to indent these parts.
2015-10-08 00:19:20 -07:00
Siddharth Agarwal
dd90f817f9 filemerge: introduce a premerge flag and function
This flag will let us get to our overall goal of performing all premerges
before any merges.
2015-10-11 20:47:04 -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
Siddharth Agarwal
da75e232c9 filemerge: add a wrapper around the filemerge function
We'll introduce a separate premerge function that calls the same code.
2015-10-11 12:31:08 -07:00
Siddharth Agarwal
056b42f09f filemerge: clean up temp files in a finally block
This isn't really a big deal because the temp files are created in $TMPDIR, but
it makes some upcoming work simpler.
2015-10-07 21:51:24 -07:00
Siddharth Agarwal
4376011dff filemerge: move post-merge checks into a separate function
This makes the overall filemerge function easier to follow, and makes upcoming
work simpler.
2015-10-07 23:35:30 -07:00
Siddharth Agarwal
3fbcf75f0f filemerge._xmerge: drop no longer necessary 'if r:' check
Cleanup from an earlier patch to make premerge be directly called from the main
filemerge function.
2015-10-08 14:18:43 -07:00
Siddharth Agarwal
1cb9cb73fe filemerge._idump: drop no longer necessary 'if r:' check
Cleanup from an earlier patch to make premerge be directly called from the main
filemerge function.
2015-10-08 14:17:31 -07:00
Siddharth Agarwal
3f7b11ab57 filemerge._merge: drop no longer necessary 'if r:' check
Cleanup from an earlier patch to make premerge be directly called from the main
filemerge function.
2015-10-08 14:16:19 -07:00
Siddharth Agarwal
3d95b69af3 filemerge: call premerge directly from main merge function
The merge code currently does (in pseudocode):

for f in tomerge:
    premerge f
    merge f

We'd like to change this to look more like:

for f in tomerge:
    premerge f

for f in tomerge:
    merge f

This makes sure as many files are resolved as possible before prompting for the
others. This restructuring is also necessary for custom merge drivers.

This function separates out the premerge step from the merge step. In future
patches we'll actually turn these into separate steps in the merge driver.

The 'if r:' occurrences will be cleaned up in subsequent patches.
2015-10-07 21:22:16 -07:00
Siddharth Agarwal
1f3c72862f filemerge: move precheck to before files are written out
This is much simpler, and also avoids unnecessary disk IO.
2015-10-07 21:28:43 -07:00