Re: Handling renames.
Linus Torvalds wrote: > > On Thu, 14 Apr 2005, H. Peter Anvin wrote: > >> Although Linus is correct in that an SCM doesn't *have* to handle >> this, it really feels like shooting for mediocracy to me. We might >> as well design it right from the beginning. > > > No. git is not an SCM. it's a filesystem designed to _host_ an SCM, > and that _is_ doing it right from the beginning. I imagine quite a few folks expect something not entirely unlike an SCM to emerge from these current efforts. Moreover, Petr's 'git' scripts wrap your "filesystem" plumbing to that very end. To avoid confusion, I think it would be better to distinguish the two layers, perhaps by calling the low-level plumbing... 'gitfs', of course. Cheers, Zach Welch Superlucidity Services - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support
Hi all, I'm working on an OO perl alternative to Petr's git scripts, which I'm currently calling "yogi" (your other git interface). While I'm not ready to release that just yet, I wanted to start floating some patches to the core plumbing to support the respective packages' potentially divergent demands. For those die-hard perl hackers, I can float you a copy of the package off-list if you're interested; I'm hoping to finish a public 0.0.1 release by the end of the week. The first two patches in the series are already in the pasky.git repository, but Linus hasn't merged them yet. The are included only because the next few patches expect them to be in place. The third patch in the series prepares for the forth patch by factoring the object directory detection and creation functionality. The fifth patch makes one final pass at cleaning up init-db. The 3rd and 5th patches aren't particularly valuable unless the remaining patches are also applied, but they do make the code a bit prettier. To me, at least. The remaining patches (4,6,7,8) add the ability for the '.git' index directory to be overridden in the same manner as the object directory. This allows me to create my own independent '.yogi' trees, the very notion of which may cause this whole series to be henceforth flamed into oblivion. Here's to hoping otherwise Cheers, Zach Welch Superlucidity Services These patches are based off commit 5b53d3a08d64198d26d4f2323f235790c04aeaab. There are 8 patches in this series: [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support [PATCH 5/8] init-db.c: refactor mkdir logic [PATCH 6/8] read-cache.c: add INDEX_FILE_DIRECTORY support [PATCH 7/8] read-tree.c: add INDEX_FILE_DIRECTORY support [PATCH 8/8] update-cache.c: add INDEX_FILE_DIRECTORY support - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call
init-db calls getenv(DB_ENVIRONMENT) twice. Once should be enough. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support init-db.c |3 +-- 1 files changed, 1 insertion(+), 2 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Signed-Off-By: Tony Luck <[EMAIL PROTECTED]> --- a/init-db.c 2005-04-14 11:01:52.0 -0700 +++ b/init-db.c 2005-04-14 11:01:52.0 -0700 @@ -7,7 +7,7 @@ int main(int argc, char **argv) { - char *sha1_dir = getenv(DB_ENVIRONMENT), *path; + char *sha1_dir, *path; int len, i; if (mkdir(".git", 0755) < 0) { - - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects
This makes init-db work for common object database. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call init-db.c |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Signed-Off-By: Aaron Straus <[EMAIL PROTECTED]> Author: Aaron Straus <[EMAIL PROTECTED]> init-db.c: aa00fbb1b95624f6c30090a17354c9c08a6ac596 --- a/init-db.c +++ b/init-db.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) sha1_dir = getenv(DB_ENVIRONMENT); if (sha1_dir) { struct stat st; - if (!stat(sha1_dir, &st) < 0 && S_ISDIR(st.st_mode)) + if (!stat(sha1_dir, &st) && S_ISDIR(st.st_mode)) return 0; fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir); } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/8] init-db.c: refactor directory creation
This patch factors the init-db directory creation into a new function, which is then reused in the next patch. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects init-db.c | 61 --- 1 files changed, 34 insertions(+), 27 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> --- a/init-db.c +++ b/init-db.c @@ -4,43 +4,50 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +/* + * If you want to, you can share the DB area with any number of branches. + * That has advantages: you can save space by sharing all the SHA1 objects. + * On the other hand, it might just make lookup slower and messier. You + * be the judge. The default case is to have a DB per managed directory. + */ + +static char* init_dir(char *env, char *std, char *label, int *len) +{ + char *dir; + dir = getenv(env); + if (dir) { + struct stat st; + if (stat(dir, &st) < 0 || !S_ISDIR(st.st_mode)) { + fprintf(stderr, "%s set to bad directory %s: ", env, dir); + exit(1); + } + } + else { + dir = std; + fprintf(stderr, "defaulting to private %s area\n", label); + } + if (mkdir(dir, 0755) < 0) { + if (errno != EEXIST) { + perror(dir); + exit(1); + } + } + if (len) + *len = strlen(dir); + return dir; +} int main(int argc, char **argv) { char *sha1_dir, *path; int len, i; if (mkdir(".git", 0755) < 0) { perror("unable to create .git directory"); exit(1); } - - /* -* If you want to, you can share the DB area with any number of branches. -* That has advantages: you can save space by sharing all the SHA1 objects. -* On the other hand, it might just make lookup slower and messier. You -* be the judge. -*/ - sha1_dir = getenv(DB_ENVIRONMENT); - if (sha1_dir) { - struct stat st; - if (!stat(sha1_dir, &st) && S_ISDIR(st.st_mode)) - return 0; - fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir); - } - - /* -* The default case is to have a DB per managed directory. -*/ - sha1_dir = DEFAULT_DB_ENVIRONMENT; - fprintf(stderr, "defaulting to private storage area\n"); - len = strlen(sha1_dir); - if (mkdir(sha1_dir, 0755) < 0) { - if (errno != EEXIST) { - perror(sha1_dir); - exit(1); - } - } + sha1_dir = init_dir(DB_ENVIRONMENT, DEFAULT_DB_ENVIRONMENT, "storage", &len); + path = malloc(len + 40); memcpy(path, sha1_dir, len); for (i = 0; i < 256; i++) { - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support
This patch give init-db the ability for the index directory to be overridden by the INDEX_FILE_DIRECTORY environment variable. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation cache.h |3 +++ init-db.c |5 + 2 files changed, 4 insertions(+), 4 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> --- a/cache.h 2005-04-18 21:13:36.0 -0700 +++ b/cache.h 2005-04-18 21:13:44.0 -0700 @@ -81,6 +81,9 @@ struct cache_entry **active_cache; unsigned int active_nr, active_alloc; +#define INDEX_ENVIRONMENT "INDEX_FILE_DIRECTORY" +#define DEFAULT_INDEX_ENVIRONMENT ".git" + #define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY" #define DEFAULT_DB_ENVIRONMENT ".git/objects" --- a/init-db.c 2005-04-18 21:21:02.0 -0700 +++ b/init-db.c 2005-04-18 21:15:14.0 -0700 @@ -42,10 +42,7 @@ char *sha1_dir, *path; int len, i; - if (mkdir(".git", 0755) < 0) { - perror("unable to create .git directory"); - exit(1); - } + (void) init_dir(INDEX_ENVIRONMENT, DEFAULT_INDEX_ENVIRONMENT, "index", NULL); sha1_dir = init_dir(DB_ENVIRONMENT, DEFAULT_DB_ENVIRONMENT, "storage", &len); path = malloc(len + 40); - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/8] init-db.c: refactor mkdir logic
Move redundant mkdir call logic into helper function. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support init-db.c | 24 1 files changed, 12 insertions(+), 12 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> --- a/init-db.c 2005-04-19 01:36:58.0 -0700 +++ b/init-db.c 2005-04-19 01:37:03.0 -0700 @@ -11,6 +11,16 @@ * be the judge. The default case is to have a DB per managed directory. */ +static void create_dir(char *path) +{ + if (mkdir(dir, 0755) < 0) { + if (errno != EEXIST) { + perror(dir); + exit(1); + } + } +} + static char* init_dir(char *env, char *std, char *label, int *len) { char *dir; @@ -26,12 +36,7 @@ dir = std; fprintf(stderr, "defaulting to private %s area\n", label); } - if (mkdir(dir, 0755) < 0) { - if (errno != EEXIST) { - perror(dir); - exit(1); - } - } + create_dir(dir); if (len) *len = strlen(dir); return dir; @@ -49,12 +54,7 @@ memcpy(path, sha1_dir, len); for (i = 0; i < 256; i++) { sprintf(path+len, "/%02x", i); - if (mkdir(path, 0755) < 0) { - if (errno != EEXIST) { - perror(path); - exit(1); - } - } + create_dir(path); } return 0; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 7/8] read-tree.c: add INDEX_FILE_DIRECTORY support
This patch give read-tree the ability for the index directory to be overridden by the INDEX_FILE_DIRECTORY environment variable. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support [PATCH 5/8] init-db.c: refactor mkdir logic [PATCH 6/8] read-cache.c: add INDEX_FILE_DIRECTORY support read-tree.c | 33 + 1 files changed, 25 insertions(+), 8 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> read-tree.c: 42556c82def1d23f21116a2c1b3e7ae27c0605c5 --- 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 same(struct cache_entry *a, struct cache_entry *b) @@ -154,14 +154,27 @@ static void trivially_merge_cache(struct int main(int argc, char **argv) { - int i, newfd; + int i, newfd, len; unsigned char sha1[20]; + char *index_file, *index_path; - newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600); + index_path = getenv(INDEX_ENVIRONMENT); + if (!index_path) + index_path = DEFAULT_INDEX_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; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -182,8 +195,12 @@ int main(int argc, char **argv) if (stage == 4) trivially_merge_cache(active_cache, active_nr); 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; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 8/8] update-cache.c: add INDEX_FILE_DIRECTORY support
This patch give update-cache the ability for the index directory to be overridden by the INDEX_FILE_DIRECTORY environment variable. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support [PATCH 5/8] init-db.c: refactor mkdir logic [PATCH 6/8] read-cache.c: add INDEX_FILE_DIRECTORY support [PATCH 7/8] read-tree.c: add INDEX_FILE_DIRECTORY support update-cache.c | 33 - 1 files changed, 24 insertions(+), 9 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> 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(INDEX_ENVIRONMENT); + if (!index_path) + index_path = DEFAULT_INDEX_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; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 6/8] read-cache.c: add INDEX_FILE_DIRECTORY support
This patch give read-cache the ability for the index directory to be overridden by the INDEX_FILE_DIRECTORY environment variable. This patch applies on top of: [PATCH 0/8] init-db.c cleanup, add INDEX_FILE_DIRECTORY support [PATCH 1/8] init-db.c: [RESEND] remove redundant getenv call [PATCH 2/8] init-db.c: [RESEND] make init-db work with common objects [PATCH 3/8] init-db.c: refactor directory creation [PATCH 4/8] init-db.c: add INDEX_FILE_DIRECTORY support [PATCH 5/8] init-db.c: refactor mkdir logic read-cache.c | 15 +-- 1 files changed, 13 insertions(+), 2 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> 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(INDEX_ENVIRONMENT); + if (!index_path) + index_path = DEFAULT_INDEX_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"); - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] init-db.c: fix stupid typo
Fix a stupid typo from the last mkdir refactorng patch. init-db.c |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> --- a/init-db.c 2005-04-19 13:06:11.0 -0700 +++ a/init-db.c 2005-04-19 13:06:16.0 -0700 @@ -11,7 +11,7 @@ * be the judge. The default case is to have a DB per managed directory. */ -static void create_dir(char *path) +static void create_dir(char *dir) { if (mkdir(dir, 0755) < 0) { if (errno != EEXIST) { There are 0 patches in this series: - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/3] init-db.c cleanup and fixes
Linus, I see you pulled the first two patches of my last series into your tree, so I know I had your attention briefly. I wanted to see what I can do to help the rest of the changes get in, so I realized last night as I was going to bed that the third patch might not be accepted because it changes the behaviour slightly, nevermind that they were - by comparison with today's alternative - plain ugly. For what it's worth, init-db is practically useless for my package without the second change in this series. Currently, I've implemented init-db in pure perl, but I'd like to use init-db. As such, I started from scratch, and came up with a much simpler series of patches. Please continue to ignore the previous series, but consider these new patches in their stead. New GIT_FILE_DIRECTORY patches will follow seperately. Cheers, Zach Welch Superlucidity Services These patches were based off commit 4e1778c8ceeaea340a2a7f62fc65736da327ec05. There are 3 patches in this series: [PATCH 1/3] init-db.c: cleanup comments [PATCH 2/3] init-db.c: normalize env var handling. [PATCH 3/3] init-db.c: create and use safe_create_dir helper - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/3] init-db.c: cleanup comments
init-db.c | 15 ++- 1 files changed, 6 insertions(+), 9 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Consolidate comments at top of main. --- a/init-db.c +++ b/init-db.c @@ -5,6 +5,12 @@ */ #include "cache.h" +/* + * If you want to, you can share the DB area with any number of branches. + * That has advantages: you can save space by sharing all the SHA1 objects. + * On the other hand, it might just make lookup slower and messier. You + * be the judge. The default case is to have one DB per managed directory. + */ int main(int argc, char **argv) { char *sha1_dir, *path; @@ -15,12 +21,6 @@ int main(int argc, char **argv) exit(1); } - /* -* If you want to, you can share the DB area with any number of branches. -* That has advantages: you can save space by sharing all the SHA1 objects. -* On the other hand, it might just make lookup slower and messier. You -* be the judge. -*/ sha1_dir = getenv(DB_ENVIRONMENT); if (sha1_dir) { struct stat st; @@ -29,9 +29,6 @@ int main(int argc, char **argv) fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir); } - /* -* The default case is to have a DB per managed directory. -*/ sha1_dir = DEFAULT_DB_ENVIRONMENT; fprintf(stderr, "defaulting to private storage area\n"); len = strlen(sha1_dir); - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/3] init-db.c: normalize env var handling.
This patch applies on top of: [PATCH 1/3] init-db.c: cleanup comments init-db.c | 11 +++ 1 files changed, 3 insertions(+), 8 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Normalize init-db environment variable handling, allowing the creation of object directories with something other than DEFAULT_DB_ENVIRONMENT. --- a/init-db.c +++ b/init-db.c @@ -22,15 +22,10 @@ int main(int argc, char **argv) } sha1_dir = getenv(DB_ENVIRONMENT); - if (sha1_dir) { - struct stat st; - if (!stat(sha1_dir, &st) && S_ISDIR(st.st_mode)) - return 0; - fprintf(stderr, "DB_ENVIRONMENT set to bad directory %s: ", sha1_dir); + if (!sha1_dir) { + sha1_dir = DEFAULT_DB_ENVIRONMENT; + fprintf(stderr, "defaulting to local storage area\n"); } - - sha1_dir = DEFAULT_DB_ENVIRONMENT; - fprintf(stderr, "defaulting to private storage area\n"); len = strlen(sha1_dir); if (mkdir(sha1_dir, 0755) < 0) { if (errno != EEXIST) { - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/3] init-db.c: create and use safe_create_dir helper
This patch applies on top of: [PATCH 1/3] init-db.c: cleanup comments [PATCH 2/3] init-db.c: normalize env var handling. init-db.c | 30 ++ 1 files changed, 14 insertions(+), 16 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Factor mkdir calls into common safe_create_dir subroutine. --- a/init-db.c 2005-04-19 18:50:14.0 -0700 +++ b/init-db.c 2005-04-19 18:45:48.0 -0700 @@ -5,6 +5,16 @@ */ #include "cache.h" +void safe_create_dir(char *dir) +{ + if (mkdir(dir, 0755) < 0) { + if (errno != EEXIST) { + perror(dir); + exit(1); + } + } +} + /* * If you want to, you can share the DB area with any number of branches. * That has advantages: you can save space by sharing all the SHA1 objects. @@ -16,10 +26,7 @@ char *sha1_dir, *path; int len, i; - if (mkdir(".git", 0755) < 0) { - perror("unable to create .git directory"); - exit(1); - } + safe_create_dir(".git"); sha1_dir = getenv(DB_ENVIRONMENT); if (!sha1_dir) { @@ -27,22 +34,13 @@ fprintf(stderr, "defaulting to local storage area\n"); } len = strlen(sha1_dir); - if (mkdir(sha1_dir, 0755) < 0) { - if (errno != EEXIST) { - perror(sha1_dir); - exit(1); - } - } path = malloc(len + 40); memcpy(path, sha1_dir, len); + + safe_create_dir(sha1_dir); for (i = 0; i < 256; i++) { sprintf(path+len, "/%02x", i); - if (mkdir(path, 0755) < 0) { - if (errno != EEXIST) { - perror(path); - exit(1); - } - } + safe_create_dir(path); } return 0; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/3] introduce GIT_CACHE_DIRECTORY to plumbing
The first 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. The second patch renames the DB_ENVIRONMENT symbols to match. Note, the name changes came from an off-list comment from Linus, after my sendpatches script accidentally bombed him with a half dozen copies of the init-db patch series summary. His comment inspired these last two. The third patch renames SHA1_FILE_DIRECTORY as GIT_OBJECT_DIRECTORY, to match the "GIT_CACHE_DIRECTORY" name introduced in the first patch. This was done last and seperately so it can be applied after a little bit of notice. We're not at a point of need to be backwards compatible. This require my latest init-db cleanups be applied first, otherwise you will get a rejection in init-db.c. There are 3 patches in this series: [PATCH 1/3] add GIT_CACHE_DIRECTORY support [PATCH 2/3] rename object directory symbols [PATCH 3/3] rename SHA1_FILE_DIRECTORY - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/3] add GIT_CACHE_DIRECTORY support
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 <[EMAIL PROTECTED]> 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))
[PATCH 2/3] rename object directory symbols
This patch applies on top of: [PATCH 1/3] add GIT_CACHE_DIRECTORY support cache.h |4 ++-- fsck-cache.c |2 +- init-db.c|4 ++-- ls-tree.c|4 ++-- read-cache.c |4 ++-- sha1_file.c |2 +- 6 files changed, 10 insertions(+), 10 deletions(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Rename the DB_ENVIRONMENT symbols to match the newly introduced GIT_CACHE_ENVIROMENT symbols. cache.h: 1fca894f485471d51c6a72c16e02df6d56d0052f --- a/cache.h +++ b/cache.h @@ -84,8 +84,8 @@ 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" +#define GIT_OBJECT_ENVIRONMENT "SHA1_FILE_DIRECTORY" +#define DEFAULT_GIT_OBJECT_ENVIRONMENT ".git/objects" #define alloc_nr(x) (((x)+16)*3/2) fsck-cache.c: cf39b7e054d9685fde7004ec767cd098b97e8ce7 --- a/fsck-cache.c +++ b/fsck-cache.c @@ -135,7 +135,7 @@ int main(int argc, char **argv) int i, heads; char *sha1_dir; - sha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT; + sha1_dir = getenv(GIT_OBJECT_ENVIRONMENT) ? : DEFAULT_GIT_OBJECT_ENVIRONMENT; for (i = 0; i < 256; i++) { static char dir[4096]; sprintf(dir, "%s/%02x", sha1_dir, i); init-db.c: 9e693a0a914512c5574f394222cfc75496e3453a --- a/init-db.c +++ b/init-db.c @@ -33,9 +33,9 @@ int main(int argc, char **argv) } safe_create_dir(git_dir); - sha1_dir = getenv(DB_ENVIRONMENT); + sha1_dir = getenv(GIT_OBJECT_ENVIRONMENT); if (!sha1_dir) { - sha1_dir = DEFAULT_DB_ENVIRONMENT; + sha1_dir = DEFAULT_GIT_OBJECT_ENVIRONMENT; fprintf(stderr, "defaulting to local storage area\n"); } len = strlen(sha1_dir); ls-tree.c: 936bb19a5525046a5a784d5f14c3ea7da406cc62 --- a/ls-tree.c +++ b/ls-tree.c @@ -105,9 +105,9 @@ int main(int argc, char **argv) usage(ls_tree_usage); if (get_sha1_hex(argv[1], sha1) < 0) usage(ls_tree_usage); - sha1_file_directory = getenv(DB_ENVIRONMENT); + sha1_file_directory = getenv(GIT_OBJECT_ENVIRONMENT); if (!sha1_file_directory) - sha1_file_directory = DEFAULT_DB_ENVIRONMENT; + sha1_file_directory = DEFAULT_GIT_OBJECT_ENVIRONMENT; if (list(sha1) < 0) die("list failed"); return 0; read-cache.c: 9eee23097b9406548765ec6fc77e61788317df19 --- a/read-cache.c +++ b/read-cache.c @@ -186,9 +186,9 @@ int read_cache(void) return error("more than one cachefile"); errno = ENOENT; - sha1_file_directory = getenv(DB_ENVIRONMENT); + sha1_file_directory = getenv(GIT_OBJECT_ENVIRONMENT); if (!sha1_file_directory) - sha1_file_directory = DEFAULT_DB_ENVIRONMENT; + sha1_file_directory = DEFAULT_GIT_OBJECT_ENVIRONMENT; if (access(sha1_file_directory, X_OK) < 0) return error("no access to SHA1 file directory"); sha1_file.c: c4591cd2168ae2e42c1fc9878be8befbfa1a8afa --- a/sha1_file.c +++ b/sha1_file.c @@ -61,7 +61,7 @@ char *sha1_file_name(const unsigned char static char *name, *base; if (!base) { - char *sha1_file_directory = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT; + char *sha1_file_directory = getenv(GIT_OBJECT_ENVIRONMENT) ? : DEFAULT_GIT_OBJECT_ENVIRONMENT; int len = strlen(sha1_file_directory); base = malloc(len + 60); memcpy(base, sha1_file_directory, len); - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/3] rename SHA1_FILE_DIRECTORY
This patch applies on top of: [PATCH 1/3] add GIT_CACHE_DIRECTORY support [PATCH 2/3] rename object directory symbols cache.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Signed-Off-By: Zach Welch <[EMAIL PROTECTED]> Rename SHA1_FILE_DIRECTORY to GIT_OBJECT_DIRECTORY. Scripts that used to pass this setting will need to be updated. cache.h: 218bec12fab3fb57ad03fafccedd4398c64c3646 --- a/cache.h +++ b/cache.h @@ -84,7 +84,7 @@ unsigned int active_nr, active_alloc; #define GIT_CACHE_ENVIRONMENT "GIT_CACHE_DIRECTORY" #define DEFAULT_GIT_CACHE_ENVIRONMENT ".git" -#define GIT_OBJECT_ENVIRONMENT "SHA1_FILE_DIRECTORY" +#define GIT_OBJECT_ENVIRONMENT "GIT_OBJECT_DIRECTORY" #define DEFAULT_GIT_OBJECT_ENVIRONMENT ".git/objects" #define alloc_nr(x) (((x)+16)*3/2) - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] init-db.c: normalize env var handling.
Linus Torvalds wrote: > For future reference, this is in the wrong order. I feel even more abashed for my earlier scripting faux pas. Would you like me to resend them to you off-list? Cheers, Zach - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "GIT_INDEX_FILE" environment variable
Howdy, Linus Torvalds wrote: > On Thu, 21 Apr 2005, Junio C Hamano wrote: >>I am thinking about an alternative way of doing the above by >>some modifications to the git core. I think the root of this >>problem is that there is no equivalent to GIT_INDEX_FILE and >>SHA1_FILE_DIRECTORY that tells the core git where the project >>top directory (i.e. the root of the working tree that >>corresponds to what $GIT_INDEX_FILE describes) is. > > I'd _really_ prefer to just try to teach people to work from the "top" > directory instead. Would it be okay if that were settable on a per-repository basis? :) Or do you have specific subset of operations you want restricted? >> - A new environment variable GIT_WORKING_TREE points at the >> root of the working tree. [snip] > I really don't like it that much, but to some degree it obviously is > exactly what "--prefix=" does to checkout-cache. It's basically saying > that all normal file operations have to be prefixed with a magic string. I'm going to script it one way or the other, but the environment route allows me to set things up after a fork and before exec in Perl. This works regardless of what git command I'm running, and should work even with ithreads. This ease of use would not be the case with the '--prefix' solution, as scripting the commands would requiring passing arguments to those commands that need/support them at a higher level than is desirable. At present, I have implemented Yogi to support being able to run commands from a different working directory than the root of the repository, and that behavior might be per-repository settable (someday). If I had my way, I would like to see git support the following variables: GIT_WORKING_DIRECTORY - default to '.' GIT_CACHE_DIRECTORTY- default to ${GIT_WORKING_DIRECTORY}/.git GIT_OBJECT_DIRECTORY- defaults to ${GIT_CACHE_DIRECTORY}/objects The reasoning is simple: One object repository can be shared among numerous working caches, which can be shared among multiple working directories (e.g. any directories under the project root, but maybe also import/exports, or other magic...). There are two layers of one to many relationships between the three classes of directories, and my scripts want to make use of that flexibility to the hilt. Also, do you really think git will only ever have the index file, and not someday possibly other related bits? (You may have said that elsewhere, but I missed it.) If that's ever the case, the directory variable is the way to go; scripts can be forward compatible and won't risk accidentally mingling repository data when their scripts have only set GIT_INDEX_FILE and not GIT_SOME_OTHER_FILE. That said, I think GIT_INDEX_FILE would supplement the above scheme nicely, overriding a default of ${GIT_CACHE_DIRECTORY}/index, because of use cases you've described. Cheers, Zach - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html