From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Allow multiple "git_path()" uses
Date: Mon, 11 Sep 2006 12:03:15 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0609111158390.3960@g5.osdl.org> (raw)
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;
next reply other threads:[~2006-09-11 19:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-11 19:03 Linus Torvalds [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0609111158390.3960@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).