quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] Annotate any version of a file


From: Jean Delvare
Subject: [Quilt-dev] Annotate any version of a file
Date: Sat, 10 Sep 2005 22:41:06 +0200

Hi all,

I might need to be able to annotate any version of a file, rather than
its current state, in a near future. So I started hacking the quilt
annotate command. Now I have working code, so I thought I'd just post it
here for review and comments. In particular, I would like to know if
there is a general interest in having this feature added to quilt.

Concretely, I have been adding a -p option to annotate, and when used,
the annotation loop stops at this patch rather than going on up to the
top patch. My tests are successful, and I've extended the test suite to
test this option.

You'll see a comment about next_patch needing to be computed again -
that's the point that raised my earlier questions about variables and
pipes. If anyone can find a more elegant implementation, please speak
up.

Two more notes:

1* "quilt annotate -p $(quilt top) file" is the same as "quilt annotate
file", so both commands should always behave the same.

2* I replaced a call to print_series() by a call to applied_patches() in
the process (in the case -p isn't used) as it seemed more optimal to me
that way. If I'm wrong, just let me know. If I'm not, then this change
can go in even if this patch doesn't.

Oh, and congratulations to Andreas, this annotate command is really a
killer feature :)

Thanks.

Index: bash_completion
===================================================================
RCS file: /cvsroot/quilt/quilt/bash_completion,v
retrieving revision 1.19
diff -u -r1.19 bash_completion
--- bash_completion     26 Aug 2005 10:20:48 -0000      1.19
+++ bash_completion     9 Sep 2005 20:18:02 -0000
@@ -132,8 +132,15 @@
           esac
           ;;
        annotate)
-          _quilt_comfile 
-          COMPREPLY=( address@hidden:-} $( compgen -W "-h" -- $cur ) )
+          case $prev in
+            -p)
+               COMPREPLY=( $( compgen -W "$(quilt applied)" -- $cur ) )
+               ;;
+            *)
+               _quilt_comfile
+               COMPREPLY=( address@hidden:-} $( compgen -W "-p -h" -- $cur ) )
+               ;;
+          esac
           ;;
        applied) 
           COMPREPLY=( $( compgen -W "-h $(quilt applied)" -- $cur ) )
Index: quilt/annotate.in
===================================================================
RCS file: /cvsroot/quilt/quilt/quilt/annotate.in,v
retrieving revision 1.5
diff -u -r1.5 annotate.in
--- quilt/annotate.in   18 Jul 2005 10:18:13 -0000      1.5
+++ quilt/annotate.in   9 Sep 2005 20:18:02 -0000
@@ -19,12 +19,16 @@
 
 usage()
 {
-       printf $"Usage: quilt annotate {file}\n"
+       printf $"Usage: quilt annotate [-p patch] {file}\n"
        if [ x$1 = x-h ]
        then
                printf $"
 Print an annotated listing of the specified file showing which
 patches modify which lines.
+
+-p patch
+       Annotate the file as it was right after applying this specific
+       patch, rather than the current top patch.
 "
                exit 0
        else
@@ -89,7 +93,7 @@
        exec 4<&-
 }
 
-options=`getopt -o h -- "$@"`
+options=`getopt -o p:h -- "$@"`
 
 if [ $? -ne 0 ]
 then
@@ -101,6 +105,13 @@
 while true
 do
        case "$1" in
+       -p)
+               if ! opt_patch=$(find_patch $2)
+               then
+                       printf $"Patch %s is not in series\n" "$2" >&2
+                       exit 1
+               fi
+               shift 2 ;;
        -h)
                usage -h ;;
        --)
@@ -115,7 +126,20 @@
 fi
 opt_file="$SUBDIR$1"
 
-for patch in $(cat_series); do
+if [ -n "$opt_patch" ]
+then
+       if ! is_applied "$opt_patch"
+       then
+               printf $"Patch %s is not applied\n" \
+                      "$(print_patch $opt_patch)" >&2
+               exit 1
+       fi
+       patch_list="$(applied_before "$opt_patch") $opt_patch"
+else
+       patch_list="$(applied_patches)"
+fi
+
+for patch in $patch_list; do
        if [ -f "$(backup_file_name $patch "$opt_file")" ]
        then
                address@hidden"$patch"
@@ -148,11 +172,23 @@
 empty_file ${patches[0]} "$opt_file" > $template
 for ((n = 0; n < address@hidden; n++))
 do
-       annotation_for "${patches[$n]}" "${patches[$((n+1))]}" "$opt_file" \
-                      $((n+1))
+       next_patch="${patches[$((n+1))]}"
+       [ -z "$next_patch" -a -n "$opt_patch" ] && \
+       next_patch="$(next_patch_for_file ${patches[$n]} "$opt_file")"
+       annotation_for "${patches[$n]}" "$next_patch" "$opt_file" $((n+1))
 done \
 | @PATCH@ $template
-merge_files $template "$opt_file"
+
+# Too bad we have to compute $next_patch again, it had the correct value
+# at the end of the for loop.
+[ -n "$opt_patch" ] && \
+next_patch="$(next_patch_for_file ${patches[((address@hidden))]} "$opt_file")"
+if [ -n "$next_patch" ]
+then
+       merge_files $template $(backup_file_name "$next_patch" "$opt_file")
+else
+       merge_files $template "$opt_file"
+fi
 
 echo
 for ((n = 0; n < address@hidden; n++))
Index: test/annotate.test
===================================================================
RCS file: /cvsroot/quilt/quilt/test/annotate.test,v
retrieving revision 1.3
diff -u -r1.3 annotate.test
--- test/annotate.test  9 Sep 2005 18:27:51 -0000       1.3
+++ test/annotate.test  9 Sep 2005 20:18:02 -0000
@@ -62,6 +62,29 @@
        > 2     patches/patch2
        > 3     patches/patch3
 
+       $ quilt annotate -p patch3 foo
+       >       foo
+       > 2     baz
+       >
+       > 1     patches/patch
+       > 2     patches/patch2
+       > 3     patches/patch3
+
+       $ quilt annotate -p patch2 foo
+       >       foo
+       > 1     Bar
+       > 2     baz
+       >
+       > 1     patches/patch
+       > 2     patches/patch2
+
+       $ quilt annotate -p patch foo
+       >       foo
+       > 1     Bar
+       > 1     Baz
+       >
+       > 1     patches/patch
+
        $ quilt new patch4
        > Patch patches/patch4 is now on top
 


-- 
Jean Delvare
-- 
Jean Delvare




reply via email to

[Prev in Thread] Current Thread [Next in Thread]