osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Script to instrument a 'svn diff' output to be more useful


Hi,

From time to time, I try to synch 2.4.x with trunk in order to avoid to many differences between the 2. It is just small steps, but it may avoid some nightmares when something needs to be backported. To many differences lead to merge issue.
So, IMHO, the closest, the better.

I used to do it with a simple 'svn diff' + manual inspection of what 'looks' easy and safe to backport. Then 'svn blame' to spot the corresponding commit, then 'svn merge --dry-run' to see if it can be merged as-is.

This is tedious. So today, I wrote a small script that automates most of the process. It merges the 'svn diff' with the 'svn blame' output in order to have most of the relevant information at the same place.

Then, I can easily find commit numbers, who did it, if other commits numbers are around, search in the 2.4.x/trunk diff file...

Very helpful to me (I wanted to write something like that for years).
I think that it could be also useful for others for digging the code and/or proposing backports. It also helps to spot its own pieces of code that have never been backported :)


This not httpd specific and it could be used to have a more instrumented 'svn diff' output to diff two branches of a svn repository.


First, make the 'normal' diff file:
diff -rup -X httpd_exclude.txt svn_httpd_2.4.x/ svn_httpd_trunk_unmodified/ > ~/diff_httpd_2.4.diff

Then:
./my_history_httpd_2.4 diff_httpd_2.4.diff > diff_httpd_2.4_with_history.diff

The 'my_history_httpd_2.4' script and the corresponding outputs are attached. Enjoy.

Any feedback and/or improvement appreciated.

CJ
#!/bin/bash

tempfile="tmp.tmp";

while IFS='' read -r line || [[ -n "$line" ]];
do
    # Look for new file to start with
    #    diff -rup -X httpd_exclude.txt acinclude.m4 svn_httpd_trunk_unmodified/acinclude.m4
    regex="^diff.* ([^ ]+)$";
    if [[ $line =~ $regex ]];
    then
        # Run svn blame on it and save the result in a temp file
        svn blame ${BASH_REMATCH[1]} > $tempfile;
        # Copy this line as-is
        echo $line;
        continue;
    fi

    # Copy lines starting with "---", "+++" as-is
    #    --- acinclude.m4	2018-02-10 09:58:44.297193986 +0100
    #    +++ svn_httpd_trunk_unmodified/acinclude.m4	2018-05-26 14:14:27.248401946 +0200
    regex="^(---|\+\+\+)";
    if [[ $line =~ $regex ]];
    then
        # Copy this line as-is
        echo $line;
        continue;
    fi

    # We have found a new hunk
    #    @@ -45,6 +45,7 @@ AC_DEFUN([APACHE_GEN_CONFIG_VARS],[
    regex="^@@.*\+([0-9]+)";
    if [[ $line =~ $regex ]];
    then
        # Save the position in the newer file
        pos=${BASH_REMATCH[1]};
        # Copy this line as-is
        echo $line;
        continue;
    fi

    # Copy lines starting with SPACE with some additional spaces
    # Keep the leading " " at the beginning to have it look like a real diff file
    #    APACHE_SUBST(installbuilddir)
    regex="^ ";
    if [[ $line =~ $regex ]];
    then
        # Keep the first char as-is and add some spaces
        echo "${line:0:1}                   ${line:1}";
        # +1 in the context
        pos="$(($pos + 1))";
        continue;
    fi

    # Copy lines starting with "-" with some additional spaces
    # Keep the leading "-" at the beginning to have it look like a real diff file
    #    -            cat >$mpmpath/modules.mk<<EOF
    regex="^-";
    if [[ $line =~ $regex ]];
    then
        # Keep the first char as-is and add some spaces
        echo "${line:0:1}                   ${line:1}";
        continue;
    fi

    # Copy lines starting with "+", with some blame information
    # Keep the leading "+" at the beginning to have it look like a real diff file
    #    +  APACHE_SUBST(davlockdb)
    regex="^\+";
    if [[ $line =~ $regex ]];
    then
        printf "+";
        sed "${pos}q;d" $tempfile;
        # +1 in the context
        pos="$(($pos + 1))";
        continue;
    fi
    
    # any other with another pattern silently ignored (missing files, binary files...)
done < "$1"      

# Clean-up
rm $tempfile

Attachment: diff_httpd_2.4_with_history.diff.bz2
Description: Binary data

Attachment: diff_httpd_2.4.diff.bz2
Description: Binary data