diff mbox

[FFmpeg-devel] doc&tools: Add murge script, for analyzing 3 way conflicts.

Message ID 20160817170644.16566-1-michael@niedermayer.cc
State Superseded
Headers show

Commit Message

Michael Niedermayer Aug. 17, 2016, 5:06 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 doc/libav-merge.txt |  4 ++++
 tools/murge         | 13 +++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100755 tools/murge

Comments

Clément Bœsch Aug. 17, 2016, 5:22 p.m. UTC | #1
On Wed, Aug 17, 2016 at 07:06:44PM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  doc/libav-merge.txt |  4 ++++
>  tools/murge         | 13 +++++++++++++
>  2 files changed, 17 insertions(+)
>  create mode 100755 tools/murge
> 
> diff --git a/doc/libav-merge.txt b/doc/libav-merge.txt
> index 60c953a..47c513a 100644
> --- a/doc/libav-merge.txt
> +++ b/doc/libav-merge.txt
> @@ -103,6 +103,10 @@ It has two modes: merge, and noop. The noop mode creates a merge with no change
>  to the HEAD. You can pass a hash as extra argument to reference a justification
>  (it is common that we already have the change done in FFmpeg).
>  
> +Also see tools/murge, you can copy and paste a 3 way conflict into its stdin
> +and it will display colored diffs. Any arguments to murge (like ones to supress

suppress

> +whitespace differences) are passed into colordiff.
> +

This makes me realize that the script pasted in that document could end up
in the tools directory

>  TODO/FIXME/UNMERGED
>  ===================
>  
> diff --git a/tools/murge b/tools/murge
> new file mode 100755
> index 0000000..b4d88a1
> --- /dev/null
> +++ b/tools/murge
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +grep -A99999 '<<<<<<<' | grep -B99999 '>>>>>>>' >murge.X
> +grep -A9999 '====' murge.X | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|' >murge.theirs

sometimes 99999, sometimes 9999?

> +grep -B9999 '||||' murge.X | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|' >murge.ours
> +grep -B9999 '====' murge.X | grep -A9999 '||||' | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|'  >murge.common
> +
> +colordiff -du $* murge.ours murge.theirs
> +grep . murge.common > /dev/null && colordiff -du $* murge.common murge.theirs
> +grep . murge.common > /dev/null && colordiff -du $* murge.common murge.ours

> +rm murge.theirs murge.common murge.ours murge.X

maybe these files should be in /tmp

i'd also suggest

TMPFILES="murge.theirs murge.common murge.ours murge.X"
trap 'rm -f -- $TMPFILES' EXIT

(stolen from configure)
Clément Bœsch Aug. 17, 2016, 5:26 p.m. UTC | #2
On Wed, Aug 17, 2016 at 07:06:44PM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  doc/libav-merge.txt |  4 ++++
>  tools/murge         | 13 +++++++++++++
>  2 files changed, 17 insertions(+)
>  create mode 100755 tools/murge
> 
> diff --git a/doc/libav-merge.txt b/doc/libav-merge.txt
> index 60c953a..47c513a 100644
> --- a/doc/libav-merge.txt
> +++ b/doc/libav-merge.txt
> @@ -103,6 +103,10 @@ It has two modes: merge, and noop. The noop mode creates a merge with no change
>  to the HEAD. You can pass a hash as extra argument to reference a justification
>  (it is common that we already have the change done in FFmpeg).
>  
> +Also see tools/murge, you can copy and paste a 3 way conflict into its stdin
> +and it will display colored diffs. Any arguments to murge (like ones to supress
> +whitespace differences) are passed into colordiff.
> +
>  TODO/FIXME/UNMERGED
>  ===================
>  
> diff --git a/tools/murge b/tools/murge
> new file mode 100755
> index 0000000..b4d88a1
> --- /dev/null
> +++ b/tools/murge
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +grep -A99999 '<<<<<<<' | grep -B99999 '>>>>>>>' >murge.X

> +grep -A9999 '====' murge.X | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|' >murge.theirs

btw, a few files contain '=====', see for instance libavcodec/h264dec.h

you might want to add an extra ^ marker to make sure it matches the
beginning of the line
Nicolas George Aug. 17, 2016, 5:34 p.m. UTC | #3
Le primidi 1er fructidor, an CCXXIV, Clement Boesch a écrit :
> maybe these files should be in /tmp
> 
> i'd also suggest
> 
> TMPFILES="murge.theirs murge.common murge.ours murge.X"
> trap 'rm -f -- $TMPFILES' EXIT
> 
> (stolen from configure)

Temporary files are annoying and tricky (and configure does not clean up
when it is interrupted).

I suggest to require a more advanced shell (bash or zsh; since this tool is
meant for developers it is acceptable) and use process substitution:

diff <(grep ...) <(grep ...)

