15
15
#include "patch-ids.h"
16
16
#include "refs.h"
17
17
#include "run-command.h"
18
+ #include "shortlog.h"
18
19
19
20
static int default_show_root = 1 ;
20
21
static const char * fmt_patch_subject_prefix = "PATCH" ;
@@ -621,9 +622,10 @@ static void gen_message_id(struct rev_info *info, char *base)
621
622
info -> message_id = strbuf_detach (& buf , NULL );
622
623
}
623
624
624
- static void make_cover_letter (struct rev_info * rev ,
625
- int use_stdout , int numbered , int numbered_files ,
626
- struct commit * origin , struct commit * head )
625
+ static void make_cover_letter (struct rev_info * rev , int use_stdout ,
626
+ int numbered , int numbered_files ,
627
+ struct commit * origin ,
628
+ int nr , struct commit * * list , struct commit * head )
627
629
{
628
630
const char * committer ;
629
631
const char * origin_sha1 , * head_sha1 ;
@@ -632,7 +634,9 @@ static void make_cover_letter(struct rev_info *rev,
632
634
const char * body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n" ;
633
635
const char * msg ;
634
636
const char * extra_headers = rev -> extra_headers ;
637
+ struct shortlog log ;
635
638
struct strbuf sb ;
639
+ int i ;
636
640
const char * encoding = "utf-8" ;
637
641
638
642
if (rev -> commit_format != CMIT_FMT_EMAIL )
@@ -642,7 +646,6 @@ static void make_cover_letter(struct rev_info *rev,
642
646
NULL : "cover-letter" , 0 , rev -> total ))
643
647
return ;
644
648
645
- origin_sha1 = sha1_to_hex (origin ? origin -> object .sha1 : null_sha1 );
646
649
head_sha1 = sha1_to_hex (head -> object .sha1 );
647
650
648
651
log_write_email_headers (rev , head_sha1 , & subject_start , & extra_headers );
@@ -660,21 +663,19 @@ static void make_cover_letter(struct rev_info *rev,
660
663
661
664
strbuf_release (& sb );
662
665
666
+ shortlog_init (& log );
667
+ for (i = 0 ; i < nr ; i ++ )
668
+ shortlog_add_commit (& log , list [i ]);
669
+
670
+ shortlog_output (& log );
671
+
663
672
/*
664
- * We can only do diffstat with a unique reference point, and
665
- * log is a bit tricky, so just skip it.
673
+ * We can only do diffstat with a unique reference point
666
674
*/
667
675
if (!origin )
668
676
return ;
669
677
670
- argv [0 ] = "shortlog" ;
671
- argv [1 ] = head_sha1 ;
672
- argv [2 ] = "--not" ;
673
- argv [3 ] = origin_sha1 ;
674
- argv [4 ] = "--" ;
675
- argv [5 ] = NULL ;
676
- fflush (stdout );
677
- run_command_v_opt (argv , RUN_GIT_CMD );
678
+ origin_sha1 = sha1_to_hex (origin -> object .sha1 );
678
679
679
680
argv [0 ] = "diff" ;
680
681
argv [1 ] = "--stat" ;
@@ -727,6 +728,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
727
728
int ignore_if_in_upstream = 0 ;
728
729
int thread = 0 ;
729
730
int cover_letter = 0 ;
731
+ int boundary_count = 0 ;
730
732
struct commit * origin = NULL , * head = NULL ;
731
733
const char * in_reply_to = NULL ;
732
734
struct patch_ids ids ;
@@ -917,19 +919,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
917
919
}
918
920
if (cover_letter ) {
919
921
/* remember the range */
920
- int negative_count = 0 ;
921
922
int i ;
922
923
for (i = 0 ; i < rev .pending .nr ; i ++ ) {
923
924
struct object * o = rev .pending .objects [i ].item ;
924
- if (o -> flags & UNINTERESTING ) {
925
- origin = (struct commit * )o ;
926
- negative_count ++ ;
927
- } else
925
+ if (!(o -> flags & UNINTERESTING ))
928
926
head = (struct commit * )o ;
929
927
}
930
- /* Multiple origins don't work for diffstat. */
931
- if (negative_count > 1 )
932
- origin = NULL ;
933
928
/* We can't generate a cover letter without any patches */
934
929
if (!head )
935
930
return 0 ;
@@ -941,8 +936,17 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
941
936
if (!use_stdout )
942
937
realstdout = xfdopen (xdup (1 ), "w" );
943
938
944
- prepare_revision_walk (& rev );
939
+ if (prepare_revision_walk (& rev ))
940
+ die ("revision walk setup failed" );
941
+ rev .boundary = 1 ;
945
942
while ((commit = get_revision (& rev )) != NULL ) {
943
+ if (commit -> object .flags & BOUNDARY ) {
944
+ fprintf (stderr , "Boundary %s\n" , sha1_to_hex (commit -> object .sha1 ));
945
+ boundary_count ++ ;
946
+ origin = (boundary_count == 1 ) ? commit : NULL ;
947
+ continue ;
948
+ }
949
+
946
950
/* ignore merges */
947
951
if (commit -> parents && commit -> parents -> next )
948
952
continue ;
@@ -966,7 +970,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
966
970
if (thread )
967
971
gen_message_id (& rev , "cover" );
968
972
make_cover_letter (& rev , use_stdout , numbered , numbered_files ,
969
- origin , head );
973
+ origin , nr , list , head );
970
974
total ++ ;
971
975
start_number -- ;
972
976
}
0 commit comments