@matheusbsbs / matheus-bagliano / commits / cdcefbc971
Fork 0

Add "--early-output" log flag for interactive GUI use

This adds support for "--early-output[=n]" as a flag to the "git log" family of commands. This allows GUI programs to state that they want to get some output early, in order to be able to show at least something quickly, even if the full output may take longer to generate. If no count is specified, a default count of a hundred commits will be used, although the actual numbr of commits output may be smaller depending on how many commits were actually found in the first tenth of a second (or if *everything* was found before that, in which case no early output will be provided, and only the final list is made available). When the full list is generated, there will be a "Final output:" string prepended to it, regardless of whether any early commits were shown or not, so that the consumer can always know the difference between early output and the final list. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Nov 3, 2007 at 11:11 UTC cdcefbc971d8fcdd293750af7571d4c715f86964
3 files changed +93
builtin-log.c
+67
@@ -77,11 +77,78 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
77 }
78 }
79
80 +static void log_show_early(struct rev_info *revs, struct commit_list *list)
81 +{
82 + int i = revs->early_output;
83 +
84 + sort_in_topological_order(&list, revs->lifo);
85 + while (list && i) {
86 + struct commit *commit = list->item;
87 + log_tree_commit(revs, commit);
88 + list = list->next;
89 + i--;
90 + }
91 +}
92 +
93 +static void early_output(int signal)
94 +{
95 + show_early_output = log_show_early;
96 +}
97 +
98 +static void setup_early_output(struct rev_info *rev)
99 +{
100 + struct sigaction sa;
101 + struct itimerval v;
102 +
103 + /*
104 + * Set up the signal handler, minimally intrusively:
105 + * we only set a single volatile integer word (not
106 + * using sigatomic_t - trying to avoid unnecessary
107 + * system dependencies and headers), and using
108 + * SA_RESTART.
109 + */
110 + memset(&sa, 0, sizeof(sa));
111 + sa.sa_handler = early_output;
112 + sigemptyset(&sa.sa_mask);
113 + sa.sa_flags = SA_RESTART;
114 + sigaction(SIGALRM, &sa, NULL);
115 +
116 + /*
117 + * If we can get the whole output in less than a
118 + * tenth of a second, don't even bother doing the
119 + * early-output thing..
120 + *
121 + * This is a one-time-only trigger.
122 + */
123 + memset(&v, 0, sizeof(v));
124 + v.it_value.tv_sec = 0;
125 + v.it_value.tv_usec = 100000;
126 + setitimer(ITIMER_REAL, &v, NULL);
127 +}
128 +
129 +static void finish_early_output(struct rev_info *rev)
130 +{
131 + signal(SIGALRM, SIG_IGN);
132 + if (rev->shown_one) {
133 + rev->shown_one = 0;
134 + if (rev->commit_format != CMIT_FMT_ONELINE)
135 + putchar(rev->diffopt.line_termination);
136 + }
137 + printf("Final output:\n");
138 +}
139 +
140 static int cmd_log_walk(struct rev_info *rev)
141 {
142 struct commit *commit;
143
144 + if (rev->early_output)
145 + setup_early_output(rev);
146 +
147 prepare_revision_walk(rev);
148 +
149 + if (rev->early_output)
150 + finish_early_output(rev);
151 +
152 while ((commit = get_revision(rev)) != NULL) {
153 log_tree_commit(rev, commit);
154 if (!rev->reflog_info) {
revision.c
+22
@@ -10,6 +10,8 @@
10 #include "reflog-walk.h"
11 #include "patch-ids.h"
12
13 +volatile show_early_output_fn_t show_early_output;
14 +
15 static char *path_name(struct name_path *path, const char *name)
16 {
17 struct name_path *p;
@@ -533,6 +535,7 @@ static int limit_list(struct rev_info *revs)
535 struct commit_list *entry = list;
536 struct commit *commit = list->item;
537 struct object *obj = &commit->object;
538 + show_early_output_fn_t show;
539
540 list = list->next;
541 free(entry);
@@ -550,6 +553,13 @@ static int limit_list(struct rev_info *revs)
553 if (revs->min_age != -1 && (commit->date > revs->min_age))
554 continue;
555 p = &commit_list_insert(commit, p)->next;
556 +
557 + show = show_early_output;
558 + if (!show)
559 + continue;
560 +
561 + show(revs, newlist);
562 + show_early_output = NULL;
563 }
564 if (revs->cherry_pick)
565 cherry_pick_list(newlist, revs);
@@ -991,6 +1001,18 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1001 revs->topo_order = 1;
1002 continue;
1003 }
1004 + if (!prefixcmp(arg, "--early-output")) {
1005 + int count = 100;
1006 + switch (arg[14]) {
1007 + case '=':
1008 + count = atoi(arg+15);
1009 + /* Fallthrough */
1010 + case 0:
1011 + revs->topo_order = 1;
1012 + revs->early_output = count;
1013 + continue;
1014 + }
1015 + }
1016 if (!strcmp(arg, "--parents")) {
1017 revs->parents = 1;
1018 continue;
revision.h
+4
@@ -30,6 +30,8 @@ struct rev_info {
30 void *prune_data;
31 prune_fn_t *prune_fn;
32
33 + unsigned int early_output;
34 +
35 /* Traversal flags */
36 unsigned int dense:1,
37 no_merges:1,
@@ -105,6 +107,8 @@ struct rev_info {
107 #define REV_TREE_DIFFERENT 2
108
109 /* revision.c */
110 +typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
111 +volatile show_early_output_fn_t show_early_output;
112
113 extern void init_revisions(struct rev_info *revs, const char *prefix);
114 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);