Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Builtin "git log" and related commands (show, whatchanged) |
| 3 | * |
| 4 | * (C) Copyright 2006 Linus Torvalds |
| 5 | * 2006 Junio Hamano |
| 6 | */ |
| 7 | #include "cache.h" |
Matthias Kestenholz | 6b2f2d9 | 2008-02-18 08:26:03 +0100 | [diff] [blame] | 8 | #include "color.h" |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 9 | #include "commit.h" |
| 10 | #include "diff.h" |
| 11 | #include "revision.h" |
| 12 | #include "log-tree.h" |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 13 | #include "builtin.h" |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 14 | #include "tag.h" |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 15 | #include "reflog-walk.h" |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 16 | #include "patch-ids.h" |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 17 | #include "run-command.h" |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 18 | #include "shortlog.h" |
Markus Heidelberg | f296802 | 2008-12-29 18:45:20 +0100 | [diff] [blame] | 19 | #include "remote.h" |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 20 | #include "string-list.h" |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 21 | |
Heikki Orsila | dd0ffd5 | 2008-05-22 18:24:07 +0300 | [diff] [blame] | 22 | /* Set a default date-time format for git log ("log.date" config variable) */ |
| 23 | static const char *default_date_mode = NULL; |
| 24 | |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 25 | static int default_show_root = 1; |
Alex Riesen | d54276f | 2007-07-04 12:37:27 +0200 | [diff] [blame] | 26 | static const char *fmt_patch_subject_prefix = "PATCH"; |
Denis Cheng | 94c22a5 | 2008-03-02 17:05:53 +0800 | [diff] [blame] | 27 | static const char *fmt_pretty; |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 28 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 29 | static void cmd_log_init(int argc, const char **argv, const char *prefix, |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 30 | struct rev_info *rev) |
| 31 | { |
Junio C Hamano | 52883fb | 2006-12-25 11:48:35 -0800 | [diff] [blame] | 32 | int i; |
| 33 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 34 | rev->abbrev = DEFAULT_ABBREV; |
| 35 | rev->commit_format = CMIT_FMT_DEFAULT; |
Denis Cheng | 94c22a5 | 2008-03-02 17:05:53 +0800 | [diff] [blame] | 36 | if (fmt_pretty) |
Junio C Hamano | 4da45be | 2008-04-07 17:11:34 -0700 | [diff] [blame] | 37 | get_commit_format(fmt_pretty, rev); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 38 | rev->verbose_header = 1; |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 39 | DIFF_OPT_SET(&rev->diffopt, RECURSIVE); |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 40 | rev->show_root_diff = default_show_root; |
Alex Riesen | d54276f | 2007-07-04 12:37:27 +0200 | [diff] [blame] | 41 | rev->subject_prefix = fmt_patch_subject_prefix; |
Jeff King | 5ec11af | 2008-12-07 21:54:17 -0500 | [diff] [blame] | 42 | DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV); |
Heikki Orsila | dd0ffd5 | 2008-05-22 18:24:07 +0300 | [diff] [blame] | 43 | |
| 44 | if (default_date_mode) |
| 45 | rev->date_mode = parse_date_format(default_date_mode); |
| 46 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 47 | argc = setup_revisions(argc, argv, rev, "HEAD"); |
Heikki Orsila | dd0ffd5 | 2008-05-22 18:24:07 +0300 | [diff] [blame] | 48 | |
Timo Hirvonen | 9dafea2 | 2006-06-25 15:39:35 +0300 | [diff] [blame] | 49 | if (rev->diffopt.pickaxe || rev->diffopt.filter) |
| 50 | rev->always_show_header = 0; |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 51 | if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) { |
Linus Torvalds | 750f7b6 | 2007-06-19 14:22:46 -0700 | [diff] [blame] | 52 | rev->always_show_header = 0; |
| 53 | if (rev->diffopt.nr_paths != 1) |
| 54 | usage("git logs can only follow renames on one pathname at a time"); |
| 55 | } |
Junio C Hamano | 52883fb | 2006-12-25 11:48:35 -0800 | [diff] [blame] | 56 | for (i = 1; i < argc; i++) { |
| 57 | const char *arg = argv[i]; |
Jeff King | 6668833 | 2007-05-16 07:15:07 -0400 | [diff] [blame] | 58 | if (!strcmp(arg, "--decorate")) { |
René Scharfe | 5e9bf11 | 2008-09-04 23:38:08 +0200 | [diff] [blame] | 59 | load_ref_decorations(); |
Linus Torvalds | d467a52 | 2008-11-03 11:23:57 -0800 | [diff] [blame] | 60 | rev->show_decorations = 1; |
Linus Torvalds | 0f3a290 | 2008-10-27 12:51:59 -0700 | [diff] [blame] | 61 | } else if (!strcmp(arg, "--source")) { |
| 62 | rev->show_source = 1; |
Linus Torvalds | ca135e7 | 2007-04-16 16:05:10 -0700 | [diff] [blame] | 63 | } else |
Junio C Hamano | 52883fb | 2006-12-25 11:48:35 -0800 | [diff] [blame] | 64 | die("unrecognized argument: %s", arg); |
| 65 | } |
Timo Hirvonen | 9dafea2 | 2006-06-25 15:39:35 +0300 | [diff] [blame] | 66 | } |
| 67 | |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 68 | /* |
| 69 | * This gives a rough estimate for how many commits we |
| 70 | * will print out in the list. |
| 71 | */ |
| 72 | static int estimate_commit_count(struct rev_info *rev, struct commit_list *list) |
| 73 | { |
| 74 | int n = 0; |
| 75 | |
| 76 | while (list) { |
| 77 | struct commit *commit = list->item; |
| 78 | unsigned int flags = commit->object.flags; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 79 | list = list->next; |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 80 | if (!(flags & (TREESAME | UNINTERESTING))) |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 81 | n++; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 82 | } |
| 83 | return n; |
| 84 | } |
| 85 | |
| 86 | static void show_early_header(struct rev_info *rev, const char *stage, int nr) |
| 87 | { |
| 88 | if (rev->shown_one) { |
| 89 | rev->shown_one = 0; |
| 90 | if (rev->commit_format != CMIT_FMT_ONELINE) |
| 91 | putchar(rev->diffopt.line_termination); |
| 92 | } |
| 93 | printf("Final output: %d %s\n", nr, stage); |
| 94 | } |
| 95 | |
| 96 | struct itimerval early_output_timer; |
| 97 | |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 98 | static void log_show_early(struct rev_info *revs, struct commit_list *list) |
| 99 | { |
| 100 | int i = revs->early_output; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 101 | int show_header = 1; |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 102 | |
| 103 | sort_in_topological_order(&list, revs->lifo); |
| 104 | while (list && i) { |
| 105 | struct commit *commit = list->item; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 106 | switch (simplify_commit(revs, commit)) { |
| 107 | case commit_show: |
| 108 | if (show_header) { |
| 109 | int n = estimate_commit_count(revs, list); |
| 110 | show_early_header(revs, "incomplete", n); |
| 111 | show_header = 0; |
| 112 | } |
| 113 | log_tree_commit(revs, commit); |
| 114 | i--; |
| 115 | break; |
| 116 | case commit_ignore: |
| 117 | break; |
| 118 | case commit_error: |
| 119 | return; |
| 120 | } |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 121 | list = list->next; |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 122 | } |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 123 | |
| 124 | /* Did we already get enough commits for the early output? */ |
| 125 | if (!i) |
| 126 | return; |
| 127 | |
| 128 | /* |
| 129 | * ..if no, then repeat it twice a second until we |
| 130 | * do. |
| 131 | * |
| 132 | * NOTE! We don't use "it_interval", because if the |
| 133 | * reader isn't listening, we want our output to be |
| 134 | * throttled by the writing, and not have the timer |
| 135 | * trigger every second even if we're blocked on a |
| 136 | * reader! |
| 137 | */ |
| 138 | early_output_timer.it_value.tv_sec = 0; |
| 139 | early_output_timer.it_value.tv_usec = 500000; |
| 140 | setitimer(ITIMER_REAL, &early_output_timer, NULL); |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void early_output(int signal) |
| 144 | { |
| 145 | show_early_output = log_show_early; |
| 146 | } |
| 147 | |
| 148 | static void setup_early_output(struct rev_info *rev) |
| 149 | { |
| 150 | struct sigaction sa; |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Set up the signal handler, minimally intrusively: |
| 154 | * we only set a single volatile integer word (not |
| 155 | * using sigatomic_t - trying to avoid unnecessary |
| 156 | * system dependencies and headers), and using |
| 157 | * SA_RESTART. |
| 158 | */ |
| 159 | memset(&sa, 0, sizeof(sa)); |
| 160 | sa.sa_handler = early_output; |
| 161 | sigemptyset(&sa.sa_mask); |
| 162 | sa.sa_flags = SA_RESTART; |
| 163 | sigaction(SIGALRM, &sa, NULL); |
| 164 | |
| 165 | /* |
| 166 | * If we can get the whole output in less than a |
| 167 | * tenth of a second, don't even bother doing the |
| 168 | * early-output thing.. |
| 169 | * |
| 170 | * This is a one-time-only trigger. |
| 171 | */ |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 172 | early_output_timer.it_value.tv_sec = 0; |
| 173 | early_output_timer.it_value.tv_usec = 100000; |
| 174 | setitimer(ITIMER_REAL, &early_output_timer, NULL); |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void finish_early_output(struct rev_info *rev) |
| 178 | { |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 179 | int n = estimate_commit_count(rev, rev->commits); |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 180 | signal(SIGALRM, SIG_IGN); |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 181 | show_early_header(rev, "done", n); |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Timo Hirvonen | 9dafea2 | 2006-06-25 15:39:35 +0300 | [diff] [blame] | 184 | static int cmd_log_walk(struct rev_info *rev) |
| 185 | { |
| 186 | struct commit *commit; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 187 | |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 188 | if (rev->early_output) |
| 189 | setup_early_output(rev); |
| 190 | |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 191 | if (prepare_revision_walk(rev)) |
| 192 | die("revision walk setup failed"); |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 193 | |
| 194 | if (rev->early_output) |
| 195 | finish_early_output(rev); |
| 196 | |
Peter Valdemar Mørch | 036d17f | 2008-08-11 08:46:24 +0200 | [diff] [blame] | 197 | /* |
Peter Valdemar Mørch | 84102a3 | 2008-08-11 08:46:25 +0200 | [diff] [blame] | 198 | * For --check and --exit-code, the exit code is based on CHECK_FAILED |
| 199 | * and HAS_CHANGES being accumulated in rev->diffopt, so be careful to |
| 200 | * retain that state information if replacing rev->diffopt in this loop |
Peter Valdemar Mørch | 036d17f | 2008-08-11 08:46:24 +0200 | [diff] [blame] | 201 | */ |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 202 | while ((commit = get_revision(rev)) != NULL) { |
| 203 | log_tree_commit(rev, commit); |
Johannes Schindelin | a6c7306 | 2007-01-20 22:28:16 +0100 | [diff] [blame] | 204 | if (!rev->reflog_info) { |
| 205 | /* we allow cycles in reflog ancestry */ |
| 206 | free(commit->buffer); |
| 207 | commit->buffer = NULL; |
| 208 | } |
Linus Torvalds | cb11574 | 2006-06-17 18:47:58 -0700 | [diff] [blame] | 209 | free_commit_list(commit->parents); |
| 210 | commit->parents = NULL; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 211 | } |
Peter Valdemar Mørch | 036d17f | 2008-08-11 08:46:24 +0200 | [diff] [blame] | 212 | if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF && |
| 213 | DIFF_OPT_TST(&rev->diffopt, CHECK_FAILED)) { |
| 214 | return 02; |
| 215 | } |
Peter Valdemar Mørch | 84102a3 | 2008-08-11 08:46:25 +0200 | [diff] [blame] | 216 | return diff_result_code(&rev->diffopt, 0); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 219 | static int git_log_config(const char *var, const char *value, void *cb) |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 220 | { |
Denis Cheng | 94c22a5 | 2008-03-02 17:05:53 +0800 | [diff] [blame] | 221 | if (!strcmp(var, "format.pretty")) |
| 222 | return git_config_string(&fmt_pretty, var, value); |
Brian Hetro | 70cff3a | 2008-07-05 01:24:41 -0400 | [diff] [blame] | 223 | if (!strcmp(var, "format.subjectprefix")) |
| 224 | return git_config_string(&fmt_patch_subject_prefix, var, value); |
Heikki Orsila | dd0ffd5 | 2008-05-22 18:24:07 +0300 | [diff] [blame] | 225 | if (!strcmp(var, "log.date")) |
| 226 | return git_config_string(&default_date_mode, var, value); |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 227 | if (!strcmp(var, "log.showroot")) { |
| 228 | default_show_root = git_config_bool(var, value); |
| 229 | return 0; |
| 230 | } |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 231 | return git_diff_ui_config(var, value, cb); |
Peter Baumann | 0f03ca9 | 2006-11-23 10:36:33 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 234 | int cmd_whatchanged(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 235 | { |
| 236 | struct rev_info rev; |
| 237 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 238 | git_config(git_log_config, NULL); |
Matthias Kestenholz | 6b2f2d9 | 2008-02-18 08:26:03 +0100 | [diff] [blame] | 239 | |
| 240 | if (diff_use_color_default == -1) |
| 241 | diff_use_color_default = git_use_color_default; |
| 242 | |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 243 | init_revisions(&rev, prefix); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 244 | rev.diff = 1; |
Linus Torvalds | 9202434 | 2006-06-11 10:57:35 -0700 | [diff] [blame] | 245 | rev.simplify_history = 0; |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 246 | cmd_log_init(argc, argv, prefix, &rev); |
Timo Hirvonen | 9dafea2 | 2006-06-25 15:39:35 +0300 | [diff] [blame] | 247 | if (!rev.diffopt.output_format) |
| 248 | rev.diffopt.output_format = DIFF_FORMAT_RAW; |
| 249 | return cmd_log_walk(&rev); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 252 | static void show_tagger(char *buf, int len, struct rev_info *rev) |
| 253 | { |
Johannes Schindelin | ea718e6 | 2009-01-02 19:08:43 +0100 | [diff] [blame] | 254 | struct strbuf out = STRBUF_INIT; |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 255 | |
Johannes Schindelin | ea718e6 | 2009-01-02 19:08:43 +0100 | [diff] [blame] | 256 | pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode, |
| 257 | git_log_output_encoding ? |
| 258 | git_log_output_encoding: git_commit_encoding); |
| 259 | printf("%s\n", out.buf); |
| 260 | strbuf_release(&out); |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static int show_object(const unsigned char *sha1, int show_tag_object, |
| 264 | struct rev_info *rev) |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 265 | { |
| 266 | unsigned long size; |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 267 | enum object_type type; |
| 268 | char *buf = read_sha1_file(sha1, &type, &size); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 269 | int offset = 0; |
| 270 | |
| 271 | if (!buf) |
| 272 | return error("Could not read object %s", sha1_to_hex(sha1)); |
| 273 | |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 274 | if (show_tag_object) |
| 275 | while (offset < size && buf[offset] != '\n') { |
| 276 | int new_offset = offset + 1; |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 277 | while (new_offset < size && buf[new_offset++] != '\n') |
| 278 | ; /* do nothing */ |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 279 | if (!prefixcmp(buf + offset, "tagger ")) |
| 280 | show_tagger(buf + offset + 7, |
| 281 | new_offset - offset - 7, rev); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 282 | offset = new_offset; |
| 283 | } |
| 284 | |
| 285 | if (offset < size) |
| 286 | fwrite(buf + offset, size - offset, 1, stdout); |
| 287 | free(buf); |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int show_tree_object(const unsigned char *sha1, |
| 292 | const char *base, int baselen, |
René Scharfe | 671f070 | 2008-07-14 21:22:12 +0200 | [diff] [blame] | 293 | const char *pathname, unsigned mode, int stage, void *context) |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 294 | { |
| 295 | printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); |
| 296 | return 0; |
| 297 | } |
| 298 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 299 | int cmd_show(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 300 | { |
| 301 | struct rev_info rev; |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 302 | struct object_array_entry *objects; |
| 303 | int i, count, ret = 0; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 304 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 305 | git_config(git_log_config, NULL); |
Matthias Kestenholz | 6b2f2d9 | 2008-02-18 08:26:03 +0100 | [diff] [blame] | 306 | |
| 307 | if (diff_use_color_default == -1) |
| 308 | diff_use_color_default = git_use_color_default; |
| 309 | |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 310 | init_revisions(&rev, prefix); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 311 | rev.diff = 1; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 312 | rev.combine_merges = 1; |
| 313 | rev.dense_combined_merges = 1; |
| 314 | rev.always_show_header = 1; |
| 315 | rev.ignore_merges = 0; |
| 316 | rev.no_walk = 1; |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 317 | cmd_log_init(argc, argv, prefix, &rev); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 318 | |
| 319 | count = rev.pending.nr; |
| 320 | objects = rev.pending.objects; |
| 321 | for (i = 0; i < count && !ret; i++) { |
| 322 | struct object *o = objects[i].item; |
| 323 | const char *name = objects[i].name; |
| 324 | switch (o->type) { |
| 325 | case OBJ_BLOB: |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 326 | ret = show_object(o->sha1, 0, NULL); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 327 | break; |
| 328 | case OBJ_TAG: { |
| 329 | struct tag *t = (struct tag *)o; |
| 330 | |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 331 | printf("%stag %s%s\n", |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 332 | diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 333 | t->tag, |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 334 | diff_get_color_opt(&rev.diffopt, DIFF_RESET)); |
Johannes Schindelin | 56122ed | 2007-12-18 18:01:33 +0000 | [diff] [blame] | 335 | ret = show_object(o->sha1, 1, &rev); |
Junio C Hamano | d2dadfe | 2008-12-15 00:36:56 -0800 | [diff] [blame] | 336 | if (ret) |
| 337 | break; |
| 338 | o = parse_object(t->tagged->sha1); |
| 339 | if (!o) |
| 340 | ret = error("Could not read object %s", |
| 341 | sha1_to_hex(t->tagged->sha1)); |
| 342 | objects[i].item = o; |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 343 | i--; |
| 344 | break; |
| 345 | } |
| 346 | case OBJ_TREE: |
| 347 | printf("%stree %s%s\n\n", |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 348 | diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 349 | name, |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 350 | diff_get_color_opt(&rev.diffopt, DIFF_RESET)); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 351 | read_tree_recursive((struct tree *)o, "", 0, 0, NULL, |
René Scharfe | 671f070 | 2008-07-14 21:22:12 +0200 | [diff] [blame] | 352 | show_tree_object, NULL); |
Johannes Schindelin | 5d7eeee | 2006-12-14 11:31:05 +0100 | [diff] [blame] | 353 | break; |
| 354 | case OBJ_COMMIT: |
| 355 | rev.pending.nr = rev.pending.alloc = 0; |
| 356 | rev.pending.objects = NULL; |
| 357 | add_object_array(o, name, &rev.pending); |
| 358 | ret = cmd_log_walk(&rev); |
| 359 | break; |
| 360 | default: |
| 361 | ret = error("Unknown type: %d", o->type); |
| 362 | } |
| 363 | } |
| 364 | free(objects); |
| 365 | return ret; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 368 | /* |
| 369 | * This is equivalent to "git log -g --abbrev-commit --pretty=oneline" |
| 370 | */ |
| 371 | int cmd_log_reflog(int argc, const char **argv, const char *prefix) |
| 372 | { |
| 373 | struct rev_info rev; |
| 374 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 375 | git_config(git_log_config, NULL); |
Matthias Kestenholz | 6b2f2d9 | 2008-02-18 08:26:03 +0100 | [diff] [blame] | 376 | |
| 377 | if (diff_use_color_default == -1) |
| 378 | diff_use_color_default = git_use_color_default; |
| 379 | |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 380 | init_revisions(&rev, prefix); |
| 381 | init_reflog_walk(&rev.reflog_info); |
| 382 | rev.abbrev_commit = 1; |
| 383 | rev.verbose_header = 1; |
| 384 | cmd_log_init(argc, argv, prefix, &rev); |
| 385 | |
| 386 | /* |
| 387 | * This means that we override whatever commit format the user gave |
| 388 | * on the cmd line. Sad, but cmd_log_init() currently doesn't |
| 389 | * allow us to set a different default. |
| 390 | */ |
| 391 | rev.commit_format = CMIT_FMT_ONELINE; |
Junio C Hamano | 4da45be | 2008-04-07 17:11:34 -0700 | [diff] [blame] | 392 | rev.use_terminator = 1; |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 393 | rev.always_show_header = 1; |
| 394 | |
| 395 | /* |
| 396 | * We get called through "git reflog", so unlike the other log |
| 397 | * routines, we need to set up our pager manually.. |
| 398 | */ |
| 399 | setup_pager(); |
| 400 | |
| 401 | return cmd_log_walk(&rev); |
| 402 | } |
| 403 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 404 | int cmd_log(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 405 | { |
| 406 | struct rev_info rev; |
| 407 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 408 | git_config(git_log_config, NULL); |
Matthias Kestenholz | 6b2f2d9 | 2008-02-18 08:26:03 +0100 | [diff] [blame] | 409 | |
| 410 | if (diff_use_color_default == -1) |
| 411 | diff_use_color_default = git_use_color_default; |
| 412 | |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 413 | init_revisions(&rev, prefix); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 414 | rev.always_show_header = 1; |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 415 | cmd_log_init(argc, argv, prefix, &rev); |
Timo Hirvonen | 9dafea2 | 2006-06-25 15:39:35 +0300 | [diff] [blame] | 416 | return cmd_log_walk(&rev); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 417 | } |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 418 | |
Robin Rosenberg | c06d2da | 2007-02-23 23:27:58 +0100 | [diff] [blame] | 419 | /* format-patch */ |
| 420 | #define FORMAT_PATCH_NAME_MAX 64 |
| 421 | |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 422 | static int istitlechar(char c) |
| 423 | { |
| 424 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || |
| 425 | (c >= '0' && c <= '9') || c == '.' || c == '_'; |
| 426 | } |
| 427 | |
Junio C Hamano | 917a8f8 | 2007-01-17 15:03:39 -0800 | [diff] [blame] | 428 | static const char *fmt_patch_suffix = ".patch"; |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 429 | static int numbered = 0; |
Brian Gernhardt | a567fdc | 2008-10-02 16:55:39 -0400 | [diff] [blame] | 430 | static int auto_number = 1; |
Johannes Schindelin | 20ff068 | 2006-06-02 15:21:17 +0200 | [diff] [blame] | 431 | |
Jeremy White | 0db5260 | 2009-02-12 09:51:55 -0600 | [diff] [blame] | 432 | static char *default_attach = NULL; |
| 433 | |
Daniel Barkalow | 3ee79d9 | 2008-02-19 02:40:33 -0500 | [diff] [blame] | 434 | static char **extra_hdr; |
| 435 | static int extra_hdr_nr; |
| 436 | static int extra_hdr_alloc; |
| 437 | |
| 438 | static char **extra_to; |
| 439 | static int extra_to_nr; |
| 440 | static int extra_to_alloc; |
| 441 | |
| 442 | static char **extra_cc; |
| 443 | static int extra_cc_nr; |
| 444 | static int extra_cc_alloc; |
| 445 | |
| 446 | static void add_header(const char *value) |
| 447 | { |
| 448 | int len = strlen(value); |
Jim Meyering | c8c4450 | 2008-08-19 20:42:04 +0200 | [diff] [blame] | 449 | while (len && value[len - 1] == '\n') |
Daniel Barkalow | 3ee79d9 | 2008-02-19 02:40:33 -0500 | [diff] [blame] | 450 | len--; |
| 451 | if (!strncasecmp(value, "to: ", 4)) { |
| 452 | ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc); |
| 453 | extra_to[extra_to_nr++] = xstrndup(value + 4, len - 4); |
| 454 | return; |
| 455 | } |
| 456 | if (!strncasecmp(value, "cc: ", 4)) { |
| 457 | ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); |
| 458 | extra_cc[extra_cc_nr++] = xstrndup(value + 4, len - 4); |
| 459 | return; |
| 460 | } |
| 461 | ALLOC_GROW(extra_hdr, extra_hdr_nr + 1, extra_hdr_alloc); |
| 462 | extra_hdr[extra_hdr_nr++] = xstrndup(value, len); |
| 463 | } |
| 464 | |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 465 | #define THREAD_SHALLOW 1 |
| 466 | #define THREAD_DEEP 2 |
| 467 | static int thread = 0; |
| 468 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 469 | static int git_format_config(const char *var, const char *value, void *cb) |
Johannes Schindelin | 20ff068 | 2006-06-02 15:21:17 +0200 | [diff] [blame] | 470 | { |
| 471 | if (!strcmp(var, "format.headers")) { |
Junio C Hamano | d7fb91c | 2007-01-17 11:13:02 -0800 | [diff] [blame] | 472 | if (!value) |
| 473 | die("format.headers without value"); |
Daniel Barkalow | 3ee79d9 | 2008-02-19 02:40:33 -0500 | [diff] [blame] | 474 | add_header(value); |
Johannes Schindelin | 20ff068 | 2006-06-02 15:21:17 +0200 | [diff] [blame] | 475 | return 0; |
| 476 | } |
Brian Hetro | 70cff3a | 2008-07-05 01:24:41 -0400 | [diff] [blame] | 477 | if (!strcmp(var, "format.suffix")) |
| 478 | return git_config_string(&fmt_patch_suffix, var, value); |
Miklos Vajna | fe8928e | 2008-04-26 23:19:06 +0200 | [diff] [blame] | 479 | if (!strcmp(var, "format.cc")) { |
| 480 | if (!value) |
| 481 | return config_error_nonbool(var); |
| 482 | ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); |
| 483 | extra_cc[extra_cc_nr++] = xstrdup(value); |
| 484 | return 0; |
| 485 | } |
Andy Parkins | a159ca0 | 2006-12-13 09:13:28 +0000 | [diff] [blame] | 486 | if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) { |
Ryan Anderson | f3aafa4 | 2006-07-09 02:28:21 -0400 | [diff] [blame] | 487 | return 0; |
| 488 | } |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 489 | if (!strcmp(var, "format.numbered")) { |
Junio C Hamano | 90f5c18 | 2008-02-11 13:09:16 -0800 | [diff] [blame] | 490 | if (value && !strcasecmp(value, "auto")) { |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 491 | auto_number = 1; |
| 492 | return 0; |
| 493 | } |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 494 | numbered = git_config_bool(var, value); |
Brian Gernhardt | a567fdc | 2008-10-02 16:55:39 -0400 | [diff] [blame] | 495 | auto_number = auto_number && numbered; |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 496 | return 0; |
| 497 | } |
Jeremy White | 0db5260 | 2009-02-12 09:51:55 -0600 | [diff] [blame] | 498 | if (!strcmp(var, "format.attach")) { |
| 499 | if (value && *value) |
| 500 | default_attach = xstrdup(value); |
| 501 | else |
| 502 | default_attach = xstrdup(git_version_string); |
| 503 | return 0; |
| 504 | } |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 505 | if (!strcmp(var, "format.thread")) { |
| 506 | if (value && !strcasecmp(value, "deep")) { |
| 507 | thread = THREAD_DEEP; |
| 508 | return 0; |
| 509 | } |
| 510 | if (value && !strcasecmp(value, "shallow")) { |
| 511 | thread = THREAD_SHALLOW; |
| 512 | return 0; |
| 513 | } |
| 514 | thread = git_config_bool(var, value) && THREAD_SHALLOW; |
| 515 | return 0; |
| 516 | } |
Adam Roben | dbd2144 | 2007-07-01 17:48:59 -0700 | [diff] [blame] | 517 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 518 | return git_log_config(var, value, cb); |
Johannes Schindelin | 20ff068 | 2006-06-02 15:21:17 +0200 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 522 | static const char *get_oneline_for_filename(struct commit *commit, |
| 523 | int keep_subject) |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 524 | { |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 525 | static char filename[PATH_MAX]; |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 526 | char *sol; |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 527 | int len = 0; |
Robin Rosenberg | c06d2da | 2007-02-23 23:27:58 +0100 | [diff] [blame] | 528 | int suffix_len = strlen(fmt_patch_suffix) + 1; |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 529 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 530 | sol = strstr(commit->buffer, "\n\n"); |
| 531 | if (!sol) |
| 532 | filename[0] = '\0'; |
| 533 | else { |
| 534 | int j, space = 0; |
| 535 | |
| 536 | sol += 2; |
| 537 | /* strip [PATCH] or [PATCH blabla] */ |
| 538 | if (!keep_subject && !prefixcmp(sol, "[PATCH")) { |
| 539 | char *eos = strchr(sol + 6, ']'); |
| 540 | if (eos) { |
| 541 | while (isspace(*eos)) |
| 542 | eos++; |
| 543 | sol = eos; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | for (j = 0; |
| 548 | j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 && |
| 549 | len < sizeof(filename) - suffix_len && |
| 550 | sol[j] && sol[j] != '\n'; |
| 551 | j++) { |
| 552 | if (istitlechar(sol[j])) { |
| 553 | if (space) { |
| 554 | filename[len++] = '-'; |
| 555 | space = 0; |
| 556 | } |
| 557 | filename[len++] = sol[j]; |
| 558 | if (sol[j] == '.') |
| 559 | while (sol[j + 1] == '.') |
| 560 | j++; |
| 561 | } else |
| 562 | space = 1; |
| 563 | } |
| 564 | while (filename[len - 1] == '.' |
| 565 | || filename[len - 1] == '-') |
| 566 | len--; |
| 567 | filename[len] = '\0'; |
| 568 | } |
| 569 | return filename; |
| 570 | } |
| 571 | |
| 572 | static FILE *realstdout = NULL; |
| 573 | static const char *output_directory = NULL; |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 574 | static int outdir_offset; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 575 | |
Nate Case | ec2956d | 2009-03-18 12:00:45 -0500 | [diff] [blame] | 576 | static int reopen_stdout(const char *oneline, int nr, struct rev_info *rev) |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 577 | { |
| 578 | char filename[PATH_MAX]; |
| 579 | int len = 0; |
| 580 | int suffix_len = strlen(fmt_patch_suffix) + 1; |
| 581 | |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 582 | if (output_directory) { |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 583 | len = snprintf(filename, sizeof(filename), "%s", |
| 584 | output_directory); |
| 585 | if (len >= |
Robin Rosenberg | c06d2da | 2007-02-23 23:27:58 +0100 | [diff] [blame] | 586 | sizeof(filename) - FORMAT_PATCH_NAME_MAX - suffix_len) |
| 587 | return error("name of output directory is too long"); |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 588 | if (filename[len - 1] != '/') |
| 589 | filename[len++] = '/'; |
| 590 | } |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 591 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 592 | if (!oneline) |
| 593 | len += sprintf(filename + len, "%d", nr); |
| 594 | else { |
| 595 | len += sprintf(filename + len, "%04d-", nr); |
| 596 | len += snprintf(filename + len, sizeof(filename) - len - 1 |
| 597 | - suffix_len, "%s", oneline); |
Jon Loeliger | e6ff0f4 | 2007-06-05 15:06:53 -0500 | [diff] [blame] | 598 | strcpy(filename + len, fmt_patch_suffix); |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 599 | } |
Jon Loeliger | e6ff0f4 | 2007-06-05 15:06:53 -0500 | [diff] [blame] | 600 | |
Nate Case | ec2956d | 2009-03-18 12:00:45 -0500 | [diff] [blame] | 601 | if (!DIFF_OPT_TST(&rev->diffopt, QUIET)) |
| 602 | fprintf(realstdout, "%s\n", filename + outdir_offset); |
| 603 | |
Robin Rosenberg | c06d2da | 2007-02-23 23:27:58 +0100 | [diff] [blame] | 604 | if (freopen(filename, "w", stdout) == NULL) |
| 605 | return error("Cannot open patch file %s",filename); |
Robin Rosenberg | c06d2da | 2007-02-23 23:27:58 +0100 | [diff] [blame] | 606 | |
Jon Loeliger | e6ff0f4 | 2007-06-05 15:06:53 -0500 | [diff] [blame] | 607 | return 0; |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 608 | } |
| 609 | |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 610 | static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const char *prefix) |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 611 | { |
| 612 | struct rev_info check_rev; |
| 613 | struct commit *commit; |
| 614 | struct object *o1, *o2; |
| 615 | unsigned flags1, flags2; |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 616 | |
| 617 | if (rev->pending.nr != 2) |
| 618 | die("Need exactly one range."); |
| 619 | |
| 620 | o1 = rev->pending.objects[0].item; |
| 621 | flags1 = o1->flags; |
| 622 | o2 = rev->pending.objects[1].item; |
| 623 | flags2 = o2->flags; |
| 624 | |
| 625 | if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) |
| 626 | die("Not a range."); |
| 627 | |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 628 | init_patch_ids(ids); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 629 | |
| 630 | /* given a range a..b get all patch ids for b..a */ |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 631 | init_revisions(&check_rev, prefix); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 632 | o1->flags ^= UNINTERESTING; |
| 633 | o2->flags ^= UNINTERESTING; |
| 634 | add_pending_object(&check_rev, o1, "o1"); |
| 635 | add_pending_object(&check_rev, o2, "o2"); |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 636 | if (prepare_revision_walk(&check_rev)) |
| 637 | die("revision walk setup failed"); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 638 | |
| 639 | while ((commit = get_revision(&check_rev)) != NULL) { |
| 640 | /* ignore merges */ |
| 641 | if (commit->parents && commit->parents->next) |
| 642 | continue; |
| 643 | |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 644 | add_commit_patch_id(commit, ids); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* reset for next revision walk */ |
Johannes Schindelin | 81db094 | 2006-06-27 22:38:04 +0200 | [diff] [blame] | 648 | clear_commit_marks((struct commit *)o1, |
| 649 | SEEN | UNINTERESTING | SHOWN | ADDED); |
| 650 | clear_commit_marks((struct commit *)o2, |
| 651 | SEEN | UNINTERESTING | SHOWN | ADDED); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 652 | o1->flags = flags1; |
| 653 | o2->flags = flags2; |
| 654 | } |
| 655 | |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 656 | static void gen_message_id(struct rev_info *info, char *base) |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 657 | { |
Junio C Hamano | 774751a | 2007-12-08 17:32:08 -0800 | [diff] [blame] | 658 | const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME); |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 659 | const char *email_start = strrchr(committer, '<'); |
| 660 | const char *email_end = strrchr(committer, '>'); |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 661 | struct strbuf buf = STRBUF_INIT; |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 662 | if (!email_start || !email_end || email_start > email_end - 1) |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 663 | die("Could not extract email from committer identity."); |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 664 | strbuf_addf(&buf, "%s.%lu.git.%.*s", base, |
| 665 | (unsigned long) time(NULL), |
| 666 | (int)(email_end - email_start - 1), email_start + 1); |
| 667 | info->message_id = strbuf_detach(&buf, NULL); |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 670 | static void make_cover_letter(struct rev_info *rev, int use_stdout, |
| 671 | int numbered, int numbered_files, |
| 672 | struct commit *origin, |
| 673 | int nr, struct commit **list, struct commit *head) |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 674 | { |
| 675 | const char *committer; |
Daniel Barkalow | 39fe578 | 2008-02-28 12:14:13 -0500 | [diff] [blame] | 676 | char *head_sha1; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 677 | const char *subject_start = NULL; |
| 678 | const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; |
| 679 | const char *msg; |
| 680 | const char *extra_headers = rev->extra_headers; |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 681 | struct shortlog log; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 682 | struct strbuf sb = STRBUF_INIT; |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 683 | int i; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 684 | const char *encoding = "utf-8"; |
Daniel Barkalow | 39fe578 | 2008-02-28 12:14:13 -0500 | [diff] [blame] | 685 | struct diff_options opts; |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 686 | int need_8bit_cte = 0; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 687 | |
| 688 | if (rev->commit_format != CMIT_FMT_EMAIL) |
| 689 | die("Cover letter needs email format"); |
| 690 | |
| 691 | if (!use_stdout && reopen_stdout(numbered_files ? |
Nate Case | ec2956d | 2009-03-18 12:00:45 -0500 | [diff] [blame] | 692 | NULL : "cover-letter", 0, rev)) |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 693 | return; |
| 694 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 695 | head_sha1 = sha1_to_hex(head->object.sha1); |
| 696 | |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 697 | log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers, |
| 698 | &need_8bit_cte); |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 699 | |
| 700 | committer = git_committer_info(0); |
| 701 | |
| 702 | msg = body; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 703 | pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822, |
| 704 | encoding); |
| 705 | pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers, |
Junio C Hamano | 267123b | 2008-03-15 00:09:20 -0700 | [diff] [blame] | 706 | encoding, need_8bit_cte); |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 707 | pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0); |
| 708 | printf("%s\n", sb.buf); |
| 709 | |
| 710 | strbuf_release(&sb); |
| 711 | |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 712 | shortlog_init(&log); |
Johannes Schindelin | 859c4fb | 2008-03-02 15:53:39 +0000 | [diff] [blame] | 713 | log.wrap_lines = 1; |
| 714 | log.wrap = 72; |
| 715 | log.in1 = 2; |
| 716 | log.in2 = 4; |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 717 | for (i = 0; i < nr; i++) |
| 718 | shortlog_add_commit(&log, list[i]); |
| 719 | |
| 720 | shortlog_output(&log); |
| 721 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 722 | /* |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 723 | * We can only do diffstat with a unique reference point |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 724 | */ |
| 725 | if (!origin) |
| 726 | return; |
| 727 | |
Johannes Schindelin | 5d02294 | 2008-03-02 15:53:04 +0000 | [diff] [blame] | 728 | memcpy(&opts, &rev->diffopt, sizeof(opts)); |
| 729 | opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 730 | |
Daniel Barkalow | 39fe578 | 2008-02-28 12:14:13 -0500 | [diff] [blame] | 731 | diff_setup_done(&opts); |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 732 | |
Daniel Barkalow | 39fe578 | 2008-02-28 12:14:13 -0500 | [diff] [blame] | 733 | diff_tree_sha1(origin->tree->object.sha1, |
| 734 | head->tree->object.sha1, |
| 735 | "", &opts); |
| 736 | diffcore_std(&opts); |
| 737 | diff_flush(&opts); |
| 738 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 739 | printf("\n"); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 740 | } |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 741 | |
Junio C Hamano | 8419d2e | 2007-09-13 22:30:45 -0700 | [diff] [blame] | 742 | static const char *clean_message_id(const char *msg_id) |
| 743 | { |
| 744 | char ch; |
| 745 | const char *a, *z, *m; |
Junio C Hamano | 8419d2e | 2007-09-13 22:30:45 -0700 | [diff] [blame] | 746 | |
| 747 | m = msg_id; |
| 748 | while ((ch = *m) && (isspace(ch) || (ch == '<'))) |
| 749 | m++; |
| 750 | a = m; |
| 751 | z = NULL; |
| 752 | while ((ch = *m)) { |
| 753 | if (!isspace(ch) && (ch != '>')) |
| 754 | z = m; |
| 755 | m++; |
| 756 | } |
| 757 | if (!z) |
| 758 | die("insane in-reply-to: %s", msg_id); |
| 759 | if (++z == m) |
| 760 | return a; |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 761 | return xmemdupz(a, z - a); |
Junio C Hamano | 8419d2e | 2007-09-13 22:30:45 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 764 | static const char *set_outdir(const char *prefix, const char *output_directory) |
| 765 | { |
| 766 | if (output_directory && is_absolute_path(output_directory)) |
| 767 | return output_directory; |
| 768 | |
| 769 | if (!prefix || !*prefix) { |
| 770 | if (output_directory) |
| 771 | return output_directory; |
| 772 | /* The user did not explicitly ask for "./" */ |
| 773 | outdir_offset = 2; |
| 774 | return "./"; |
| 775 | } |
| 776 | |
| 777 | outdir_offset = strlen(prefix); |
| 778 | if (!output_directory) |
| 779 | return prefix; |
| 780 | |
| 781 | return xstrdup(prefix_filename(prefix, outdir_offset, |
| 782 | output_directory)); |
| 783 | } |
| 784 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 785 | int cmd_format_patch(int argc, const char **argv, const char *prefix) |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 786 | { |
| 787 | struct commit *commit; |
| 788 | struct commit **list = NULL; |
| 789 | struct rev_info rev; |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 790 | int nr = 0, total, i, j; |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 791 | int use_stdout = 0; |
Johannes Schindelin | fa0f02d | 2006-05-25 23:55:11 +0200 | [diff] [blame] | 792 | int start_number = -1; |
Johannes Schindelin | 8ac80a5 | 2006-05-05 04:31:29 +0200 | [diff] [blame] | 793 | int keep_subject = 0; |
Jon Loeliger | e6ff0f4 | 2007-06-05 15:06:53 -0500 | [diff] [blame] | 794 | int numbered_files = 0; /* _just_ numbers */ |
Robin H. Johnson | 2d9e4a4 | 2007-04-11 16:58:07 -0700 | [diff] [blame] | 795 | int subject_prefix = 0; |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 796 | int ignore_if_in_upstream = 0; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 797 | int cover_letter = 0; |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 798 | int boundary_count = 0; |
Caio Marcelo de Oliveira Filho | 37c22a4 | 2008-05-09 19:55:43 -0300 | [diff] [blame] | 799 | int no_binary_diff = 0; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 800 | struct commit *origin = NULL, *head = NULL; |
Junio C Hamano | 76af073 | 2006-07-14 22:47:53 -0700 | [diff] [blame] | 801 | const char *in_reply_to = NULL; |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 802 | struct patch_ids ids; |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 803 | char *add_signoff = NULL; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 804 | struct strbuf buf = STRBUF_INIT; |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 805 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 806 | git_config(git_format_config, NULL); |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 807 | init_revisions(&rev, prefix); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 808 | rev.commit_format = CMIT_FMT_EMAIL; |
| 809 | rev.verbose_header = 1; |
| 810 | rev.diff = 1; |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 811 | rev.combine_merges = 0; |
| 812 | rev.ignore_merges = 1; |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 813 | DIFF_OPT_SET(&rev.diffopt, RECURSIVE); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 814 | |
Adam Roben | dbd2144 | 2007-07-01 17:48:59 -0700 | [diff] [blame] | 815 | rev.subject_prefix = fmt_patch_subject_prefix; |
Johannes Schindelin | 20ff068 | 2006-06-02 15:21:17 +0200 | [diff] [blame] | 816 | |
Jeremy White | 0db5260 | 2009-02-12 09:51:55 -0600 | [diff] [blame] | 817 | if (default_attach) { |
| 818 | rev.mime_boundary = default_attach; |
| 819 | rev.no_inline = 1; |
| 820 | } |
| 821 | |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 822 | /* |
| 823 | * Parse the arguments before setup_revisions(), or something |
Frank Lichtenheld | 2dc189a | 2007-05-14 16:44:51 +0200 | [diff] [blame] | 824 | * like "git format-patch -o a123 HEAD^.." may fail; a123 is |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 825 | * possibly a valid SHA1. |
| 826 | */ |
| 827 | for (i = 1, j = 1; i < argc; i++) { |
| 828 | if (!strcmp(argv[i], "--stdout")) |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 829 | use_stdout = 1; |
Johannes Schindelin | 596524b | 2006-05-05 04:30:52 +0200 | [diff] [blame] | 830 | else if (!strcmp(argv[i], "-n") || |
| 831 | !strcmp(argv[i], "--numbered")) |
| 832 | numbered = 1; |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 833 | else if (!strcmp(argv[i], "-N") || |
| 834 | !strcmp(argv[i], "--no-numbered")) { |
| 835 | numbered = 0; |
| 836 | auto_number = 0; |
| 837 | } |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 838 | else if (!prefixcmp(argv[i], "--start-number=")) |
Johannes Schindelin | fa0f02d | 2006-05-25 23:55:11 +0200 | [diff] [blame] | 839 | start_number = strtol(argv[i] + 15, NULL, 10); |
Jon Loeliger | e6ff0f4 | 2007-06-05 15:06:53 -0500 | [diff] [blame] | 840 | else if (!strcmp(argv[i], "--numbered-files")) |
| 841 | numbered_files = 1; |
Johannes Schindelin | fa0f02d | 2006-05-25 23:55:11 +0200 | [diff] [blame] | 842 | else if (!strcmp(argv[i], "--start-number")) { |
| 843 | i++; |
| 844 | if (i == argc) |
| 845 | die("Need a number for --start-number"); |
| 846 | start_number = strtol(argv[i], NULL, 10); |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 847 | } |
Daniel Barkalow | 736cc67 | 2008-02-19 02:40:35 -0500 | [diff] [blame] | 848 | else if (!prefixcmp(argv[i], "--cc=")) { |
| 849 | ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); |
| 850 | extra_cc[extra_cc_nr++] = xstrdup(argv[i] + 5); |
| 851 | } |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 852 | else if (!strcmp(argv[i], "-k") || |
Johannes Schindelin | 8ac80a5 | 2006-05-05 04:31:29 +0200 | [diff] [blame] | 853 | !strcmp(argv[i], "--keep-subject")) { |
| 854 | keep_subject = 1; |
| 855 | rev.total = -1; |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 856 | } |
Junio C Hamano | efd0201 | 2006-06-06 08:46:23 -0700 | [diff] [blame] | 857 | else if (!strcmp(argv[i], "--output-directory") || |
| 858 | !strcmp(argv[i], "-o")) { |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 859 | i++; |
Junio C Hamano | efd0201 | 2006-06-06 08:46:23 -0700 | [diff] [blame] | 860 | if (argc <= i) |
| 861 | die("Which directory?"); |
| 862 | if (output_directory) |
| 863 | die("Two output directories?"); |
| 864 | output_directory = argv[i]; |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 865 | } |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 866 | else if (!strcmp(argv[i], "--signoff") || |
| 867 | !strcmp(argv[i], "-s")) { |
Eric W. Biederman | 6c4cca1 | 2006-06-12 13:31:38 -0600 | [diff] [blame] | 868 | const char *committer; |
| 869 | const char *endpos; |
Junio C Hamano | 774751a | 2007-12-08 17:32:08 -0800 | [diff] [blame] | 870 | committer = git_committer_info(IDENT_ERROR_ON_NO_NAME); |
Eric W. Biederman | 6c4cca1 | 2006-06-12 13:31:38 -0600 | [diff] [blame] | 871 | endpos = strchr(committer, '>'); |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 872 | if (!endpos) |
Alexander Potashev | d753070 | 2009-01-04 21:38:41 +0300 | [diff] [blame] | 873 | die("bogus committer info %s", committer); |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 874 | add_signoff = xmemdupz(committer, endpos - committer + 1); |
Junio C Hamano | cf2251b | 2006-05-31 15:11:49 -0700 | [diff] [blame] | 875 | } |
Johannes Schindelin | c112f68 | 2007-03-04 00:12:06 +0100 | [diff] [blame] | 876 | else if (!strcmp(argv[i], "--attach")) { |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 877 | rev.mime_boundary = git_version_string; |
Johannes Schindelin | c112f68 | 2007-03-04 00:12:06 +0100 | [diff] [blame] | 878 | rev.no_inline = 1; |
| 879 | } |
| 880 | else if (!prefixcmp(argv[i], "--attach=")) { |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 881 | rev.mime_boundary = argv[i] + 9; |
Johannes Schindelin | c112f68 | 2007-03-04 00:12:06 +0100 | [diff] [blame] | 882 | rev.no_inline = 1; |
| 883 | } |
Jeremy White | 0db5260 | 2009-02-12 09:51:55 -0600 | [diff] [blame] | 884 | else if (!strcmp(argv[i], "--no-attach")) { |
| 885 | rev.mime_boundary = NULL; |
| 886 | rev.no_inline = 0; |
| 887 | } |
Johannes Schindelin | c112f68 | 2007-03-04 00:12:06 +0100 | [diff] [blame] | 888 | else if (!strcmp(argv[i], "--inline")) { |
| 889 | rev.mime_boundary = git_version_string; |
| 890 | rev.no_inline = 0; |
| 891 | } |
| 892 | else if (!prefixcmp(argv[i], "--inline=")) { |
| 893 | rev.mime_boundary = argv[i] + 9; |
| 894 | rev.no_inline = 0; |
| 895 | } |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 896 | else if (!strcmp(argv[i], "--ignore-if-in-upstream")) |
| 897 | ignore_if_in_upstream = 1; |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 898 | else if (!strcmp(argv[i], "--thread") |
| 899 | || !strcmp(argv[i], "--thread=shallow")) |
| 900 | thread = THREAD_SHALLOW; |
| 901 | else if (!strcmp(argv[i], "--thread=deep")) |
| 902 | thread = THREAD_DEEP; |
| 903 | else if (!strcmp(argv[i], "--no-thread")) |
| 904 | thread = 0; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 905 | else if (!prefixcmp(argv[i], "--in-reply-to=")) |
Josh Triplett | da56645 | 2006-07-14 17:49:08 -0700 | [diff] [blame] | 906 | in_reply_to = argv[i] + 14; |
| 907 | else if (!strcmp(argv[i], "--in-reply-to")) { |
| 908 | i++; |
| 909 | if (i == argc) |
| 910 | die("Need a Message-Id for --in-reply-to"); |
| 911 | in_reply_to = argv[i]; |
Robin H. Johnson | 2d9e4a4 | 2007-04-11 16:58:07 -0700 | [diff] [blame] | 912 | } else if (!prefixcmp(argv[i], "--subject-prefix=")) { |
| 913 | subject_prefix = 1; |
| 914 | rev.subject_prefix = argv[i] + 17; |
| 915 | } else if (!prefixcmp(argv[i], "--suffix=")) |
Junio C Hamano | 03eeaea | 2007-01-17 11:12:03 -0800 | [diff] [blame] | 916 | fmt_patch_suffix = argv[i] + 9; |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 917 | else if (!strcmp(argv[i], "--cover-letter")) |
| 918 | cover_letter = 1; |
Caio Marcelo de Oliveira Filho | 37c22a4 | 2008-05-09 19:55:43 -0300 | [diff] [blame] | 919 | else if (!strcmp(argv[i], "--no-binary")) |
| 920 | no_binary_diff = 1; |
Michael Hendricks | d7d9c2d | 2009-03-26 10:51:05 -0600 | [diff] [blame] | 921 | else if (!prefixcmp(argv[i], "--add-header=")) |
| 922 | add_header(argv[i] + 13); |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 923 | else |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 924 | argv[j++] = argv[i]; |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 925 | } |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 926 | argc = j; |
| 927 | |
Daniel Barkalow | 3ee79d9 | 2008-02-19 02:40:33 -0500 | [diff] [blame] | 928 | for (i = 0; i < extra_hdr_nr; i++) { |
| 929 | strbuf_addstr(&buf, extra_hdr[i]); |
| 930 | strbuf_addch(&buf, '\n'); |
| 931 | } |
| 932 | |
| 933 | if (extra_to_nr) |
| 934 | strbuf_addstr(&buf, "To: "); |
| 935 | for (i = 0; i < extra_to_nr; i++) { |
| 936 | if (i) |
| 937 | strbuf_addstr(&buf, " "); |
| 938 | strbuf_addstr(&buf, extra_to[i]); |
| 939 | if (i + 1 < extra_to_nr) |
| 940 | strbuf_addch(&buf, ','); |
| 941 | strbuf_addch(&buf, '\n'); |
| 942 | } |
| 943 | |
| 944 | if (extra_cc_nr) |
| 945 | strbuf_addstr(&buf, "Cc: "); |
| 946 | for (i = 0; i < extra_cc_nr; i++) { |
| 947 | if (i) |
| 948 | strbuf_addstr(&buf, " "); |
| 949 | strbuf_addstr(&buf, extra_cc[i]); |
| 950 | if (i + 1 < extra_cc_nr) |
| 951 | strbuf_addch(&buf, ','); |
| 952 | strbuf_addch(&buf, '\n'); |
| 953 | } |
| 954 | |
| 955 | rev.extra_headers = strbuf_detach(&buf, 0); |
| 956 | |
Junio C Hamano | add5c8a | 2006-05-26 11:30:49 -0700 | [diff] [blame] | 957 | if (start_number < 0) |
Johannes Schindelin | fa0f02d | 2006-05-25 23:55:11 +0200 | [diff] [blame] | 958 | start_number = 1; |
Junio C Hamano | 63b398a | 2006-05-28 09:23:29 -0700 | [diff] [blame] | 959 | if (numbered && keep_subject) |
Johannes Schindelin | 8ac80a5 | 2006-05-05 04:31:29 +0200 | [diff] [blame] | 960 | die ("-n and -k are mutually exclusive."); |
Robin H. Johnson | 2d9e4a4 | 2007-04-11 16:58:07 -0700 | [diff] [blame] | 961 | if (keep_subject && subject_prefix) |
| 962 | die ("--subject-prefix and -k are mutually exclusive."); |
Johannes Schindelin | 8ac80a5 | 2006-05-05 04:31:29 +0200 | [diff] [blame] | 963 | |
Johannes Schindelin | 2448482 | 2006-05-05 03:33:32 +0200 | [diff] [blame] | 964 | argc = setup_revisions(argc, argv, &rev, "HEAD"); |
| 965 | if (argc > 1) |
| 966 | die ("unrecognized argument: %s", argv[1]); |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 967 | |
Jeff King | 68daa64 | 2008-08-24 22:10:29 -0400 | [diff] [blame] | 968 | if (!rev.diffopt.output_format |
| 969 | || rev.diffopt.output_format == DIFF_FORMAT_PATCH) |
Junio C Hamano | c261e43 | 2007-01-17 13:51:44 -0800 | [diff] [blame] | 970 | rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH; |
Timo Hirvonen | c9b5ef9 | 2006-06-24 20:24:14 +0300 | [diff] [blame] | 971 | |
Caio Marcelo de Oliveira Filho | 37c22a4 | 2008-05-09 19:55:43 -0300 | [diff] [blame] | 972 | if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff) |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 973 | DIFF_OPT_SET(&rev.diffopt, BINARY); |
Junio C Hamano | e47f306 | 2007-01-17 14:32:52 -0800 | [diff] [blame] | 974 | |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 975 | if (!use_stdout) |
| 976 | output_directory = set_outdir(prefix, output_directory); |
Matthias Lederhofer | 77e565d | 2006-09-28 21:55:35 +0200 | [diff] [blame] | 977 | |
Junio C Hamano | efd0201 | 2006-06-06 08:46:23 -0700 | [diff] [blame] | 978 | if (output_directory) { |
| 979 | if (use_stdout) |
| 980 | die("standard output, or directory, which one?"); |
| 981 | if (mkdir(output_directory, 0777) < 0 && errno != EEXIST) |
| 982 | die("Could not create directory %s", |
| 983 | output_directory); |
| 984 | } |
| 985 | |
Linus Torvalds | 1f1e895 | 2006-06-19 17:42:35 -0700 | [diff] [blame] | 986 | if (rev.pending.nr == 1) { |
Junio C Hamano | 8a1d076 | 2007-08-28 00:38:48 -0700 | [diff] [blame] | 987 | if (rev.max_count < 0 && !rev.show_root_diff) { |
| 988 | /* |
| 989 | * This is traditional behaviour of "git format-patch |
| 990 | * origin" that prepares what the origin side still |
| 991 | * does not have. |
| 992 | */ |
Junio C Hamano | 7c49628 | 2007-01-17 13:35:13 -0800 | [diff] [blame] | 993 | rev.pending.objects[0].item->flags |= UNINTERESTING; |
Junio C Hamano | 3384a2d | 2007-12-11 10:09:04 -0800 | [diff] [blame] | 994 | add_head_to_pending(&rev); |
Junio C Hamano | 7c49628 | 2007-01-17 13:35:13 -0800 | [diff] [blame] | 995 | } |
Junio C Hamano | 8a1d076 | 2007-08-28 00:38:48 -0700 | [diff] [blame] | 996 | /* |
| 997 | * Otherwise, it is "format-patch -22 HEAD", and/or |
| 998 | * "format-patch --root HEAD". The user wants |
| 999 | * get_revision() to do the usual traversal. |
Junio C Hamano | 7c49628 | 2007-01-17 13:35:13 -0800 | [diff] [blame] | 1000 | */ |
Johannes Schindelin | e686eb9 | 2006-05-06 22:56:38 +0200 | [diff] [blame] | 1001 | } |
Junio C Hamano | 68c2ec7 | 2009-01-10 12:41:33 -0800 | [diff] [blame] | 1002 | |
| 1003 | /* |
| 1004 | * We cannot move this anywhere earlier because we do want to |
| 1005 | * know if --root was given explicitly from the comand line. |
| 1006 | */ |
| 1007 | rev.show_root_diff = 1; |
| 1008 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1009 | if (cover_letter) { |
| 1010 | /* remember the range */ |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1011 | int i; |
| 1012 | for (i = 0; i < rev.pending.nr; i++) { |
| 1013 | struct object *o = rev.pending.objects[i].item; |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 1014 | if (!(o->flags & UNINTERESTING)) |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1015 | head = (struct commit *)o; |
| 1016 | } |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1017 | /* We can't generate a cover letter without any patches */ |
| 1018 | if (!head) |
| 1019 | return 0; |
| 1020 | } |
Johannes Schindelin | e686eb9 | 2006-05-06 22:56:38 +0200 | [diff] [blame] | 1021 | |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 1022 | if (ignore_if_in_upstream) |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1023 | get_patch_ids(&rev, &ids, prefix); |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 1024 | |
Johannes Schindelin | 81f3a18 | 2006-05-05 03:33:05 +0200 | [diff] [blame] | 1025 | if (!use_stdout) |
Jim Meyering | f578825 | 2007-06-27 16:28:53 +0200 | [diff] [blame] | 1026 | realstdout = xfdopen(xdup(1), "w"); |
Johannes Schindelin | 81f3a18 | 2006-05-05 03:33:05 +0200 | [diff] [blame] | 1027 | |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 1028 | if (prepare_revision_walk(&rev)) |
| 1029 | die("revision walk setup failed"); |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 1030 | rev.boundary = 1; |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1031 | while ((commit = get_revision(&rev)) != NULL) { |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 1032 | if (commit->object.flags & BOUNDARY) { |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 1033 | boundary_count++; |
| 1034 | origin = (boundary_count == 1) ? commit : NULL; |
| 1035 | continue; |
| 1036 | } |
| 1037 | |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 1038 | /* ignore merges */ |
| 1039 | if (commit->parents && commit->parents->next) |
| 1040 | continue; |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 1041 | |
| 1042 | if (ignore_if_in_upstream && |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1043 | has_commit_patch_id(commit, &ids)) |
Johannes Schindelin | 9c6efa3 | 2006-06-25 03:52:01 +0200 | [diff] [blame] | 1044 | continue; |
| 1045 | |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1046 | nr++; |
Jonas Fonseca | 83572c1 | 2006-08-26 16:16:18 +0200 | [diff] [blame] | 1047 | list = xrealloc(list, nr * sizeof(list[0])); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1048 | list[nr - 1] = commit; |
| 1049 | } |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 1050 | total = nr; |
Brian Gernhardt | 49604a4 | 2007-11-03 23:38:24 -0400 | [diff] [blame] | 1051 | if (!keep_subject && auto_number && total > 1) |
| 1052 | numbered = 1; |
Johannes Schindelin | 596524b | 2006-05-05 04:30:52 +0200 | [diff] [blame] | 1053 | if (numbered) |
Johannes Schindelin | fa0f02d | 2006-05-25 23:55:11 +0200 | [diff] [blame] | 1054 | rev.total = total + start_number - 1; |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 1055 | if (in_reply_to || thread || cover_letter) |
| 1056 | rev.ref_message_ids = xcalloc(1, sizeof(struct string_list)); |
| 1057 | if (in_reply_to) { |
| 1058 | const char *msgid = clean_message_id(in_reply_to); |
| 1059 | string_list_append(msgid, rev.ref_message_ids); |
| 1060 | } |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1061 | if (cover_letter) { |
| 1062 | if (thread) |
| 1063 | gen_message_id(&rev, "cover"); |
| 1064 | make_cover_letter(&rev, use_stdout, numbered, numbered_files, |
Daniel Barkalow | 2bda2cf | 2008-02-25 18:24:17 -0500 | [diff] [blame] | 1065 | origin, nr, list, head); |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1066 | total++; |
| 1067 | start_number--; |
| 1068 | } |
| 1069 | rev.add_signoff = add_signoff; |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1070 | while (0 <= --nr) { |
| 1071 | int shown; |
| 1072 | commit = list[nr]; |
Junio C Hamano | add5c8a | 2006-05-26 11:30:49 -0700 | [diff] [blame] | 1073 | rev.nr = total - nr + (start_number - 1); |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 1074 | /* Make the second and subsequent mails replies to the first */ |
Josh Triplett | cc35de8 | 2006-07-14 17:49:04 -0700 | [diff] [blame] | 1075 | if (thread) { |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1076 | /* Have we already had a message ID? */ |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 1077 | if (rev.message_id) { |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1078 | /* |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 1079 | * For deep threading: make every mail |
| 1080 | * a reply to the previous one, no |
| 1081 | * matter what other options are set. |
| 1082 | * |
| 1083 | * For shallow threading: |
| 1084 | * |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 1085 | * Without --cover-letter and |
| 1086 | * --in-reply-to, make every mail a |
| 1087 | * reply to the one before. |
| 1088 | * |
| 1089 | * With --in-reply-to but no |
| 1090 | * --cover-letter, make every mail a |
| 1091 | * reply to the <reply-to>. |
| 1092 | * |
| 1093 | * With --cover-letter, make every |
| 1094 | * mail but the cover letter a reply |
| 1095 | * to the cover letter. The cover |
| 1096 | * letter is a reply to the |
| 1097 | * --in-reply-to, if specified. |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1098 | */ |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 1099 | if (thread == THREAD_SHALLOW |
| 1100 | && rev.ref_message_ids->nr > 0 |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 1101 | && (!cover_letter || rev.nr > 1)) |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 1102 | free(rev.message_id); |
| 1103 | else |
Thomas Rast | b079c50 | 2009-02-19 22:26:31 +0100 | [diff] [blame] | 1104 | string_list_append(rev.message_id, |
| 1105 | rev.ref_message_ids); |
Josh Triplett | cc35de8 | 2006-07-14 17:49:04 -0700 | [diff] [blame] | 1106 | } |
Daniel Barkalow | e1a3734 | 2008-02-18 22:56:06 -0500 | [diff] [blame] | 1107 | gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); |
Josh Triplett | d1566f7 | 2006-07-14 17:48:51 -0700 | [diff] [blame] | 1108 | } |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1109 | if (!use_stdout && reopen_stdout(numbered_files ? NULL : |
| 1110 | get_oneline_for_filename(commit, keep_subject), |
Nate Case | ec2956d | 2009-03-18 12:00:45 -0500 | [diff] [blame] | 1111 | rev.nr, &rev)) |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 1112 | die("Failed to create output files"); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1113 | shown = log_tree_commit(&rev, commit); |
| 1114 | free(commit->buffer); |
| 1115 | commit->buffer = NULL; |
Junio C Hamano | add5c8a | 2006-05-26 11:30:49 -0700 | [diff] [blame] | 1116 | |
| 1117 | /* We put one extra blank line between formatted |
| 1118 | * patches and this flag is used by log-tree code |
| 1119 | * to see if it needs to emit a LF before showing |
| 1120 | * the log; when using one file per patch, we do |
| 1121 | * not want the extra blank line. |
| 1122 | */ |
| 1123 | if (!use_stdout) |
| 1124 | rev.shown_one = 0; |
Johannes Schindelin | 698ce6f | 2006-05-20 15:40:29 +0200 | [diff] [blame] | 1125 | if (shown) { |
| 1126 | if (rev.mime_boundary) |
| 1127 | printf("\n--%s%s--\n\n\n", |
| 1128 | mime_boundary_leader, |
| 1129 | rev.mime_boundary); |
| 1130 | else |
| 1131 | printf("-- \n%s\n\n", git_version_string); |
| 1132 | } |
Johannes Schindelin | 0377db7 | 2006-05-05 01:16:40 +0200 | [diff] [blame] | 1133 | if (!use_stdout) |
| 1134 | fclose(stdout); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1135 | } |
| 1136 | free(list); |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1137 | if (ignore_if_in_upstream) |
| 1138 | free_patch_ids(&ids); |
Junio C Hamano | 91efcf6 | 2006-04-21 13:19:58 -0700 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1142 | static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) |
| 1143 | { |
| 1144 | unsigned char sha1[20]; |
| 1145 | if (get_sha1(arg, sha1) == 0) { |
| 1146 | struct commit *commit = lookup_commit_reference(sha1); |
| 1147 | if (commit) { |
| 1148 | commit->object.flags |= flags; |
| 1149 | add_pending_object(revs, &commit->object, arg); |
| 1150 | return 0; |
| 1151 | } |
| 1152 | } |
| 1153 | return -1; |
| 1154 | } |
| 1155 | |
| 1156 | static const char cherry_usage[] = |
Markus Heidelberg | 3bc52d7 | 2009-01-01 22:56:29 +0100 | [diff] [blame] | 1157 | "git cherry [-v] [<upstream> [<head> [<limit>]]]"; |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1158 | int cmd_cherry(int argc, const char **argv, const char *prefix) |
| 1159 | { |
| 1160 | struct rev_info revs; |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1161 | struct patch_ids ids; |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1162 | struct commit *commit; |
| 1163 | struct commit_list *list = NULL; |
Markus Heidelberg | f296802 | 2008-12-29 18:45:20 +0100 | [diff] [blame] | 1164 | struct branch *current_branch; |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1165 | const char *upstream; |
| 1166 | const char *head = "HEAD"; |
| 1167 | const char *limit = NULL; |
| 1168 | int verbose = 0; |
| 1169 | |
| 1170 | if (argc > 1 && !strcmp(argv[1], "-v")) { |
| 1171 | verbose = 1; |
| 1172 | argc--; |
| 1173 | argv++; |
| 1174 | } |
| 1175 | |
| 1176 | switch (argc) { |
| 1177 | case 4: |
| 1178 | limit = argv[3]; |
| 1179 | /* FALLTHROUGH */ |
| 1180 | case 3: |
| 1181 | head = argv[2]; |
| 1182 | /* FALLTHROUGH */ |
| 1183 | case 2: |
| 1184 | upstream = argv[1]; |
| 1185 | break; |
| 1186 | default: |
Markus Heidelberg | f296802 | 2008-12-29 18:45:20 +0100 | [diff] [blame] | 1187 | current_branch = branch_get(NULL); |
| 1188 | if (!current_branch || !current_branch->merge |
| 1189 | || !current_branch->merge[0] |
| 1190 | || !current_branch->merge[0]->dst) { |
| 1191 | fprintf(stderr, "Could not find a tracked" |
| 1192 | " remote branch, please" |
| 1193 | " specify <upstream> manually.\n"); |
| 1194 | usage(cherry_usage); |
| 1195 | } |
| 1196 | |
| 1197 | upstream = current_branch->merge[0]->dst; |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | init_revisions(&revs, prefix); |
| 1201 | revs.diff = 1; |
| 1202 | revs.combine_merges = 0; |
| 1203 | revs.ignore_merges = 1; |
Pierre Habouzit | 8f67f8a | 2007-11-10 20:05:14 +0100 | [diff] [blame] | 1204 | DIFF_OPT_SET(&revs.diffopt, RECURSIVE); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1205 | |
| 1206 | if (add_pending_commit(head, &revs, 0)) |
| 1207 | die("Unknown commit %s", head); |
| 1208 | if (add_pending_commit(upstream, &revs, UNINTERESTING)) |
| 1209 | die("Unknown commit %s", upstream); |
| 1210 | |
| 1211 | /* Don't say anything if head and upstream are the same. */ |
| 1212 | if (revs.pending.nr == 2) { |
| 1213 | struct object_array_entry *o = revs.pending.objects; |
| 1214 | if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0) |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1218 | get_patch_ids(&revs, &ids, prefix); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1219 | |
| 1220 | if (limit && add_pending_commit(limit, &revs, UNINTERESTING)) |
| 1221 | die("Unknown commit %s", limit); |
| 1222 | |
| 1223 | /* reverse the list of commits */ |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 1224 | if (prepare_revision_walk(&revs)) |
| 1225 | die("revision walk setup failed"); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1226 | while ((commit = get_revision(&revs)) != NULL) { |
| 1227 | /* ignore merges */ |
| 1228 | if (commit->parents && commit->parents->next) |
| 1229 | continue; |
| 1230 | |
| 1231 | commit_list_insert(commit, &list); |
| 1232 | } |
| 1233 | |
| 1234 | while (list) { |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1235 | char sign = '+'; |
| 1236 | |
| 1237 | commit = list->item; |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1238 | if (has_commit_patch_id(commit, &ids)) |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1239 | sign = '-'; |
| 1240 | |
| 1241 | if (verbose) { |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 1242 | struct strbuf buf = STRBUF_INIT; |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 1243 | pretty_print_commit(CMIT_FMT_ONELINE, commit, |
Junio C Hamano | 4593fb8 | 2007-10-31 14:55:17 -0700 | [diff] [blame] | 1244 | &buf, 0, NULL, NULL, 0, 0); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1245 | printf("%c %s %s\n", sign, |
Pierre Habouzit | 674d172 | 2007-09-10 12:35:06 +0200 | [diff] [blame] | 1246 | sha1_to_hex(commit->object.sha1), buf.buf); |
| 1247 | strbuf_release(&buf); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1248 | } |
| 1249 | else { |
| 1250 | printf("%c %s\n", sign, |
| 1251 | sha1_to_hex(commit->object.sha1)); |
| 1252 | } |
| 1253 | |
| 1254 | list = list->next; |
| 1255 | } |
| 1256 | |
Junio C Hamano | 5d23e13 | 2007-04-09 17:01:27 -0700 | [diff] [blame] | 1257 | free_patch_ids(&ids); |
Rene Scharfe | e827633 | 2006-10-24 01:01:57 +0200 | [diff] [blame] | 1258 | return 0; |
| 1259 | } |