@matheusbsbs / matheus-bagliano / commits / 7ae0b0cb65
Fork 0

git-log (internal): more options.

This ports the following options from rev-list based git-log implementation: * -<n>, -n<n>, and -n <n>. I am still wondering if we want this natively supported by setup_revisions(), which already takes --max-count. We may want to move them in the next round. Also I am not sure if we can get away with not setting revs->limited when we set max-count. The latest rev-list.c and revision.c in this series do not, so I left them as they are. * --pretty and --pretty=<fmt>. * --abbrev=<n> and --no-abbrev. The previous commit already handles time-based limiters (--since, --until and friends). The remaining things that rev-list based git-log happens to do are not useful in a pure log-viewing purposes, and not ported: * --bisect (obviously). * --header. I am actually in favor of doing the NUL terminated record format, but rev-list based one always passed --pretty, which defeated this option. Maybe next round. * --parents. I do not think of a reason a log viewer wants this. The flag is primarily for feeding squashed history via pipe to downstream tools. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 1, 2006 at 00:58 UTC 7ae0b0cb65f069b657155abcb6aa6780b93ce881
3 files changed +72 -4
git.c
+69 -1
@@ -256,12 +256,80 @@ static int cmd_log(int argc, char **argv, char **envp)
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);
rev-list.c
+2 -3
@@ -7,10 +7,9 @@
7 #include "diff.h"
8 #include "revision.h"
9
10 -/* bits #0-3 in revision.h */
10 +/* bits #0-4 in revision.h */
11
12 -#define COUNTED (1u << 4)
13 -#define TMP_MARK (1u << 5) /* for isolated cases; clean after use */
12 +#define COUNTED (1u<<5)
13
14 static const char rev_list_usage[] =
15 "git-rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
revision.h
+1
@@ -5,6 +5,7 @@
5 #define UNINTERESTING (1u<<1)
6 #define TREECHANGE (1u<<2)
7 #define SHOWN (1u<<3)
8 +#define TMP_MARK (1u<<4) /* for isolated cases; clean after use */
9
10 struct rev_info {
11 /* Starting list */