Re: [PATCH v6 6/7] git-reflog: add create and exists functions

Subsystems: the rest

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v6 6/7] git-reflog: add create and exists functions

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:05:36

Eric Sunshine [off-list ref] writes:
quoted
quoted
Alternatives would be strbuf_reset() or declaring and releasing the
strbuf within the for-loop scope.
Because _reset() just rewinds the .len pointer without deallocating,
you would need an extra _release() before it goes out of scope. If
it is expected that the strbuf will be reused for a number of times,
the length of the string each iteration uses is similar, and you
will iterate the loop many times, "_reset() each time and _release()
to clean-up" pattern would save many calls to realloc/free.
Yep, that's why I suggested strbuf_reset() as an alternative (and
likely would have chosen it myself).
OK, then let's do that by squashing this in.

 builtin/reflog.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 3080865..e9ba600 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -733,10 +733,11 @@ static int cmd_reflog_create(int argc, const char **argv, const char *prefix)
 		if (safe_create_reflog(argv[i], &err, 1)) {
 			error("could not create reflog %s: %s", argv[i],
 			      err.buf);
+			strbuf_reset(&err);
 			status = 1;
-			strbuf_release(&err);
 		}
 	}
+	strbuf_release(&err);
 	return status;
 }
 

Re: [PATCH v6 6/7] git-reflog: add create and exists functions

From: David Turner <hidden>
Date: 2016-06-15 23:05:36

On Tue, 2015-06-30 at 12:48 -0700, Junio C Hamano wrote:
Eric Sunshine [off-list ref] writes:
quoted
quoted
quoted
Alternatives would be strbuf_reset() or declaring and releasing the
strbuf within the for-loop scope.
Because _reset() just rewinds the .len pointer without deallocating,
you would need an extra _release() before it goes out of scope. If
it is expected that the strbuf will be reused for a number of times,
the length of the string each iteration uses is similar, and you
will iterate the loop many times, "_reset() each time and _release()
to clean-up" pattern would save many calls to realloc/free.
Yep, that's why I suggested strbuf_reset() as an alternative (and
likely would have chosen it myself).
OK, then let's do that by squashing this in.

 builtin/reflog.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
I squashed that into my repo on github:

https://github.com/dturner-tw/git.git
on the branch dturner/pluggable-backends-preamble
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help