[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdesdk/scripts
From:       Thiago Macieira <thiago () kde ! org>
Date:       2006-02-01 10:51:52
Message-ID: 1138791112.846742.1837.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 504489 by thiago:

A little tweaking and a bit of a usage explanation to make the user experience better

 M  +104 -33   svnintegrate  


--- trunk/KDE/kdesdk/scripts/svnintegrate #504488:504489
@@ -5,6 +5,53 @@
 # This file is distributed under the Artistic License version 2.1
 #
 
+# Usage:
+#  svnintegrate [-n] [-v] [-q] [-b branchname] [filename]
+#
+#  Where:
+#   -n		dry run - do not actually run commands that modify sources
+#		can be used to determine the changeset that would be backported
+#   -v		verbose - show the commands being executed
+#   -q		quiet - do not output some unnecessary messages
+#   -b branch	the branch to merge into [default: trunk]
+#   filename	the file whose last change should be integrated
+#               if unspecified, the last change for the current directory will
+#               be used
+#
+#  Also note that svnintegrate will try to locate ALL files modified
+#  in the changeset being integrated. So you don't need to specify all
+#  of them in the command line. However, they must all be present in
+#  the current directory or a subdirectory.
+#  (If they cannot be found, svnintegrate will tell you)
+#
+#  About branch names:
+#  svnintegrate tries hard to understand the KDE branch-naming
+#  scheme. So, in many times, it is enough to simply tell it the
+#  version of the branch you're integrating into.
+#
+#  Examples:
+#    switch		integrating from	integrate to
+#   -b trunk		/branches/KDE/3.5	/trunk/KDE
+#   -b trunk/extragear/graphics
+#			/branches/amarok/1.3	/trunk/extragear/graphics/amarok
+#   -b 3.5		/trunk/KDE/kdelibs	/branches/KDE/3.5/kdelibs
+#   -b 3.5		/branches/KDE/3.4	/branches/KDE/3.5
+#   -b tags/3.5.0	/branches/KDE/3.5	/tags/KDE/3.5.0
+#   -b work/my-branch	/branches/KDE/3.4	/branches/work/my-branch
+#   -b work/my-branch	/branches/KDE/3.4/kdelibs  /branches/work/my-branch
+#   -b work/my-branch	/trunk/KDE/kdepim/kmail	/branches/work/my-branch
+#
+
+#
+# Wanted features:
+#   Better branch guessing:
+#   - support for integrating from trunk/{playground,kdereview,extragear}
+#   - support for integrating from branches/work
+#   Other features:
+#   - support for integrating to checked-out branch
+#   - support for integrating multiple revisions
+#  
+
 use XML::DOM;
 use strict;
 
@@ -53,8 +100,10 @@
 sub getLastCommitInfo($)
 {
   my $target = @_[0];
+  my $rev = "-rCOMMITTED";
+  $rev = "-r$revision" if (defined($revision));
   
-  open(LOG, "-|", "svn", "log", "--xml", "-v", "-rCOMMITTED", $target)
+  open(LOG, "-|", "svn", "log", "--xml", "-v", $rev, $target)
     or die("Could not run svn");
     
   my $log;
@@ -67,6 +116,12 @@
   # now parse it
   my $parser = new XML::DOM::Parser;
   my $doc = $parser->parse($log);
+
+  unless ($doc->getElementsByTagName("logentry")->getLength())
+  {
+    print STDERR "Cannot find revision $revision in the current directory.\n";
+    exit(1);
+  }
   
   $revision = $doc->getElementsByTagName("logentry")->item(0)->getAttribute("revision");
   $lastCommitMsg = $doc->getElementsByTagName("msg")->item(0)->getFirstChild()->toString();
@@ -85,10 +140,10 @@
 sub transformToBranch($)
 {
   my $path = @_[0];
-  if (length($branch) == 0 or $branch eq "trunk")
+  if ($branch =~ /^trunk/)
   {
     # transform to trunk
-    $path =~ s,^/(branches|tags)/([^/]+)/[^/]+,/trunk/\2,o;
+    $path =~ s,^/(branches|tags)/([^/]+)/[^/]+,/$branch/\2,o;
     return $path;
   }
   elsif ($branch !~ m,/,)
@@ -188,7 +243,7 @@
 
 sub run(@)
 {
-  if ($dryRun or $verbose)
+  if ($dryRun || $verbose)
   {
     print join(" ", @_) . "\n";
   }
@@ -225,6 +280,7 @@
   }
   
   run("rm", "svn-commit.tmp") if (-e "svn-commit.tmp");
+  run("rm", "svn-commit.tmp~") if (-e "svn-commit.tmp~");
 }
 
 sub switchAllFiles()
@@ -237,14 +293,6 @@
   {
     my $output = run("svn", "switch", $svnroot . $target . "/$file", $file);
     push(@switchedFilenames, $file);
-
-    if ($output =~ /^D/)
-    {
-      print STDERR "I cannot handle file deletions, sorry (\'$file\').\n";
-      print STDERR "You will probably have to run \'svn up\' to recover the file.\n";
-      rollback();
-      exit 1;
-    }
   }
 }
 
@@ -347,13 +395,29 @@
   my $output = run("svn", "merge", "-r", ($revision - 1) . ":" . $revision, $svnroot . $dirname);
   my @lines = split(/\r?\n/, $output);
 
-  foreach my $line (@lines)
+  if (scalar @lines)
   {
-    if ($line =~ /^C +(.+)$/)
+    foreach my $line (@lines)
     {
-      push(@conflictedFilenames, $1)
+      if ($line =~ /^C +(.+)$/)
+      {
+        push(@conflictedFilenames, $1)
+      }
+      if ($line =~ /^D +(.+)$/)
+      {
+        print STDERR "I cannot handle file deletions, sorry (\'$1\').\n";
+	print STDERR "You will probably have to run \'svn up\' to recover the file.\n";
+	rollback();
+	exit 1;
+      }
     }
   }
+  else
+  {
+    print "No files were changed: this changeset has already been integrated.\n";
+    rollback();
+    exit(0);
+  }
 
   foreach my $conflict (@conflictedFilenames)
   {
@@ -361,15 +425,6 @@
   }
 }
 
