summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLibravatar Petr Baudis <pasky@suse.cz>2006-07-03 22:48:03 +0200
committerLibravatar Junio C Hamano <junkio@cox.net>2006-07-09 01:20:01 -0700
commit0270083ded143fd49841e3d3d0cac5eb06081d2a (patch)
tree960e1b85a2b18225a466bbf4aff040b27c581594 /sha1_file.c
parentWork around sed and make interactions on the backslash at the end of line. (diff)
downloadtgif-0270083ded143fd49841e3d3d0cac5eb06081d2a.tar.xz
Make it possible to set up libgit directly (instead of from the environment)
This introduces a setup_git() function which is essentialy a (public) backend for setup_git_env() which lets anyone specify custom sources for the various paths instead of environment variables. Since the repositories may get switched on the fly, this also updates code that caches paths to invalidate them properly; I hope neither of those is a sweet spot. It is used by Git.xs' xs__call_gate() to set up per-repository data for libgit's consumption. No code actually takes advantage of it yet but get_object() will in the next patches. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 817963045b..ab64543d4a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -126,16 +126,22 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
char *sha1_file_name(const unsigned char *sha1)
{
static char *name, *base;
+ static const char *last_objdir;
+ const char *sha1_file_directory = get_object_directory();
- if (!base) {
- const char *sha1_file_directory = get_object_directory();
+ if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
int len = strlen(sha1_file_directory);
+ if (base)
+ free(base);
base = xmalloc(len + 60);
memcpy(base, sha1_file_directory, len);
memset(base+len, 0, 60);
base[len] = '/';
base[len+3] = '/';
name = base + len + 1;
+ if (last_objdir)
+ free((char *) last_objdir);
+ last_objdir = strdup(sha1_file_directory);
}
fill_sha1_path(name, sha1);
return base;
@@ -145,14 +151,20 @@ char *sha1_pack_name(const unsigned char *sha1)
{
static const char hex[] = "0123456789abcdef";
static char *name, *base, *buf;
+ static const char *last_objdir;
+ const char *sha1_file_directory = get_object_directory();
int i;
- if (!base) {
- const char *sha1_file_directory = get_object_directory();
+ if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
int len = strlen(sha1_file_directory);
+ if (base)
+ free(base);
base = xmalloc(len + 60);
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.pack", sha1_file_directory);
name = base + len + 11;
+ if (last_objdir)
+ free((char *) last_objdir);
+ last_objdir = strdup(sha1_file_directory);
}
buf = name;
@@ -170,14 +182,20 @@ char *sha1_pack_index_name(const unsigned char *sha1)
{
static const char hex[] = "0123456789abcdef";
static char *name, *base, *buf;
+ static const char *last_objdir;
+ const char *sha1_file_directory = get_object_directory();
int i;
- if (!base) {
- const char *sha1_file_directory = get_object_directory();
+ if (!last_objdir || strcmp(last_objdir, sha1_file_directory)) {
int len = strlen(sha1_file_directory);
+ if (base)
+ free(base);
base = xmalloc(len + 60);
sprintf(base, "%s/pack/pack-1234567890123456789012345678901234567890.idx", sha1_file_directory);
name = base + len + 11;
+ if (last_objdir)
+ free((char *) last_objdir);
+ last_objdir = strdup(sha1_file_directory);
}
buf = name;