threads / patch / 13514

patchgraph.c: fix padding

Subject: [PATCH] graph.c: fix padding

## tl;dr

2 messages between May 14, 2008 and May 15, 2008. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Johannes Schindelin· May 14, 2008, 14:22 UTC · lore
There were two instances of "%*s" which want to be "%.*s" instead.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 graph.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to graph.c +2 −2
diff --git a/graph.c b/graph.c
index 9d6ed30..f3e2eed 100644
--- a/graph.c
+++ b/graph.c
@@ -422,7 +422,7 @@ static void graph_pad_horizontally(struct git_graph *graph, struct strbuf *sb)
 		return;
 
 	extra = graph->width - sb->len;
-	strbuf_addf(sb, "%*s", (int) extra, "");
+	strbuf_addf(sb, "%.*s", (int) extra, "");
 }
 
 static void graph_output_padding_line(struct git_graph *graph,
@@ -496,7 +496,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
 		struct column *col = &graph->columns[i];
 		if (col->commit == graph->commit) {
 			seen_this = 1;
-			strbuf_addf(sb, "| %*s", graph->expansion_row, "");
+			strbuf_addf(sb, "| %.*s", graph->expansion_row, "");
 		} else if (seen_this) {
 			strbuf_addstr(sb, "\\ ");
 		} else {
-- 
1.5.5.1.375.g1becb
Johannes Schindelin· May 15, 2008, 08:50 UTC · re: Johannes Schindelin · lore

Re: [PATCH] graph.c: fix padding

Hi,
On Wed, 14 May 2008, Johannes Schindelin wrote:
Show 6 quoted lines
> There were two instances of "%*s" which want to be "%.*s" instead.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  graph.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
I am a moron.

Remember when I implemented a custom strbuf_vaddf() implementation that did not suffer these workarounds we have for "broken vaddf()" on AIX and Windows?

Well, I completely forgot about it, but I still have it in my personal tree.

And this implementation did not support "%*s", since there was no user for it before the addition of the --graph stuff.

So I have this in my tree now instead of the "fix" I am replying to:

-- snipsnap -- [PATCH] strbuf_vaddf(): support %*s, too

The recent addition of graph.c broke things with our custom implementation of strbuf_vaddf(), because "%*s" was not yet supported (because it did not have any users before).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 strbuf.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Show changes to strbuf.c +6 −0
diff --git a/strbuf.c b/strbuf.c
index 466f999..8c11f15 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -155,6 +155,12 @@ void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
 			fill = *p++;
 		if (isdigit(*p))
 			size = (int)strtol(p, &p, 10);
+		else if (*p == '*') {
+			size = va_arg(ap, int);
+			if (!fill)
+				fill = ' ';
+			p++;
+		}
 		else if (!prefixcmp(p, ".*")) {
 			max_size = va_arg(ap, int);
 			p += 2;
-- 
1.5.5.1.375.g1becb

← back to recent threads