-sub showDiff()
-{
-  print "\nMerging successful\n";
-  print "Press enter to see the diff to be committed\n";
-
-  <STDIN>;
-  run("svn diff ". join(" ", @filenames) . " | $PAGER");
-}
-
 sub createLogMessage()
 {
   open(LOG, ">svn-commit.tmp");
@@ -389,26 +444,29 @@
 
 sub editLogMessage()
 {
+  print "\nMerging successful\n";
   while (1)
   {
-    print "Press Enter to accept the log message and commit\n";
-    print "Press 'Q' to revert and quit\n";
-    print "Press any other key to edit the log message\n";
+    print "Press (C) to commit, (D) to see the diff, (Q) to quit or (E) to edit the log\n";
     
     my $answer = <STDIN>;
     $answer =~ s/\r?\n$//;
-    $answer =~ tr/Q/q/;
+    $answer =~ tr/A-Z/a-z/;
     if ($answer eq "q")
     {
       rollback();
       exit(0);
     }  
-    elsif (length($answer))
+    elsif ($answer eq "e")
     {
       run($EDITOR, "svn-commit.tmp");
     }
-    else
+    elsif ($answer eq "d")
     {
+      run("svn diff ". join(" ", @filenames) . " | $PAGER");
+    }
+    elsif ($answer eq "c")
+    {
       return;
     }
   }
@@ -430,8 +488,8 @@
 
 $dryRun = 0;
 $quiet = 0;
-$verbose = 1;
-$branch = "";
+$verbose = 0;
+$branch = "trunk";
 while (@ARGV)
   {
     my $arg = shift @ARGV;
@@ -457,8 +515,19 @@
  
       $branch = shift @ARGV;
     }
+    elsif ($arg eq "-r")
+    {
+      unless (@ARGV)
+      {
+        print STDERR "Option -r requires an argument\n";
+        exit 1;
+      }
+
+      $revision = shift @ARGV;
+    }
     else
     {
+      unshift @ARGV, $arg;
       last;
     }
   }
@@ -469,8 +538,10 @@
 showLog();
 findAllFiles();
 switchAllFiles();
+
+exit(0) if ($dryRun);
+
 mergeRevision();
-showDiff();
 createLogMessage();
 editLogMessage();
 commit();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic