Code

git-notify: Be careful with "--no-merge"
authorHolger Weiss <holger@zedat.fu-berlin.de>
Fri, 2 Jul 2010 13:28:35 +0000 (15:28 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Fri, 2 Jul 2010 13:28:35 +0000 (15:28 +0200)
The "-X" option (which asks git-notify to not report merge commits) was
implemented by setting the "--no-merge" option on each invocation of
git-rev-list(1).  However, we do not only use git-rev-list(1) to get the
list of new commits, but also to check whether the old branch head (or
tag) is a parent of the new branch head (or tag).  For this latter
check, the "--no-merge" option should not be set; otherwise, git-notify
would be fooled to believe that the branch has been rewritten if the old
head was a merge commit.

tools/git-notify

index 088a58046331c7cbb2ad949d6ee4e8c4c151e27c..851429658fd238d820a06e6d6e2db62bea3431b3 100755 (executable)
@@ -69,6 +69,9 @@ my $gitweb_url = git_config( "notify.baseurl" );
 # abbreviate the SHA1 name within gitweb URLs (can be set with the -z option)
 my $abbreviate_url = git_config( "notify.shorturls" );
 
 # abbreviate the SHA1 name within gitweb URLs (can be set with the -z option)
 my $abbreviate_url = git_config( "notify.shorturls" );
 
+# don't report merge commits (can be set with the -X option)
+my $ignore_merges = git_config( "notify.ignoremerges" );
+
 # enable compatibility with SourceForge's gitweb (can be set with the -S option)
 my $sourceforge = git_config( "notify.sourceforge" );
 
 # enable compatibility with SourceForge's gitweb (can be set with the -S option)
 my $sourceforge = git_config( "notify.sourceforge" );
 
@@ -99,9 +102,6 @@ my $state_file = git_config( "notify.statefile" );
 # umask for creating the state file (can be set with -U option)
 my $mode_mask = git_config( "notify.umask" ) || 002;
 
 # umask for creating the state file (can be set with -U option)
 my $mode_mask = git_config( "notify.umask" ) || 002;
 
-# Extra options to git rev-list
-my @revlist_options;
-
 sub usage()
 {
     print "Usage: $0 [options] [--] old-sha1 new-sha1 refname\n";
 sub usage()
 {
     print "Usage: $0 [options] [--] old-sha1 new-sha1 refname\n";
@@ -145,7 +145,7 @@ sub git_rev_list(@)
     die "Cannot open pipe: $!" if not defined $pid;
     if (!$pid)
     {
     die "Cannot open pipe: $!" if not defined $pid;
     if (!$pid)
     {
-        exec "git", "rev-list", "--reverse", @revlist_options, @args or die "Cannot execute rev-list: $!";
+        exec "git", "rev-list", "--reverse", @args or die "Cannot execute rev-list: $!";
     }
     while (<REVLIST>)
     {
     }
     while (<REVLIST>)
     {
@@ -181,6 +181,7 @@ sub get_new_commits($$)
 
     @args = ( "^$old_sha1" ) unless $old_sha1 eq '0' x 40;
     push @args, $new_sha1, @exclude_list;
 
     @args = ( "^$old_sha1" ) unless $old_sha1 eq '0' x 40;
     push @args, $new_sha1, @exclude_list;
+    unshift @args, "--no-merges" if $ignore_merges;
 
     my $revlist = git_rev_list(@args);
 
 
     my $revlist = git_rev_list(@args);
 
@@ -306,8 +307,8 @@ sub parse_options()
         elsif ($arg eq '-U') { $mode_mask = shift @ARGV; }
         elsif ($arg eq '-u') { $gitweb_url = shift @ARGV; }
         elsif ($arg eq '-i') { push @include_list, shift @ARGV; }
         elsif ($arg eq '-U') { $mode_mask = shift @ARGV; }
         elsif ($arg eq '-u') { $gitweb_url = shift @ARGV; }
         elsif ($arg eq '-i') { push @include_list, shift @ARGV; }
+        elsif ($arg eq '-X') { $ignore_merges = 1; }
         elsif ($arg eq '-x') { push @exclude_list, shift @ARGV; }
         elsif ($arg eq '-x') { push @exclude_list, shift @ARGV; }
-        elsif ($arg eq '-X') { push @revlist_options, "--no-merges"; }
         elsif ($arg eq '-z') { $abbreviate_url = 1; }
         elsif ($arg eq '-d') { $debug++; }
         else { usage(); }
         elsif ($arg eq '-z') { $abbreviate_url = 1; }
         elsif ($arg eq '-d') { $debug++; }
         else { usage(); }