git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] merge-recursive: move the global obuf to struct merge_options

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Sep 3, 2008, 00:39 UTC
Message-ID
<1220402349-7181-1-git-send-email-vmiklos@frugalware.org>
In-Reply-To
<7vk5dui34q.fsf@gitster.siamese.dyndns.org>
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Tue, Sep 02, 2008 at 03:39:33PM -0700, Junio C Hamano <gitster@pobox.com> wrote:
> Shouldn't strbuf obuf be part of the merge_options structure that
> describes the current call status?
It can be done, see below. :-)

BTW, there are 3 leftovers: make_virtual_commit()'s virtual_id and the global current_file_set/current_directory_set. I guess all of them could be moved to merge_options as well. (I don't have more time today to do so, but I can do it tomorrow, unless you see some fundamental problem with it.)

 merge-recursive.c |   37 ++++++++++++++++++-------------------
 merge-recursive.h |    1 +
 2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index c426589..d4f12d0 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -80,18 +80,16 @@ struct stage_data
 static struct string_list current_file_set = {NULL, 0, 0, 1};
 static struct string_list current_directory_set = {NULL, 0, 0, 1};
 
-static struct strbuf obuf = STRBUF_INIT;
-
 static int show(struct merge_options *o, int v)
 {
 	return (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;
 }
 
-static void flush_output(void)
+static void flush_output(struct merge_options *o)
 {
-	if (obuf.len) {
-		fputs(obuf.buf, stdout);
-		strbuf_reset(&obuf);
+	if (o->obuf.len) {
+		fputs(o->obuf.buf, stdout);
+		strbuf_reset(&o->obuf);
 	}
 }
 
@@ -103,35 +101,35 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
 	if (!show(o, v))
 		return;
 
-	strbuf_grow(&obuf, o->call_depth * 2 + 2);
-	memset(obuf.buf + obuf.len, ' ', o->call_depth * 2);
-	strbuf_setlen(&obuf, obuf.len + o->call_depth * 2);
+	strbuf_grow(&o->obuf, o->call_depth * 2 + 2);
+	memset(o->obuf.buf + o->obuf.len, ' ', o->call_depth * 2);
+	strbuf_setlen(&o->obuf, o->obuf.len + o->call_depth * 2);
 
 	va_start(ap, fmt);
-	len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
+	len = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);
 	va_end(ap);
 
 	if (len < 0)
 		len = 0;
-	if (len >= strbuf_avail(&obuf)) {
-		strbuf_grow(&obuf, len + 2);
+	if (len >= strbuf_avail(&o->obuf)) {
+		strbuf_grow(&o->obuf, len + 2);
 		va_start(ap, fmt);
-		len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
+		len = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);
 		va_end(ap);
-		if (len >= strbuf_avail(&obuf)) {
+		if (len >= strbuf_avail(&o->obuf)) {
 			die("this should not happen, your snprintf is broken");
 		}
 	}
-	strbuf_setlen(&obuf, obuf.len + len);
-	strbuf_add(&obuf, "\n", 1);
+	strbuf_setlen(&o->obuf, o->obuf.len + len);
+	strbuf_add(&o->obuf, "\n", 1);
 	if (!o->buffer_output)
-		flush_output();
+		flush_output(o);
 }
 
 static void output_commit_title(struct merge_options *o, struct commit *commit)
 {
 	int i;
-	flush_output();
+	flush_output(o);
 	for (i = o->call_depth; i--;)
 		fputs("  ", stdout);
 	if (commit->util)
@@ -1289,7 +1287,7 @@ int merge_recursive(struct merge_options *o,
 		commit_list_insert(h1, &(*result)->parents);
 		commit_list_insert(h2, &(*result)->parents->next);
 	}
-	flush_output();
+	flush_output(o);
 	return clean;
 }
 
@@ -1375,4 +1373,5 @@ void init_merge_options(struct merge_options *o)
 			strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);
 	if (o->verbosity >= 5)
 		o->buffer_output = 0;
+	strbuf_init(&o->obuf, 0);
 }
diff --git a/merge-recursive.h b/merge-recursive.h
index 4f55374..be84d9b 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -10,6 +10,7 @@ struct merge_options {
 	int diff_rename_limit;
 	int merge_rename_limit;
 	int call_depth;
+	struct strbuf obuf;
 };
 
 /* merge_trees() but with recursive ancestor consolidation */
-- 
1.6.0.1
Previous: Miklos VajnaNext: Miklos Vajna
Message 9 of 15 in “Move call_depth and index_only to struct merge_options”
  1. 0/2 Move call_depth and index_only to struct merge_optionsMiklos Vajna, Sep 2, 2008
  2. 1/2 merge-recursive: move call_depth to struct merge_optionsMiklos Vajna, Sep 2, 2008
  3. 2/2 merge-recursive: move index_only to struct merge_optionsMiklos Vajna, Sep 2, 2008
  4. Makefile: add merge_recursive.h to LIB_HMiklos Vajna, Sep 2, 2008
  5. Junio C HamanoSep 2, 2008
  6. Makefile: add merge_recursive.h to LIB_HMiklos Vajna, Sep 2, 2008
  7. Junio C HamanoSep 2, 2008
  8. merge-recursive: get rid of the index_only global variableMiklos Vajna, Sep 3, 2008
  9. merge-recursive: move the global obuf to struct merge_optionsMiklos Vajna, Sep 3, 2008
  10. Miklos VajnaSep 3, 2008
  11. 1/2 merge-recursive: move current_{file,directory}_set to struct merge_optionsMiklos Vajna, Sep 3, 2008
  12. 2/2 merge-recursive: move make_virtual_commit()'s virtual_id to merge_optionsMiklos Vajna, Sep 3, 2008
  13. Junio C HamanoSep 4, 2008
  14. merge-recursive: get rid of virtual_idMiklos Vajna, Sep 5, 2008
  15. Junio C HamanoSep 4, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.