Subject: [PATCH] git send-email: allow any rev-list option as an argument.

From: Pierre Habouzit <[email-masked]>
Date: Fri, 31 Oct 2008 17:52:05 +0100

Signed-off-by: Pierre Habouzit <[email-masked]>
---

  One can consider to squash that on top of
  <[email-masked]> to be able to pass
  all non path arguments before a possible '--' to git format-patch.

  The downside of this patch is that:

    git send-email -C -C -M origin/next

  will send the content of origin/next if it's an existing file. Of course a
  disambiguation can be:

    git send-email -C -C -M refs/heads/origin/next

  But again if this file also exists, one is basically screwed. I see no
  proper way to fix that, unless to change git-send-email behaviour at once.

  Though I believe this semantics to be better than the one in the previous
  patch, as it's often a good idea to pass -M -C -C to format-patch, which is
  currently impossible. It also allow revision lists to work as expected (wrt
  --all, --not and so on).

  Comments are welcomed.

 Documentation/git-send-email.txt |    2 +-
 git-send-email.perl              |   19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 9ee81d5..39d6da9 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -8,7 +8,7 @@ git-send-email - Send a collection of patches as emails
 
 SYNOPSIS
 --------
-'git send-email' [options] <file|directory|rev-list>...
+'git send-email' [options] <file|directory|rev-list options>...

 DESCRIPTION
diff --git a/git-send-email.perl b/git-send-email.perl
index 5c189a7..8667e0b 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -25,6 +25,8 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir /;
 use Git;
 
+Getopt::Long::Configure qw/ pass_through /;
+
 package FakeTerm;
 sub new {
 	my ($class, $reason) = @_;
@@ -39,7 +41,7 @@ package main;
 
 sub usage {
 	print <<EOT;
-git send-email [options] <file | directory | rev-list >
+git send-email [options] <file | directory | rev-list options >
 
   Composing:
     --from                  <str>  * Email From:
@@ -383,8 +385,12 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
 
 # Now that all the defaults are set, process the rest of the command line
 # arguments and collect up the files that need to be processed.
-for my $f (@ARGV) {
-	if (-d $f) {
+my @rev_list_opts;
+while (my $f = pop @ARGV) {
+	if ($f eq "--") {
+		push @rev_list_opts, "--", @ARGV;
+		@ARGV = ();
+	} elsif (-d $f) {
 		opendir(DH,$f)
 			or die "Failed to opendir $f: $!";
 
@@ -394,11 +400,14 @@ for my $f (@ARGV) {
 	} elsif (-f $f or -p $f) {
 		push @files, $f;
 	} else {
-		my $tempdir = tempdir(CLEANUP => 1);
-		push @files, $repo->command('format-patch', '-o', $tempdir, $f);
+		push @rev_list_opts, $f;
 	}
 }
 
+if (@rev_list_opts) {
+	push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);
+}
+
 if ($validate) {
 	foreach my $f (@files) {
 		unless (-p $f) {
-- 
1.6.0.3.791.g15769.dirty