From e24317b4d093e4b148996172d0b749f09a0e6f2e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Oct 2005 01:43:03 +0200 Subject: Test in git-init-db if the filemode can be trusted ... and if not, write an appropriate .git/config. Of course, that happens only if no config file was yet created (by a template or a hook). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- init-db.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'init-db.c') diff --git a/init-db.c b/init-db.c index aabc09f4e1..2a4aa3c196 100644 --- a/init-db.c +++ b/init-db.c @@ -196,6 +196,43 @@ static void create_default_files(const char *git_dir, } path[len] = 0; copy_templates(path, len, template_path); + + /* + * Find out if we can trust the executable bit. + */ + safe_create_dir(path); + strcpy(path + len, "config"); + if (access(path, R_OK) < 0) { + static const char contents[] = + "#\n" + "# This is the config file\n" + "#\n" + "\n" + "; core variables\n" + "[core]\n" + " ; Don't trust file modes\n" + " filemode = false\n" + "\n"; + FILE *config = fopen(path, "w"); + struct stat st; + + if (!config) + die("Can not write to %s?", path); + + fwrite(contents, sizeof(contents)-1, 1, config); + + fclose(config); + + if (!lstat(path, &st)) { + struct stat st2; + if (!chmod(path, st.st_mode ^ S_IXUSR) && + !lstat(path, &st2) && + st.st_mode != st2.st_mode) + unlink(path); + else + fprintf(stderr, "Ignoring file modes\n"); + } + } } static const char init_db_usage[] = -- cgit v1.3-5-g9baa From 9106c097ad87577019544f45fda11c4d73986597 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 9 Oct 2005 02:30:17 -0700 Subject: Create object subdirectories on demand (phase II) This removes the unoptimization. The previous round does not mind missing fan-out directories, but still makes sure they exist, lest older versions choke on a repository created/packed by it. This round does not play that nicely anymore -- empty fan-out directories are not created by init-db, and will stay removed by prune-packed. The prune command also removes empty fan-out directories. Signed-off-by: Junio C Hamano --- git-prune.sh | 1 + init-db.c | 4 ---- prune-packed.c | 3 +-- t/t0000-basic.sh | 8 ++++---- 4 files changed, 6 insertions(+), 10 deletions(-) (limited to 'init-db.c') diff --git a/git-prune.sh b/git-prune.sh index 9657dbf271..b28630cacf 100755 --- a/git-prune.sh +++ b/git-prune.sh @@ -22,6 +22,7 @@ sed -ne '/unreachable /{ }' | { cd "$GIT_OBJECT_DIRECTORY" || exit xargs $echo rm -f + rmdir 2>/dev/null [0-9a-f][0-9a-f] } git-prune-packed $dryrun diff --git a/init-db.c b/init-db.c index 2a4aa3c196..ca6fa4d420 100644 --- a/init-db.c +++ b/init-db.c @@ -281,10 +281,6 @@ int main(int argc, char **argv) memcpy(path, sha1_dir, len); safe_create_dir(sha1_dir); - for (i = 0; i < 256; i++) { - sprintf(path+len, "/%02x", i); - safe_create_dir(path); - } strcpy(path+len, "/pack"); safe_create_dir(path); strcpy(path+len, "/info"); diff --git a/prune-packed.c b/prune-packed.c index 1e0fc0cd9e..16685d1d8b 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -27,8 +27,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len) error("unable to unlink %s", pathname); } pathname[len] = 0; - if (!rmdir(pathname)) - mkdir(pathname, 0777); + rmdir(pathname); } static void prune_packed_objects(void) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 5c5f854858..dff7d69163 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -28,12 +28,12 @@ test_expect_success \ '.git/objects should be empty after git-init-db in an empty repo.' \ 'cmp -s /dev/null should-be-empty' -# also it should have 258 subdirectories; 256 fan-out anymore, pack, and info. -# 259 is counting "objects" itself +# also it should have 2 subdirectories; no fan-out anymore, pack, and info. +# 3 is counting "objects" itself find .git/objects -type d -print >full-of-directories test_expect_success \ - '.git/objects should have 258 subdirectories.' \ - 'test $(wc -l < full-of-directories) = 259' + '.git/objects should have 3 subdirectories.' \ + 'test $(wc -l < full-of-directories) = 3' ################################################################ # Basics of the basics -- cgit v1.3-5-g9baa