Commit Graph

174 Commits

Author SHA1 Message Date
Yuya Nishihara
8af2b4d601 filemerge: optionally strip quotes from merge marker template (BC)
For consistency with the other template options. Quotes are necessary if
you want to preserve leading/trailing whitespace, which would be stripped
by config parser.
2017-02-25 19:36:02 +09:00
Pierre-Yves David
4fa55e8b7e filemerge: explicitly tests for None
Changeset 3495cae22a41 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:11:52 -07:00
Gregory Szorc
9bc6055676 filemerge: don't use mutable default argument value 2016-12-26 16:54:33 -07:00
Simon Farnsworth
17c528e46d filemerge: tag merge tool for blocked times
Merge tools can take a while - let's ensure that they're appropriately tagged
2017-03-06 03:19:40 -08:00
Pulkit Goyal
07314d0686 py3: convert the mode argument of os.fdopen to unicodes (1 of 2)
os.fdopen() does not accepts bytes as its second argument which represent the
mode in which the file is to be opened. This patch makes sure unicodes are
passed in py3 by using pycompat.sysstr().
2017-02-13 20:06:38 +05:30
Martin von Zweigbergk
d96c319788 merge: print status message before launching external merge tool
It seems somewhat common that people run into a merge conflict and
don't notice the launched merge tool, and instead they think hg just
hung. Let's print a message for each file that we launch a GUI merge
tool for.
2017-02-09 09:32:25 -08:00
Pulkit Goyal
bb08d44667 py3: replace os.environ with encoding.environ (part 3 of 5) 2016-12-18 01:54:36 +05:30
Mads Kiilerich
a31c060801 merge: use original file extension for temporary files
Some merge tools (like Araxis?) can pick merge mode based on the file
extension. That didn't work well when temporary files were given random
suffixes. It seems to work better when the random part is before the extension.

As usual, when using $output, $local will have the .orig extension. That could
perhaps be the subject of another change another day.
2016-11-23 23:47:38 +01:00
Kostia Balytskyi
279f8962a7 conflicts: make spacing consistent in conflict markers
The way default marker template was defined before this patch,
the spacing before dash in conflict markes was dependent on
whether changeset is a tip one or not. This is a relevant part
of template:
    '{ifeq(tags, "tip", "", "{tags} "}'
If revision is a tip revision with no other tags, this would
resolve to an empty string, but for revisions which are not tip
and don't have any other tags, this would resolve to a single
space string. In the end this causes weirdnesses like the ones
you can see in the affected tests.

This is a not a big deal, but double spacing may be visually
less pleasant.

Please note that test changes where commit hashes change are
the result of marking files as resolved without removing markers.
2016-11-19 15:41:37 -08:00
Augie Fackler
727b0d4499 filemerge: avoid shadowing a variable in a list comprehension 2016-11-10 16:33:07 -05:00
Pulkit Goyal
e4b15b1b8c py3: make format strings unicodes and not bytes
Fixes issues on Python 3, wherein docstrings are unicodes.
Shouldn't break anything on Python 2.
2016-10-08 16:10:58 +02:00
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