Fossil Forum

Merge conflict common ancestor marker
Login

Merge conflict common ancestor marker

(1) By anonymous on 2018-10-17 03:59:13 [link] [source]

Fossil merge conflict output is very informative and includes a common ancestor section:

======= COMMON ANCESTOR
I wonder if it's possible to use " " for the leading marker instead of "="?

This would make it agree with Git (diff3 mode), which in turn helps with visual tools that automatically highlight conflict sections and help in resolving it.

Basically, make the common ancestor header look something like:

||||||| COMMON ANCESTOR

Thanks.

(2) By anonymous on 2018-10-17 05:06:53 [link] [source] in reply to 1

I wonder if it's possible to use "" for the leading marker instead of "="?

Should read "|" for the pipe-char.

Looks like our Markdown parser took the unescaped pipe for a table column separator. Interesting...

(3) By Warren Young (wyoung) on 2018-10-17 11:17:06 [link] [source] in reply to 1

What tool are you using that doesn't understand Fossil's conflict markers? I'm pretty sure it's an old convention predating Fossil, which implies that it's your merge tool that needs to be changed, not Fossil.

(4) By anonymous on 2018-10-17 18:55:38 [link] [source] in reply to 3

Perhaps it was not clear from my orginal post. Here's the comparison between conflict sections produced by Fossil vs Git.

Fossil conflict, src/merge3.c:

  <<<<<<< BEGIN MERGE CONFLICT: local copy shown first <<<<<<<<<<<<<<<
    puts 'hola world'
  ======= COMMON ANCESTOR content follows ============================
    puts 'hello world'
  ======= MERGED IN content follows ==================================
    putd 'hello mundo'
  >>>>>>> END MERGE CONFLICT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Git conflict (diff3-style), Git - Advanced Merging:

  <<<<<<< ours
    puts 'hola world'
  ||||||| base
    puts 'hello world'
  =======
    puts 'hello mundo'
  >>>>>>> theirs

You can see that both formats are very much similar. However, the COMMON ANCESTOR section is marked differently. Git uses "|" (pipe-char) leading marker for the ancestor section and "=" for the merged-in section. Fossil uses "=" for both.

I could not find any specs that generally govern the formatting of the common ancestor section.

Git's convention does have two advantages:

  1. each section has its marker; this simplifies parsing by tools
  2. mnemonic meaning, "|" signifies center-line, with ours the the left, theirs on the right

Fossil's convention holds a descriptive advantage -- the verbose labels make section contents more clear.

TLDR; By adopting "|" for Fossil's common ancestor section leading mark, it would equally simplify the parsing.

So, what I ask is to have Fossil output the confict with a format like this (?maybe a config option):

  <<<<<<< BEGIN MERGE CONFLICT: local copy shown first <<<<<<<<<<<<<<<
    puts 'hola world'
  ||||||| COMMON ANCESTOR content follows ||||||||||||||||||||||||||||
    puts 'hello world'
  ======= MERGED IN content follows ==================================
    putd 'hello mundo'
  >>>>>>> END MERGE CONFLICT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Git's convention is the most visible online and thus has a better chance for support by visual tools.

(5) By andygoth on 2018-10-17 20:22:10 [link] [source] in reply to 4

Are you suggesting merging the merge marker conventions? ;^)

I think this is a good change. I definitely prefer our merge marker format over git's format, but that doesn't mean we can't meet in the middle, and your proposal certainly does that.

Please allow me to disagree that this change simplifies parsing tools. I dislike parsing tools that take shortcuts since they are susceptible to false positives. It is best to parse the whole line. Better still is to maintain state so that, for example, the >>>>>>> merge marker means nothing unless it comes after ======= without any intervening merge markers. Don't get me wrong; this is not a complaint. It's just a word of caution.

(6) By sebyte on 2019-11-14 08:08:52 and edited on 2019-11-14 09:08:34 [history] [link] [source] in reply to 1

I would like to second this call.

As far as I can tell, use of the pipe character has nothing to do with Git, per se. Rather, it is a Gnu diff3 convention:

https://www.gnu.org/software/diffutils/manual/html_node/Marking-Conflicts.html#Marking-Conflicts

Accordingly, Emacs' Simple Merge mode (smerge-mode.el) has matched conflict markers in source files like so:

(defconst smerge-begin-re "^<<<<<<< \\(.*\\)\n")
(defconst smerge-base-re "^||||||| \\(.*\\)\n")
(defconst smerge-lower-re "^=======\n")
(defconst smerge-end-re "^>>>>>>> \\(.*\\)\n")

since approx. 1999.

In my opinion, a diff3-conflict-markers setting defaulting to off would be a sensible addition.

EDIT

In the meantime, adding the following to your dotemacs is a possible workaround:

(defun smerge-try-smerge-mode ()
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward "^<<<<<<< " nil t)
      (require 'smerge-mode)
      (when (eq (vc-deduce-backend) 'Fossil)
        (mapc #'make-variable-buffer-local
              '(smerge-base-re smerge-lower-re))
        (setq smerge-base-re ; "^||||||| \\(.*\\)\n"
          "^======= COMMON ANCESTOR \\(.*\\)\n"
          smerge-lower-re ; "^=======\n"
          "^======= MERGED IN .*\n"))
      (smerge-mode 1))))
(add-hook 'find-file-hook 'smerge-try-smerge-mode t)

This assumes you have vc-fossil.el:

http://chiselapp.com/user/venks/repository/emacs-fossil/

installed.