git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Allow multiple "git_path()" uses
@ 2006-09-11 19:03 Linus Torvalds
  2006-09-11 23:37 ` Start handling references internally as a sorted in-memory list Linus Torvalds
  0 siblings, 1 reply; 21+ messages in thread
From: Linus Torvalds @ 2006-09-11 19:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List


This allows you to maintain a few filesystem pathnames concurrently, by 
simply replacing the single static "pathname" buffer with a LRU of four 
buffers.

We did exactly the same thing with sha1_to_hex(), for pretty much exactly 
the same reason. Sometimes you want to use two pathnames, and while it's 
easy enough to xstrdup() them, why not just do the LU buffer thing.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

[ This actually came up when I was playing with git_path("refs-packed") 
  when following refs, so while it doesn't hit us right now, it's for some 
  future work.. ]

diff --git a/path.c b/path.c
index db8905f..bb89fb0 100644
--- a/path.c
+++ b/path.c
@@ -13,9 +13,15 @@
 #include "cache.h"
 #include <pwd.h>
 
-static char pathname[PATH_MAX];
 static char bad_path[] = "/bad-path/";
 
+static char *get_pathname(void)
+{
+	static char pathname_array[4][PATH_MAX];
+	static int index;
+	return pathname_array[3 & ++index];
+}
+
 static char *cleanup_path(char *path)
 {
 	/* Clean it up */
@@ -31,6 +37,7 @@ char *mkpath(const char *fmt, ...)
 {
 	va_list args;
 	unsigned len;
+	char *pathname = get_pathname();
 
 	va_start(args, fmt);
 	len = vsnprintf(pathname, PATH_MAX, fmt, args);
@@ -43,6 +50,7 @@ char *mkpath(const char *fmt, ...)
 char *git_path(const char *fmt, ...)
 {
 	const char *git_dir = get_git_dir();
+	char *pathname = get_pathname();
 	va_list args;
 	unsigned len;
 

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2006-09-22  4:58 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-11 19:03 Allow multiple "git_path()" uses Linus Torvalds
2006-09-11 23:37 ` Start handling references internally as a sorted in-memory list Linus Torvalds
2006-09-11 23:50   ` Linus Torvalds
2006-09-11 23:57   ` Junio C Hamano
2006-09-12  1:05     ` Linus Torvalds
2006-09-12  1:09   ` Chris Wedgwood
2006-09-12  3:10   ` Add support for negative refs Linus Torvalds
2006-09-12  3:17     ` Make ref resolution saner Linus Torvalds
2006-09-12  5:36       ` Jeff King
2006-09-12 14:41         ` Linus Torvalds
2006-09-18  7:25   ` [RFC] git-pack-refs --prune Junio C Hamano
2006-09-18 16:47     ` Linus Torvalds
2006-09-18 18:44       ` Junio C Hamano
2006-09-21  7:02       ` Junio C Hamano
2006-09-21  7:06         ` [PATCH 1/5] symbolit-ref: fix resolve_ref conversion Junio C Hamano
2006-09-21  7:06         ` [PATCH 2/5] Add callback data to for_each_ref() family Junio C Hamano
2006-09-21  7:06         ` [PATCH 3/5] Tell between packed, unpacked and symbolic refs Junio C Hamano
2006-09-21  7:06         ` [PATCH 4/5] pack-refs: do not pack " Junio C Hamano
2006-09-21  7:06         ` [PATCH 5/5] git-pack-refs --prune Junio C Hamano
2006-09-21 15:19         ` [RFC] " Linus Torvalds
2006-09-22  4:57           ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).