From: Zach Welch <zw@superlucidity.net>
To: git@vger.kernel.org
Cc: torvalds@osdl.org
Subject: [PATCH 1/3] add GIT_CACHE_DIRECTORY support
Date: Tue, 19 Apr 2005 21:32:06 -0700 [thread overview]
Message-ID: <mailbox-1370-1113971526-293449@spoon> (raw)
In-Reply-To: mailbox-1370-1113971526-282751@spoon
cache.h | 3 +++
init-db.c | 9 +++++++--
read-cache.c | 15 +++++++++++++--
read-tree.c | 35 ++++++++++++++++++++++++++---------
update-cache.c | 33 ++++++++++++++++++++++++---------
5 files changed, 73 insertions(+), 22 deletions(-)
Signed-Off-By: Zach Welch <zw@superlucidity.net>
This patch introduces the GIT_CACHE_DIRECTORY to the C plumbing.
Without this patch, the index file and its lock are always placed
in './.git'. Scripts wishing to run these commands from a different
working directory can use this support to override the cache directory.
This require my latest init-db cleanups be applied first, otherwise
you will get a rejection in init-db.c.
cache.h: 5948db759b3f6fb5ade3b027f202330f71a8cb6a
--- a/cache.h
+++ b/cache.h
@@ -81,6 +81,9 @@ const char *sha1_file_directory;
struct cache_entry **active_cache;
unsigned int active_nr, active_alloc;
+#define GIT_CACHE_ENVIRONMENT "GIT_CACHE_DIRECTORY"
+#define DEFAULT_GIT_CACHE_ENVIRONMENT ".git"
+
#define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
#define DEFAULT_DB_ENVIRONMENT ".git/objects"
init-db.c: 14beb35657de229a61673198bfc4e009daafca15
--- a/init-db.c
+++ b/init-db.c
@@ -23,10 +23,15 @@ void safe_create_dir(char *dir)
*/
int main(int argc, char **argv)
{
- char *sha1_dir, *path;
+ char *sha1_dir, *path, *git_dir;
int len, i;
- safe_create_dir(".git");
+ git_dir = getenv(GIT_CACHE_ENVIRONMENT);
+ if (!git_dir) {
+ git_dir = DEFAULT_GIT_CACHE_ENVIRONMENT;
+ fprintf(stderr, "defaulting to local cache area\n");
+ }
+ safe_create_dir(git_dir);
sha1_dir = getenv(DB_ENVIRONMENT);
if (!sha1_dir) {
read-cache.c: edaadf3e1c0714735ca8d80301dd644aa0f9cd2a
--- a/read-cache.c
+++ b/read-cache.c
@@ -174,22 +174,33 @@ static int verify_hdr(struct cache_heade
int read_cache(void)
{
- int fd, i;
+ int fd, i, len;
struct stat st;
unsigned long size, offset;
void *map;
struct cache_header *hdr;
+ char *index_path, *index_file;
errno = EBUSY;
if (active_cache)
return error("more than one cachefile");
errno = ENOENT;
+
sha1_file_directory = getenv(DB_ENVIRONMENT);
if (!sha1_file_directory)
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);
+
+ index_path = getenv(GIT_CACHE_ENVIRONMENT);
+ if (!index_path)
+ index_path = DEFAULT_GIT_CACHE_ENVIRONMENT;
+ len = strlen(index_path);
+ index_file = malloc(len + 7);
+ if (!index_file) error("out of memory");
+ sprintf(index_file, "%s/index", index_path);
+
+ fd = open(index_file, O_RDONLY);
if (fd < 0)
return (errno == ENOENT) ? 0 : error("open failed");
read-tree.c: 9bcba2d567e1c86ae967d383cc081e6947d00a13
--- a/read-tree.c
+++ b/read-tree.c
@@ -65,12 +65,12 @@ static int read_tree(unsigned char *sha1
return 0;
}
-static int remove_lock = 0;
+static char *index_lock = NULL;
static void remove_lock_file(void)
{
- if (remove_lock)
- unlink(".git/index.lock");
+ if (index_lock)
+ unlink(index_lock);
}
static int path_matches(struct cache_entry *a, struct cache_entry *b)
@@ -205,14 +205,27 @@ static void merge_stat_info(struct cache
int main(int argc, char **argv)
{
- int i, newfd, merge;
+ int i, newfd, len, merge;
unsigned char sha1[20];
-
- newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
+ char *index_file, *index_path;
+
+ index_path = getenv(GIT_CACHE_ENVIRONMENT);
+ if (!index_path)
+ index_path = DEFAULT_GIT_CACHE_ENVIRONMENT;
+
+ len = strlen(index_path);
+ index_file = malloc(len + 7);
+ if (!index_file) error("out of memory");
+ sprintf(index_file, "%s/index", index_path);
+
+ index_lock = malloc(len + 12);
+ if (!index_lock) error("out of memory");
+ sprintf(index_lock, "%s/index.lock", index_path);
+
+ newfd = open(index_lock, O_RDWR | O_CREAT | O_EXCL, 0600);
if (newfd < 0)
die("unable to create new cachefile");
atexit(remove_lock_file);
- remove_lock = 1;
merge = 0;
for (i = 1; i < argc; i++) {
@@ -253,8 +266,12 @@ int main(int argc, char **argv)
}
}
if (write_cache(newfd, active_cache, active_nr) ||
- rename(".git/index.lock", ".git/index"))
+ rename(index_lock, index_file))
die("unable to write new index file");
- remove_lock = 0;
+
+ free(index_file);
+ free(index_lock);
+ index_lock = NULL;
+
return 0;
}
update-cache.c: 0d16b36d7d074e9f0a2811a40e16e9823a628ec9
--- a/update-cache.c
+++ b/update-cache.c
@@ -270,25 +270,37 @@ static int add_cacheinfo(char *arg1, cha
return add_cache_entry(ce, allow_add);
}
-static int remove_lock = 0;
+static char *index_lock = NULL;
static void remove_lock_file(void)
{
- if (remove_lock)
- unlink(".git/index.lock");
+ if (index_lock)
+ unlink(index_lock);
}
int main(int argc, char **argv)
{
- int i, newfd, entries;
+ int i, newfd, entries, len;
int allow_options = 1;
+ char *index_file, *index_path;
- newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
+ index_path = getenv(GIT_CACHE_ENVIRONMENT);
+ if (!index_path)
+ index_path = DEFAULT_GIT_CACHE_ENVIRONMENT;
+
+ len = strlen(index_path);
+ index_file = malloc(len + 7);
+ if (!index_file) error("out of memory");
+ sprintf(index_file, "%s/index", index_path);
+
+ index_lock = malloc(len + 12);
+ if (!index_lock) error("out of memory");
+ sprintf(index_lock, "%s/index.lock", index_path);
+
+ newfd = open(index_lock, O_RDWR | O_CREAT | O_EXCL, 0600);
if (newfd < 0)
die("unable to create new cachefile");
-
atexit(remove_lock_file);
- remove_lock = 1;
entries = read_cache();
if (entries < 0)
@@ -330,9 +342,12 @@ int main(int argc, char **argv)
die("Unable to add %s to database", path);
}
if (write_cache(newfd, active_cache, active_nr) ||
- rename(".git/index.lock", ".git/index"))
+ rename(index_lock, index_file))
die("Unable to write new cachefile");
- remove_lock = 0;
+ free(index_file);
+ free(index_lock);
+ index_lock = NULL;
+
return 0;
}
reply other threads:[~2005-04-20 4:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mailbox-1370-1113971526-293449@spoon \
--to=zw@superlucidity.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).