[patch 0/1] New feature for splitdiff

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch 0/1] New feature for splitdiff

Wolfram Sang-3
Hello,

I missed a feature for splitdiff and took an hour to implement it. Now, using
the option "-t", you can recreate the directory structure from a combined set
of diffs. See the description of the patch for more information. Hope you like
it and consider it for inclusion.

Kind regards,

   Wolfram Sang

Reply | Threaded
Open this post in threaded view
|

[patch 1/1] splitdiff: add option to extract the whole tree of subdiffs

Wolfram Sang-3
Sometimes I get a huge patch blob (a couple of MB) which touches several files
all over a base directory (in this case the linux kernel tree). This new option
to splitdiff creates the path for every subdiff inside the blob and extracts it
to there. So, in the end, you get a directory tree you are familiar with and
can easily find the small diffs which are of interest to you. Also, useful for
grepping in certain parts of the tree.

Signed-off-by: Wolfram Sang <[hidden email]>
---
 splitdiff.in |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Index: splitdiff.in
===================================================================
--- splitdiff.in.orig
+++ splitdiff.in
@@ -18,7 +18,10 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 use Getopt::Std;
-getopts('p:v-:ad', \%opts);
+use File::Basename;
+use File::Path;
+
+getopts('p:v-:adt', \%opts);
 if ($opts{'-'} && $opts{'-'} eq 'version') {
     print "splitdiff - patchutils version @VERSION@\n";
     exit 0;
@@ -29,6 +32,7 @@ if ($opts{'-'} && $opts{'-'} eq 'help')
     print "  -a              split out every single file-level patch\n";
     print "  -p N            pathname components to ignore\n";
     print "  -d              use output filenames like a_b.c for a/b.c\n";
+    print "  -t              create the whole tree of subdiffs (selects -a, drops -d)";
     exit 0;
 }
 
@@ -44,6 +48,10 @@ sub process {
     if ($opts{d}) {
  $out = $_[2];
  $out =~ s,/,_,g;
+    } elsif ($opts{t})  {
+     my (undef, $dir) = fileparse($_[2]);
+     mkpath $dir;
+     $out = "$_[2].diff";
     } else {
  $out = sprintf ("%s.part%03d", $ARGV[0], $part);
     }
@@ -66,6 +74,12 @@ if($#ARGV != 0) {
 $getlist = 'lsdiff -n ';
 $getlist .= '--strip='.$opts{p}.' ' if ($opts{p});
 $getlist .= $ARGV[0]; # Yuck.  How do you do this properly in perl?
+
+if ($opts{t}) {
+    $opts{a} = 1;
+    undef $opts{d};
+}
+
 open(LIST, '-|', $getlist) or die "Can't run lsdiff";
 @list = <LIST>;
 close LIST;

Reply | Threaded
Open this post in threaded view
|

[patch v2] splitdiff: add option to extract the whole tree of subdiffs

Wolfram Sang-3
Sometimes I get a huge patch blob (a couple of MB) which touches several files
all over a base directory (in this case the linux kernel tree). This new option
to splitdiff creates the path for every subdiff inside the blob and extracts it
to there. So, in the end, you get a directory tree you are familiar with and
can easily find the small diffs which are of interest to you. Also, useful for
grepping in certain parts of the tree.

Signed-off-by: Wolfram Sang <[hidden email]>
---

Changes since V1:

  - make it a p1-patch
  - add '\n' to help-test

Stupid mistakes, sorry for the noise.

 splitdiff.in |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Index: splitdiff.in
===================================================================
--- a/splitdiff.in.orig
+++ b/splitdiff.in
@@ -18,7 +18,10 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 use Getopt::Std;
-getopts('p:v-:ad', \%opts);
+use File::Basename;
+use File::Path;
+
+getopts('p:v-:adt', \%opts);
 if ($opts{'-'} && $opts{'-'} eq 'version') {
     print "splitdiff - patchutils version @VERSION@\n";
     exit 0;
@@ -29,6 +32,7 @@ if ($opts{'-'} && $opts{'-'} eq 'help')
     print "  -a              split out every single file-level patch\n";
     print "  -p N            pathname components to ignore\n";
     print "  -d              use output filenames like a_b.c for a/b.c\n";
+    print "  -t              create the whole tree of subdiffs (selects -a, drops -d)\n";
     exit 0;
 }
 
@@ -44,6 +48,10 @@ sub process {
     if ($opts{d}) {
  $out = $_[2];
  $out =~ s,/,_,g;
+    } elsif ($opts{t})  {
+     my (undef, $dir) = fileparse($_[2]);
+     mkpath $dir;
+     $out = "$_[2].diff";
     } else {
  $out = sprintf ("%s.part%03d", $ARGV[0], $part);
     }
@@ -66,6 +74,12 @@ if($#ARGV != 0) {
 $getlist = 'lsdiff -n ';
 $getlist .= '--strip='.$opts{p}.' ' if ($opts{p});
 $getlist .= $ARGV[0]; # Yuck.  How do you do this properly in perl?
+
+if ($opts{t}) {
+    $opts{a} = 1;
+    undef $opts{d};
+}
+
 open(LIST, '-|', $getlist) or die "Can't run lsdiff";
 @list = <LIST>;
 close LIST;


--
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

signature.asc (204 bytes) Download Attachment