Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly

From
Phillip Wood <hidden>
Date
2020-06-16 16:04:33
Reply to
Jeff King, 2020-06-16
Hi Peff

On 16/06/2020 14:10, Jeff King wrote:
On Mon, Jun 15, 2020 at 04:05:52PM +0100, Phillip Wood wrote:
quoted
quoted
@@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)
   	};
   	static struct hashmap refs;
   	static struct strbuf anon = STRBUF_INIT;
+	static char *main_branch;
[...]
quoted
-	if (!strcmp(refname, "refs/heads/master"))
+	if (!main_branch)
+		main_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);
+
+	if (!strcmp(refname, main_branch))
   		return "refs/heads/ref0";
This leaks main_branch if it came from git_main_branch_name()
It's a static that's used over and over, so I think it's intentional to
essentially memoize it for the life of the program
Oh you're right, I completely misread the patch

Thanks

Phillip
(at which point we
could free it, but don't bother to do so, letting the process exit take
care of it, and trusting in leak detectors to be aware that it's still
reachable, as we do for lots of other process-lifetime allocations).

-Peff
Thread (101 messages) 101 messages, 16 authors, last reply 2020-07-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help