256
struct rev_info rev;
257
struct commit *commit;
258
char *buf = xmalloc(LOGSIZE);
259
+ static enum cmit_fmt commit_format = CMIT_FMT_DEFAULT;
260
+ int abbrev = DEFAULT_ABBREV;
261
+ int show_parents = 0;
262
+ const char *commit_prefix = "commit ";
263
264
argc = setup_revisions(argc, argv, &rev, "HEAD");
265
+ while (1 < argc) {
266
+ char *arg = argv[1];
267
+ /* accept -<digit>, like traditilnal "head" */
268
+ if ((*arg == '-') && isdigit(arg[1])) {
269
+ rev.max_count = atoi(arg + 1);
270
+ }
271
+ else if (!strcmp(arg, "-n")) {
272
+ if (argc < 2)
273
+ die("-n requires an argument");
274
+ rev.max_count = atoi(argv[2]);
275
+ argc--; argv++;
276
+ }
277
+ else if (!strncmp(arg,"-n",2)) {
278
+ rev.max_count = atoi(arg + 2);
279
+ }
280
+ else if (!strncmp(arg, "--pretty", 8)) {
281
+ commit_format = get_commit_format(arg + 8);
282
+ if (commit_format == CMIT_FMT_ONELINE)
283
+ commit_prefix = "";
284
+ }
285
+ else if (!strcmp(arg, "--parents")) {
286
+ show_parents = 1;
287
+ }
288
+ else if (!strcmp(arg, "--no-abbrev")) {
289
+ abbrev = 0;
290
+ }
291
+ else if (!strncmp(arg, "--abbrev=", 9)) {
292
+ abbrev = strtoul(arg + 9, NULL, 10);
293
+ if (abbrev && abbrev < MINIMUM_ABBREV)
294
+ abbrev = MINIMUM_ABBREV;
295
+ else if (40 < abbrev)
296
+ abbrev = 40;
297
+ }
298
+ else
299
+ die("unrecognized argument: %s", arg);
300
+ argc--; argv++;
301
+ }
302
+
303
prepare_revision_walk(&rev);
304
setup_pager();
305
while ((commit = get_revision(&rev)) != NULL) {
264
- pretty_print_commit(CMIT_FMT_DEFAULT, commit, ~0, buf, LOGSIZE, 18);
306
+ printf("%s%s", commit_prefix,
307
+ sha1_to_hex(commit->object.sha1));
308
+ if (show_parents) {
309
+ struct commit_list *parents = commit->parents;
310
+ while (parents) {
311
+ struct object *o = &(parents->item->object);
312
+ parents = parents->next;
313
+ if (o->flags & TMP_MARK)
314
+ continue;
315
+ printf(" %s", sha1_to_hex(o->sha1));
316
+ o->flags |= TMP_MARK;
317
+ }
318
+ /* TMP_MARK is a general purpose flag that can
319
+ * be used locally, but the user should clean
320
+ * things up after it is done with them.
321
+ */
322
+ for (parents = commit->parents;
323
+ parents;
324
+ parents = parents->next)
325
+ parents->item->object.flags &= ~TMP_MARK;
326
+ }
327
+ if (commit_format == CMIT_FMT_ONELINE)
328
+ putchar(' ');
329
+ else
330
+ putchar('\n');
331
+ pretty_print_commit(commit_format, commit, ~0, buf,
332
+ LOGSIZE, abbrev);
333
printf("%s\n", buf);
334
}
335
free(buf);