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
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 <redacted>
Signed-Off-By: Aaron Straus <redacted>
Author: Aaron Straus [off-list ref]
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){structstatst;-if(!stat(sha1_dir,&st)<0&&S_ISDIR(st.st_mode))+if(!stat(sha1_dir,&st)&&S_ISDIR(st.st_mode))return0;fprintf(stderr,"DB_ENVIRONMENT set to bad directory %s: ",sha1_dir);}
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 <redacted>
--- a/init-db.c+++ b/init-db.c
@@ -4,43 +4,50 @@*Copyright(C)LinusTorvalds,2005*/#include"cache.h"+/*+*Ifyouwantto,youcansharetheDBareawithanynumberofbranches.+*Thathasadvantages:youcansavespacebysharingalltheSHA1objects.+*Ontheotherhand,itmightjustmakelookupslowerandmessier.You+*bethejudge.ThedefaultcaseistohaveaDBpermanageddirectory.+*/++staticchar*init_dir(char*env,char*std,char*label,int*len)+{+char*dir;+dir=getenv(env);+if(dir){+structstatst;+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);+returndir;+}intmain(intargc,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++) {
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 <redacted>
Signed-Off-By: Tony Luck <tony.luck@intel.com>
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 <redacted>
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 <redacted>
update-cache.c: 0d16b36d7d074e9f0a2811a40e16e9823a628ec9
--- a/update-cache.c+++ b/update-cache.c
@@ -270,25 +270,37 @@ static int add_cacheinfo(char *arg1, chareturnadd_cache_entry(ce,allow_add);}-staticintremove_lock=0;+staticchar*index_lock=NULL;staticvoidremove_lock_file(void){-if(remove_lock)-unlink(".git/index.lock");+if(index_lock)+unlink(index_lock);}intmain(intargc,char**argv){-inti,newfd,entries;+inti,newfd,entries,len;intallow_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;+return0;}
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 <redacted>
read-cache.c: edaadf3e1c0714735ca8d80301dd644aa0f9cd2a
--- a/read-cache.c+++ b/read-cache.c
@@ -174,22 +174,33 @@ static int verify_hdr(struct cache_headeintread_cache(void){-intfd,i;+intfd,i,len;structstatst;unsignedlongsize,offset;void*map;structcache_header*hdr;+char*index_path,*index_file;errno=EBUSY;if(active_cache)returnerror("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)returnerror("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");
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 <redacted>
read-tree.c: 42556c82def1d23f21116a2c1b3e7ae27c0605c5
--- a/read-tree.c+++ b/read-tree.c
@@ -65,12 +65,12 @@ static int read_tree(unsigned char *sha1return0;}-staticintremove_lock=0;+staticchar*index_lock=NULL;staticvoidremove_lock_file(void){-if(remove_lock)-unlink(".git/index.lock");+if(index_lock)+unlink(index_lock);}staticintsame(structcache_entry*a,structcache_entry*b)
@@ -154,14 +154,27 @@ static void trivially_merge_cache(structintmain(intargc,char**argv){-inti,newfd;+inti,newfd,len;unsignedcharsha1[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++){constchar*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;+return0;}