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

merge-recursive: move the global obuf to struct merge_options

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>

Miklos Vajna committed Sep 3, 2008 at 02:30 UTC c7d849243a4be2c60ff48cc42ea8b0518bb7f27f
2 files changed +19 -19
merge-recursive.c
+18 -19
@@ -80,18 +80,16 @@ struct stage_data
80 static struct string_list current_file_set = {NULL, 0, 0, 1};
81 static struct string_list current_directory_set = {NULL, 0, 0, 1};
82
83 -static struct strbuf obuf = STRBUF_INIT;
84 -
83 static int show(struct merge_options *o, int v)
84 {
85 return (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;
86 }
87
90 -static void flush_output(void)
88 +static void flush_output(struct merge_options *o)
89 {
92 - if (obuf.len) {
93 - fputs(obuf.buf, stdout);
94 - strbuf_reset(&obuf);
90 + if (o->obuf.len) {
91 + fputs(o->obuf.buf, stdout);
92 + strbuf_reset(&o->obuf);
93 }
94 }
95
@@ -103,35 +101,35 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
101 if (!show(o, v))
102 return;
103
106 - strbuf_grow(&obuf, o->call_depth * 2 + 2);
107 - memset(obuf.buf + obuf.len, ' ', o->call_depth * 2);
108 - strbuf_setlen(&obuf, obuf.len + o->call_depth * 2);
104 + strbuf_grow(&o->obuf, o->call_depth * 2 + 2);
105 + memset(o->obuf.buf + o->obuf.len, ' ', o->call_depth * 2);
106 + strbuf_setlen(&o->obuf, o->obuf.len + o->call_depth * 2);
107
108 va_start(ap, fmt);
111 - len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
109 + len = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);
110 va_end(ap);
111
112 if (len < 0)
113 len = 0;
116 - if (len >= strbuf_avail(&obuf)) {
117 - strbuf_grow(&obuf, len + 2);
114 + if (len >= strbuf_avail(&o->obuf)) {
115 + strbuf_grow(&o->obuf, len + 2);
116 va_start(ap, fmt);
119 - len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
117 + len = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);
118 va_end(ap);
121 - if (len >= strbuf_avail(&obuf)) {
119 + if (len >= strbuf_avail(&o->obuf)) {
120 die("this should not happen, your snprintf is broken");
121 }
122 }
125 - strbuf_setlen(&obuf, obuf.len + len);
126 - strbuf_add(&obuf, "\n", 1);
123 + strbuf_setlen(&o->obuf, o->obuf.len + len);
124 + strbuf_add(&o->obuf, "\n", 1);
125 if (!o->buffer_output)
128 - flush_output();
126 + flush_output(o);
127 }
128
129 static void output_commit_title(struct merge_options *o, struct commit *commit)
130 {
131 int i;
134 - flush_output();
132 + flush_output(o);
133 for (i = o->call_depth; i--;)
134 fputs(" ", stdout);
135 if (commit->util)
@@ -1289,7 +1287,7 @@ int merge_recursive(struct merge_options *o,
1287 commit_list_insert(h1, &(*result)->parents);
1288 commit_list_insert(h2, &(*result)->parents->next);
1289 }
1292 - flush_output();
1290 + flush_output(o);
1291 return clean;
1292 }
1293
@@ -1375,4 +1373,5 @@ void init_merge_options(struct merge_options *o)
1373 strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);
1374 if (o->verbosity >= 5)
1375 o->buffer_output = 0;
1376 + strbuf_init(&o->obuf, 0);
1377 }
merge-recursive.h
+1
@@ -10,6 +10,7 @@ struct merge_options {
10 int diff_rename_limit;
11 int merge_rename_limit;
12 int call_depth;
13 + struct strbuf obuf;
14 };
15
16 /* merge_trees() but with recursive ancestor consolidation */