summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 65bb491)
raw | patch | inline | side by side (parent: 65bb491)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Thu, 21 Apr 2005 17:55:18 +0000 (10:55 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Thu, 21 Apr 2005 17:55:18 +0000 (10:55 -0700) |
We use that to specify alternative index files, which can be useful
if you want to (for example) generate a temporary index file to do
some specific operation that you don't want to mess with your main
one with.
It defaults to the regular ".git/index" if it hasn't been specified.
if you want to (for example) generate a temporary index file to do
some specific operation that you don't want to mess with your main
one with.
It defaults to the regular ".git/index" if it hasn't been specified.
cache.h | patch | blob | history | |
checkout-cache.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
read-tree.c | patch | blob | history | |
show-files.c | patch | blob | history | |
update-cache.c | patch | blob | history |
index 378299a0349cc4bb28ede53599d87a30cbb6a090..02b6a73117c6aaf3f10477e9afd13229fa88dd46 100644 (file)
--- a/cache.h
+++ b/cache.h
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
+#include <sys/param.h>
#include <netinet/in.h>
#include <openssl/sha.h>
#define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
#define DEFAULT_DB_ENVIRONMENT ".git/objects"
+#define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)
+
+#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
+#define DEFAULT_INDEX_ENVIRONMENT ".git/index"
+
+#define get_index_file() (getenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)
+
#define alloc_nr(x) (((x)+16)*3/2)
/* Initialize and use the cache information */
diff --git a/checkout-cache.c b/checkout-cache.c
index 972b1f776e49f82eaf9e10ecd013bce0e2529915..f65be62b4abad184bd755884fb72681fc28c8b3b 100644 (file)
--- a/checkout-cache.c
+++ b/checkout-cache.c
* of "-a" causing problems (not possible in the above example,
* but get used to it in scripting!).
*/
-#include <sys/param.h>
-
#include "cache.h"
static int force = 0, quiet = 0;
diff --git a/read-cache.c b/read-cache.c
index 44a713aed6d5d3f051dd7a709ceb9044869cf783..4b668be47d378d3127230974613db5e0db19d806 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
if (access(sha1_file_directory, X_OK) < 0)
return error("no access to SHA1 file directory");
- fd = open(".git/index", O_RDONLY);
+ fd = open(get_index_file(), O_RDONLY);
if (fd < 0)
return (errno == ENOENT) ? 0 : error("open failed");
diff --git a/read-tree.c b/read-tree.c
index 53351f05c74cb892530c2d351592cc0cc1a1274c..8121e30671718737328f0ea3189ed7f69b31ce8b 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
return read_tree_recursive(buffer, "tree", size, base, baselen);
}
-static int remove_lock = 0;
+static char *lockfile_name;
static void remove_lock_file(void)
{
- if (remove_lock)
- unlink(".git/index.lock");
+ if (lockfile_name)
+ unlink(lockfile_name);
}
static int path_matches(struct cache_entry *a, struct cache_entry *b)
{
int i, newfd, merge;
unsigned char sha1[20];
+ static char lockfile[MAXPATHLEN+1];
+ const char *indexfile = get_index_file();
- newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
+ snprintf(lockfile, sizeof(lockfile), "%s.lock", indexfile);
+
+ newfd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0600);
if (newfd < 0)
die("unable to create new cachefile");
atexit(remove_lock_file);
- remove_lock = 1;
+ lockfile_name = lockfile;
merge = 0;
for (i = 1; i < argc; i++) {
die("just how do you expect me to merge %d trees?", stage-1);
}
}
- if (write_cache(newfd, active_cache, active_nr) ||
- rename(".git/index.lock", ".git/index"))
+ if (write_cache(newfd, active_cache, active_nr) || rename(lockfile, indexfile))
die("unable to write new index file");
- remove_lock = 0;
+ lockfile_name = NULL;
return 0;
}
diff --git a/show-files.c b/show-files.c
index b1a8e3dd5556b61dd771d32307c6ee5d7150fa43..b53ab1053e1acf7e2a1e9c97a4d87b76e8ee238e 100644 (file)
--- a/show-files.c
+++ b/show-files.c
* Copyright (C) Linus Torvalds, 2005
*/
#include <dirent.h>
-#include <sys/param.h>
#include "cache.h"
diff --git a/update-cache.c b/update-cache.c
index 8ec69e22b4e32a84cc8575a8eec349cec5b24fc0..4353b80890ba2afbe22248a4dc25060aa4a429b2 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
return add_cache_entry(ce, allow_add);
}
-static int remove_lock = 0;
+static const char *lockfile_name = NULL;
static void remove_lock_file(void)
{
- if (remove_lock)
- unlink(".git/index.lock");
+ if (lockfile_name)
+ unlink(lockfile_name);
}
int main(int argc, char **argv)
{
int i, newfd, entries;
int allow_options = 1;
+ static char lockfile[MAXPATHLEN+1];
+ const char *indexfile = get_index_file();
- newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
+ snprintf(lockfile, sizeof(lockfile), "%s.lock", indexfile);
+
+ newfd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0600);
if (newfd < 0)
die("unable to create new cachefile");
atexit(remove_lock_file);
- remove_lock = 1;
+ lockfile_name = lockfile;
entries = read_cache();
if (entries < 0)
if (add_file_to_cache(path))
die("Unable to add %s to database", path);
}
- if (write_cache(newfd, active_cache, active_nr) ||
- rename(".git/index.lock", ".git/index"))
+ if (write_cache(newfd, active_cache, active_nr) || rename(lockfile, indexfile))
die("Unable to write new cachefile");
- remove_lock = 0;
+ lockfile_name = NULL;
return 0;
}