format-patch: trivial cleanups
Now that the cover-letter code has been shuffled, we can do some cleanups. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 7, 2013 at 12:46 UTC
d7ddad012b1badaf96075e880d546ef3525f23ff
1 file changed
+35
-36
builtin/log.c
+35
-36
@@ -810,9 +810,37 @@ static void add_branch_description(struct strbuf *buf, const char *branch_name)
810
}
811
}
812
813
+static char *find_branch_name(struct rev_info *rev)
814
+{
815
+ int i, positive = -1;
816
+ unsigned char branch_sha1[20];
817
+ const unsigned char *tip_sha1;
818
+ const char *ref;
819
+ char *full_ref, *branch = NULL;
820
+
821
+ for (i = 0; i < rev->cmdline.nr; i++) {
822
+ if (rev->cmdline.rev[i].flags & UNINTERESTING)
823
+ continue;
824
+ if (positive < 0)
825
+ positive = i;
826
+ else
827
+ return NULL;
828
+ }
829
+ if (positive < 0)
830
+ return NULL;
831
+ ref = rev->cmdline.rev[positive].name;
832
+ tip_sha1 = rev->cmdline.rev[positive].item->sha1;
833
+ if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
834
+ !prefixcmp(full_ref, "refs/heads/") &&
835
+ !hashcmp(tip_sha1, branch_sha1))
836
+ branch = xstrdup(full_ref + strlen("refs/heads/"));
837
+ free(full_ref);
838
+ return branch;
839
+}
840
+
841
static void make_cover_letter(struct rev_info *rev, int use_stdout,
842
struct commit *origin,
815
- int nr, struct commit **list, struct commit *head,
843
+ int nr, struct commit **list,
844
const char *branch_name,
845
int quiet)
846
{
@@ -826,6 +854,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
854
struct diff_options opts;
855
int need_8bit_cte = 0;
856
struct pretty_print_context pp = {0};
857
+ struct commit *head = list[0];
858
859
if (rev->commit_format != CMIT_FMT_EMAIL)
860
die(_("Cover letter needs email format"));
@@ -843,6 +872,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
872
if (has_non_ascii(list[i]->buffer))
873
need_8bit_cte = 1;
874
875
+ if (!branch_name)
876
+ branch_name = find_branch_name(rev);
877
+
878
msg = body;
879
pp.fmt = CMIT_FMT_EMAIL;
880
pp.date_mode = DATE_RFC2822;
@@ -1049,36 +1081,6 @@ static int cc_callback(const struct option *opt, const char *arg, int unset)
1081
return 0;
1082
}
1083
1052
-static char *find_branch_name(struct rev_info *rev)
1053
-{
1054
- int i, positive = -1;
1055
- unsigned char branch_sha1[20];
1056
- const unsigned char *tip_sha1;
1057
- const char *ref;
1058
- char *full_ref, *branch = NULL;
1059
-
1060
- for (i = 0; i < rev->cmdline.nr; i++) {
1061
- if (rev->cmdline.rev[i].flags & UNINTERESTING)
1062
- continue;
1063
- if (positive < 0)
1064
- positive = i;
1065
- else
1066
- return NULL;
1067
- }
1068
- if (0 <= positive) {
1069
- ref = rev->cmdline.rev[positive].name;
1070
- tip_sha1 = rev->cmdline.rev[positive].item->sha1;
1071
- } else {
1072
- return NULL;
1073
- }
1074
- if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
1075
- !prefixcmp(full_ref, "refs/heads/") &&
1076
- !hashcmp(tip_sha1, branch_sha1))
1077
- branch = xstrdup(full_ref + strlen("refs/heads/"));
1078
- free(full_ref);
1079
- return branch;
1080
-}
1081
-
1084
int cmd_format_patch(int argc, const char **argv, const char *prefix)
1085
{
1086
struct commit *commit;
@@ -1093,7 +1095,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1095
int cover_letter = -1;
1096
int boundary_count = 0;
1097
int no_binary_diff = 0;
1096
- struct commit *origin = NULL, *head = NULL;
1098
+ struct commit *origin = NULL;
1099
const char *in_reply_to = NULL;
1100
struct patch_ids ids;
1101
struct strbuf buf = STRBUF_INIT;
@@ -1359,7 +1361,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1361
if (nr == 0)
1362
/* nothing to do */
1363
return 0;
1362
- head = list[0];
1364
total = nr;
1365
if (!keep_subject && auto_number && total > 1)
1366
numbered = 1;
@@ -1383,10 +1384,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1384
if (cover_letter) {
1385
if (thread)
1386
gen_message_id(&rev, "cover");
1386
- if (!branch_name)
1387
- branch_name = find_branch_name(&rev);
1387
make_cover_letter(&rev, use_stdout,
1389
- origin, nr, list, head, branch_name, quiet);
1388
+ origin, nr, list, branch_name, quiet);
1389
total++;
1390
start_number--;
1391
}