Skip to contentSkip to conversation

(reverse) combined diff conflict style

RFC In review Bert Wesarg 2 participants 3 messages Jun 15, 2016 – Aug 13, 2016 2 messages not in the archive Kbuild

lore
Share & tools
lore
#1 lore raw
In reply to Bert Wesarg
Quoted 9 lines · Bert Wesarg

----- output ----

1
<<<<<<<
-2
- 3

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

4

Quoted 7 lines

------ end ------

As you can see, the conflict region is way smaller as the diff3 one, but keeps all information.

I'm not doing much merges myself, so there are probably people out there who can better judge the usefulness of this style.

As a format to review conflicted regions in a pager, this might be a good alternative representation.

But I doubt I would want to use this as a way for "git merge", "git am -3" and their friends to write a half-merged result out to the work tree for me to resolve. With either --conflict=merge or --conflict=diff3, it is easy to pick lines from either side (you remove what is not needed in the final result), but with this format you always have to not just pick but remove the change marker at the beginning from the "these are good, I'd use them" lines. And you have to do so for every single line you reuse from either side.

#4 lore raw
In reply to a message not in the archive

[ Sorry, I removed the list by mistake. CC'ed again ]

Quoted 16 lines · Junio C Hamano
Quoted 10 lines · Bert Wesarg

I use two programmed short-cuts in my editor for this. The first 'applies' the diff, i.e. it keeps all lines prefixed with ' ' or '+' and deletes lines with '-', and then removes the first column. The second 'reverses' a diff, i.e. exchanges '+' with '-' and vice versa. With these two operations I find it easier to resolve the conflict than with the mege/diff3 presentation.

I'm also convinced, that it is currently impossible to implement this conflict style in the xdiff library. So it will probably be forever some 'external solution'.

Why not?

IIUC, your approach is to postprocess output diff3 style merge.

Quoted 8 lines

 - First define your style as a new "conflict style" and store it in git_xmerge_style to pass it around.  "checkout --conflict=bert" would learn this style automatically.

 - In ll_xdl_merge(), we usually call xdl_merge() and return directly its return value.  When style is "bert", instead of doing that, you pass "diff3 style" and drive xdl_merge(), _but_ you do not return.  Instead, you do your postprocessing right there and then return the result.

Thanks for this pointer. That looks really doable. Will report back later.

Bert

#0 lore raw

RFC 1/1 (reverse) combined diff conflict style

Hi All,

as I mentioned in my reply[1] to Junio about a reversed combined diff, I've done this with the intended use case to display merge conflicts this way.

The algorithm is pretty much the same as the diff --cc/-c one and most of the code too. I have currently too proof-of-concept tools for this:

* git cdiff <base> <targets>..
This command takes files as parameters and generates a combined diff from the <base> to all <targets>. No hunking is done.

* git cdiff-conflict-filter
This filters it input stream and looks for merge conflict markers and replaces the conflict with the output of the cdiff. It needs the diff3 conflict style for this. Here is a simple example:

----- input -----

1
<<<<<<<
2
|||||||
2
3
=======
3

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

4

----- output ----

1
<<<<<<<
-2
- 3

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

4

------ end ------

As you can see, the conflict region is way smaller as the diff3 one, but keeps all information.

I'm not doing much merges myself, so there are probably people out there who can better judge the usefulness of this style.

Bert

[1]: http://article.gmane.org/gmane.comp.version-control.git/138108

---
 .gitignore      |    2 +
 Makefile        |    2 +
 builtin-cdiff.c |  387 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h       |    2 +
 git.c           |    2 +
 5 files changed, 395 insertions(+), 0 deletions(-)
.gitignore +2 -0
index 8df8f88..ce685ce 100644
@@ -17,6 +17,8 @@
 /git-branch
 /git-bundle
 /git-cat-file
+/git-cdiff
+/git-cdiff-conflict-filter
 /git-check-attr
 /git-check-ref-format
 /git-checkout
Makefile +2 -0
index 7bf2fca..cd5df9e 100644
@@ -384,6 +384,7 @@ BUILT_INS += git-show$X
 BUILT_INS += git-stage$X
 BUILT_INS += git-status$X
 BUILT_INS += git-whatchanged$X
+BUILT_INS += git-cdiff-conflict-filter$X
 
 # what 'all' will build and 'install' will install in gitexecdir,
 # excluding programs for built-in commands
@@ -681,6 +682,7 @@ BUILTIN_OBJS += builtin-var.o
 BUILTIN_OBJS += builtin-verify-pack.o
 BUILTIN_OBJS += builtin-verify-tag.o
 BUILTIN_OBJS += builtin-write-tree.o
+BUILTIN_OBJS += builtin-cdiff.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 EXTLIBS =
builtin-cdiff.c new file +387 -0

387 lines not on this page · raw message

builtin.h +2 -0
index e8202f3..5ec84b8 100644
@@ -121,5 +121,7 @@ extern int cmd_verify_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_show_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_refs(int argc, const char **argv, const char *prefix);
 extern int cmd_replace(int argc, const char **argv, const char *prefix);
+extern int cmd_cdiff(int argc, const char **argv, const char *prefix);
+extern int cmd_cdiff_conflict_filter(int argc, const char **argv, const char *prefix);
 
 #endif
git.c +2 -0
index 90c6daf..6fb7d84 100644
@@ -386,6 +386,8 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "verify-pack", cmd_verify_pack },
 		{ "show-ref", cmd_show_ref, RUN_SETUP },
 		{ "pack-refs", cmd_pack_refs, RUN_SETUP },
+		{ "cdiff", cmd_cdiff },
+		{ "cdiff-conflict-filter", cmd_cdiff_conflict_filter },
 	};
 	int i;
 	static const char ext[] = STRIP_EXTENSION;
Signature · 1 line
tg: (6d81630..) bw/cdiff-conflict-style (depends on: master)