It starts both grep processes just like "grep | diff", but then, instead of
connecting the other end of the pipe to diff's standard input, it gives it
the corresponding file name as /dev/fd/42.

If temp files are really necessary because the command does not work with
pipes, then zsh's process substitution can serve:

diff =(grep ...) =(grep ...)

It does the same as <(grep) but with a temp file instead of a pipe; zsh does
all the cleanup for us.

Last of all, if temp files are necessary because the output needs to be
processed several times, zsh's process substitution can still be abused:

function do_the_work {
  grep > $1
  grep > $2
  grep > $3
  diff $1 $2
  diff $2 $3
}
do_the_work =(:) =(:) =(:)

The strange smileys are just process substitution with a dummy command.
Therefore, it starts the function with three temp files. They are all empty,
because the dummy command does not produce output, but they can then be used
in the function.

Regards,
Michael Niedermayer Aug. 18, 2016, 4:35 p.m. UTC | #4
On Wed, Aug 17, 2016 at 07:34:07PM +0200, Nicolas George wrote:
> Le primidi 1er fructidor, an CCXXIV, Clement Boesch a écrit :
> > maybe these files should be in /tmp
> > 
> > i'd also suggest
> > 
> > TMPFILES="murge.theirs murge.common murge.ours murge.X"
> > trap 'rm -f -- $TMPFILES' EXIT
> > 
> > (stolen from configure)
> 
> Temporary files are annoying and tricky (and configure does not clean up
> when it is interrupted).
> 
> I suggest to require a more advanced shell (bash or zsh; since this tool is
> meant for developers it is acceptable) and use process substitution:
> 
> diff <(grep ...) <(grep ...)
> 
> It starts both grep processes just like "grep | diff", but then, instead of
> connecting the other end of the pipe to diff's standard input, it gives it
> the corresponding file name as /dev/fd/42.
> 
> If temp files are really necessary because the command does not work with
> pipes, then zsh's process substitution can serve:
> 
> diff =(grep ...) =(grep ...)
> 
> It does the same as <(grep) but with a temp file instead of a pipe; zsh does
> all the cleanup for us.
> 
> Last of all, if temp files are necessary because the output needs to be
> processed several times, zsh's process substitution can still be abused:
> 
> function do_the_work {
>   grep > $1
>   grep > $2
>   grep > $3
>   diff $1 $2
>   diff $2 $3
> }
> do_the_work =(:) =(:) =(:)
> 
> The strange smileys are just process substitution with a dummy command.
> Therefore, it starts the function with three temp files. They are all empty,
> because the dummy command does not produce output, but they can then be used
> in the function.

It seems you are very interrested in this, this mail after all is
several times longer than the script its about.
maybe it would be easiest if you take over the maintaince of it ?
I used the script for years and never cleaned anything up yet i have
no match for "locate murge" except the script itself, also i dont
have zsh installed
If i would rewrite it based on zsh (which i dont know) fixing
a bug (which apparently never occured in years of actual use)
i have the fear the result will be more buggy, especially as iam not
using it currently and wouldnt notice a new bug ...

These changes should either be done by someone using it or someone
knowing the features he is using.

[...]
diff mbox

Patch

diff --git a/doc/libav-merge.txt b/doc/libav-merge.txt
index 60c953a..47c513a 100644
--- a/doc/libav-merge.txt
+++ b/doc/libav-merge.txt
@@ -103,6 +103,10 @@  It has two modes: merge, and noop. The noop mode creates a merge with no change
 to the HEAD. You can pass a hash as extra argument to reference a justification
 (it is common that we already have the change done in FFmpeg).
 
+Also see tools/murge, you can copy and paste a 3 way conflict into its stdin
+and it will display colored diffs. Any arguments to murge (like ones to supress
+whitespace differences) are passed into colordiff.
+
 TODO/FIXME/UNMERGED
 ===================
 
diff --git a/tools/murge b/tools/murge
new file mode 100755
index 0000000..b4d88a1
--- /dev/null
+++ b/tools/murge
@@ -0,0 +1,13 @@ 
+#!/bin/sh
+
+grep -A99999 '<<<<<<<' | grep -B99999 '>>>>>>>' >murge.X
+grep -A9999 '====' murge.X | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|' >murge.theirs
+grep -B9999 '||||' murge.X | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|' >murge.ours
+grep -B9999 '====' murge.X | grep -A9999 '||||' | egrep -v '=======|<<<<<<<|>>>>>>>|\|\|\|\|\|\|\|'  >murge.common
+
+colordiff -du $* murge.ours murge.theirs
+grep . murge.common > /dev/null && colordiff -du $* murge.common murge.theirs
+grep . murge.common > /dev/null && colordiff -du $* murge.common murge.ours
+rm murge.theirs murge.common murge.ours murge.X
+
+