git-imerge icon indicating copy to clipboard operation
git-imerge copied to clipboard

Add a --transposed option to the diagram subcommand

Open waldyrious opened this issue 5 years ago • 4 comments

If one of the branches has lots of commits, the diagram can become too wide for the terminal and even wrap around, which makes it very hard to read.

Here's an example from a rebase I did today:

❯ git imerge diagram
***********************************************************************************************************************************************************************************************************************************************************************************************************************
*????.*??????????????????????.#????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
*.............................?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Key:
  * = merge done manually
  . = merge done automatically
  # = conflict that is currently blocking progress
  @ = merge was blocked but has been resolved
  ? = no merge recorded

...which, when wrapped, becomes this:

❯ git imerge diagram
********************************************************************************
********************************************************************************
********************************************************************************
***********************************************************************
*????.*??????????????????????.#?????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????
*.............................??????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????

Key:
  * = merge done manually
  . = merge done automatically
  # = conflict that is currently blocking progress
  @ = merge was blocked but has been resolved
  ? = no merge recorded

I think an option to rotate the diagram, so that the shortest branch grows horizontally and the longest one grows vertically, would be helpful in these situations:

❯ git imerge diagram
***
*?.
*?.
*?.
*?.
*..
**.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*?.
*..
*#?
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??
*??

Key:
  * = merge done manually
  . = merge done automatically
  # = conflict that is currently blocking progress
  @ = merge was blocked but has been resolved
  ? = no merge recorded

waldyrious avatar Jan 09 '20 18:01 waldyrious

I wouldn't mind such a feature, but I'm unlikely to have time to work on it.

mhagger avatar Jan 10 '20 08:01 mhagger

Any hints about how one should go about implementing it?

waldyrious avatar Jan 10 '20 10:01 waldyrious

I think the transposition would have to happen pretty late. Probably you'd want:

  • a function to transpose the output of Block.create_diagram() or MergeFrontier.create_diagram() (one function could probably do both). Remember that FRONTIER_BOTTOM_EDGE and FRONTIER_RIGHT_EDGE have to be swapped in the individual cells.
  • Block.format_diagram(), Block.write(), Block.writeppm(), MergeFrontier.write(), MergeFrontier.write_html(), and MergeFrontier.format_diagram() probably need a new optional transpose=false argument.

I think it would help to make a Diagram class to hold the output of *.create_diagram(). Class instances should know their lengths and know how to transpose themselves. Note that MergeFrontier.write_html() also accesses the SHA-1 of cells via the associated block using self.block.get_value(i1, i2). You could provide access to this via the new Diagram class. Probably the write*() methods could move to the Diagram class.

It's going to be subtle to implement this without adding conditional logic all over the place, but I think it's possible. If not, then it'd probably be better to live without this feature rather than complicating the code a lot.

mhagger avatar Jan 10 '20 12:01 mhagger

It would also be nice to see numbers that git-imerge uses explained somewhere on the diagram. I suspect that they map to dimensions, but I am not sure about their meaning and how start+end are determined.

abitrolly avatar Jun 16 '20 16:06 abitrolly