1. David Wolever
  2. hg-mergediff
  3. Issues
Issue #1 open

Confusing presentation of hunk sides

Christoph Rissner
created an issue

Maybe its just me, but I like to think of of "left" and "right" parents of merges. The "left" is the first parent (local, where I merge into), the "right" parent is the second one (other, the one I merge from).

However, mergediff shows added lines of the left side with a + char in the second column, added lines of the right side get a + in the first column.

Example:

{{{

!bash

~/tmp/x % hg init ~/tmp/x % touch a ~/tmp/x % hg ci -A -m "init" adding a ~/tmp/x % echo 1 > a ~/tmp/x % hg ci -m "added 1" ~/tmp/x % hg up -r 0 1 files updated, 0 files merged, 0 files removed, 0 files unresolved ~/tmp/x % echo 2 > a ~/tmp/x % hg ci -m "added 2" created new head ~/tmp/x % hg merge 1 ... resolve conflict ... ~/tmp/x % hg res -m ~/tmp/x % hg ci -m "merged 1" ~/tmp/x % hg mdiff --- a/a --- b/a +++ c/a @ +1,2 @ + 1 +2 }}} The first line was added in the "other" branch ("left"), the 2nd in the local branch ("right").

I suggest a small patch (there is no need for %2, we only have sides 0 and 1): {{{

!patch

diff --git a/mergediff.py b/mergediff.py --- a/mergediff.py +++ b/mergediff.py @@ -289,7 +289,7 @@ raise FoundABug()

             if line_added:
  • prefix[(hunk._side+1)%2] = "+"
  • prefix[hunk._side] = "+"

         if line is not None:
             ui.debug("line: ")
    

    }}}

Comments (1)

  1. David Wolever repo owner
    • changed status to open

    Thanks for the patch… Although I don't think it's quite that simple: to do that correctly, you'll also need to update the 'removed hunk' logic (starting at the comment `# If there are any lines that have been removed…`).

    To see why, use the `mktestrepo` script to build a test repository, then look at the mdiff shown for the file `resolved` (which was set to “in a” in branch `a`, “in b” in branch `b`, then during the merge the conflict was resolved by setting it to “in a”). Without the patch, it looks like this:

    --- a/resolved
    +++ c/resolved
    @ +3,7 @
      unchanged line 2
      unchanged line 3
      unchanged line 4
     -in b
     +in a
      unchanged line 5
      unchanged line 6
      unchanged line 7
    

    Which, ignoring the side of the +/-, is correct… But with your patch, it shows:

    --- a/resolved
    +++ c/resolved
    @ +3,7 @
      unchanged line 2
      unchanged line 3
      unchanged line 4
     -in b
    + in a
      unchanged line 5
      unchanged line 6
      unchanged line 7
    

    Which doesn't make sense.

    Possibly this is why I chose to use the confusing `prefix[(hunk._side+1)%2]` logic rather than the more straight forward `prefix[hunk._side]`.

  2. Log in to comment