From be65e7d9fbd3ae6fc097cedade2afe39805fcf4e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 7 May 2006 00:02:53 +0200 Subject: Fix users of prefix_path() to free() only when necessary Unfortunately, prefix_path() sometimes returns a newly xmalloc()ed buffer, and in other cases it returns a substring! For example, when calling git update-index ./hello.txt prefix_path() returns "hello.txt", but does not allocate a new buffer. The original code only checked if the result of prefix_path() was different from what was passed in, and thusly trigger a segmentation fault. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano diff --git a/checkout-index.c b/checkout-index.c index 0b9cabc..cc3a745 100644 --- a/checkout-index.c +++ b/checkout-index.c @@ -277,7 +277,7 @@ int main(int argc, char **argv) die("git-checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); checkout_file(p); - if (p != arg) + if (p < arg || p > arg + strlen(arg)) free((char*)p); } @@ -299,7 +299,7 @@ int main(int argc, char **argv) path_name = buf.buf; p = prefix_path(prefix, prefix_length, path_name); checkout_file(p); - if (p != path_name) + if (p < path_name || p > path_name + strlen(path_name)) free((char *)p); if (path_name != buf.buf) free(path_name); diff --git a/update-index.c b/update-index.c index d63f8ac..00cde70 100644 --- a/update-index.c +++ b/update-index.c @@ -382,7 +382,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length) die("Unable to process file %s", path); report("add '%s'", path); free_return: - if (p != path) + if (p < path || p > path + strlen(path)) free((char*)p); } @@ -594,7 +594,7 @@ static int do_unresolve(int ac, const char **av, const char *arg = av[i]; const char *p = prefix_path(prefix, prefix_length, arg); err |= unresolve_one(p); - if (p != arg) + if (p < arg || p > arg + strlen(arg)) free((char*)p); } return err; @@ -750,7 +750,7 @@ int main(int argc, const char **argv) update_one(p, NULL, 0); if (set_executable_bit) chmod_path(set_executable_bit, p); - if (p != path_name) + if (p < path_name || p > path_name + strlen(path_name)) free((char*) p); if (path_name != buf.buf) free(path_name); -- cgit v0.10.2-6-g49f6 From 245f1029d674b95d63b5faea2269f98d28b3adb2 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Sun, 7 May 2006 19:32:53 +0200 Subject: core-tutorial.txt: escape asterisk Signed-off-by: Junio C Hamano diff --git a/Documentation/core-tutorial.txt b/Documentation/core-tutorial.txt index 4211c81..d1360ec 100644 --- a/Documentation/core-tutorial.txt +++ b/Documentation/core-tutorial.txt @@ -971,7 +971,7 @@ $ git show-branch --topo-order master mybranch The first two lines indicate that it is showing the two branches and the first line of the commit log message from their top-of-the-tree commits, you are currently on `master` branch -(notice the asterisk `*` character), and the first column for +(notice the asterisk `\*` character), and the first column for the later output lines is used to show commits contained in the `master` branch, and the second column for the `mybranch` branch. Three commits are shown along with their log messages. -- cgit v0.10.2-6-g49f6 From 5d8ee9ceb8912c83336191d32b8898943b8944b8 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 7 May 2006 17:36:12 -0400 Subject: Release config lock if the regex is invalid Signed-off-by: Pavel Roskin Signed-off-by: Junio C Hamano diff --git a/config.c b/config.c index 87fb220..11d65f8 100644 --- a/config.c +++ b/config.c @@ -514,6 +514,8 @@ int git_config_set_multivar(const char* key, const char* value, fprintf(stderr, "Invalid pattern: %s\n", value_regex); free(store.value_regex); + close(fd); + unlink(lock_file); ret = 6; goto out_free; } -- cgit v0.10.2-6-g49f6 From 6fe31e2e4cdb7ed5333107174e23fbf2e226e370 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 7 May 2006 15:32:51 -0700 Subject: repo-config: document what value_regexp does a bit more clearly. Signed-off-by: Junio C Hamano diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt index 71f96bd..fccecd6 100644 --- a/Documentation/git-repo-config.txt +++ b/Documentation/git-repo-config.txt @@ -22,10 +22,11 @@ You can query/set/replace/unset options with this command. The name is actually the section and the key separated by a dot, and the value will be escaped. -If you want to set/unset an option which can occur on multiple lines, you -should provide a POSIX regex for the value. If you want to handle the lines -*not* matching the regex, just prepend a single exclamation mark in front -(see EXAMPLES). +If you want to set/unset an option which can occur on multiple +lines, a POSIX regexp `value_regex` needs to be given. Only the +existing values that match the regexp are updated or unset. If +you want to handle the lines that do *not* match the regex, just +prepend a single exclamation mark in front (see EXAMPLES). The type specifier can be either '--int' or '--bool', which will make 'git-repo-config' ensure that the variable(s) are of the given type and -- cgit v0.10.2-6-g49f6 From cf9dc65368113caa28f2829e2ada5477fbb031ec Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Sun, 7 May 2006 20:19:09 +0200 Subject: clone: keep --reference even with -l -s Both -l -s and --reference update objects/info/alternates and used to write over each other. Signed-off-by: Martin Waitz Signed-off-by: Junio C Hamano diff --git a/git-clone.sh b/git-clone.sh index 0805168..b785247 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -265,7 +265,7 @@ yes,yes) test -f "$repo/objects/info/alternates" && cat "$repo/objects/info/alternates"; echo "$repo/objects" - } >"$GIT_DIR/objects/info/alternates" + } >>"$GIT_DIR/objects/info/alternates" ;; esac git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh new file mode 100755 index 0000000..916ee15 --- /dev/null +++ b/t/t5700-clone-reference.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# +# Copyright (C) 2006 Martin Waitz +# + +test_description='test clone --reference' +. ./test-lib.sh + +base_dir=`pwd` + +test_expect_success 'preparing first repository' \ +'test_create_repo A && cd A && +echo first > file1 && +git add file1 && +git commit -m initial' + +cd "$base_dir" + +test_expect_success 'preparing second repository' \ +'git clone A B && cd B && +echo second > file2 && +git add file2 && +git commit -m addition && +git repack -a -d && +git prune' + +cd "$base_dir" + +test_expect_success 'cloning with reference' \ +'git clone -l -s --reference B A C' + +cd "$base_dir" + +test_expect_success 'existance of info/alternates' \ +'test `wc -l expected && +git count-objects > current && +diff expected current' + +cd "$base_dir" + +test_expect_success 'updating origin' \ +'cd A && +echo third > file3 && +git add file3 && +git commit -m update && +git repack -a -d && +git prune' + +cd "$base_dir" + +test_expect_success 'pulling changes from origin' \ +'cd C && +git pull origin' + +cd "$base_dir" + +# the 2 local objects are commit and tree from the merge +test_expect_success 'that alternate to origin gets used' \ +'cd C && +echo "2 objects" > expected && +git count-objects | cut -d, -f1 > current && +diff expected current' + +cd "$base_dir" + +test_done -- cgit v0.10.2-6-g49f6 From 178613c737f82489a1e2c387236731541fe19081 Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Sun, 7 May 2006 20:18:53 +0200 Subject: repack: honor -d even when no new pack was created If all objects are reachable via an alternate object store then we still have to remove all obsolete local packs. Signed-off-by: Martin Waitz Signed-off-by: Junio C Hamano diff --git a/git-repack.sh b/git-repack.sh index a5d349f..20774fb 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -46,15 +46,15 @@ name=$(git-rev-list --objects --all $rev_list 2>&1 | exit 1 if [ -z "$name" ]; then echo Nothing new to pack. - exit 0 -fi -echo "Pack pack-$name created." +else + echo "Pack pack-$name created." -mkdir -p "$PACKDIR" || exit + mkdir -p "$PACKDIR" || exit -mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" && -mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" || -exit + mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" && + mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" || + exit +fi if test "$remove_redundant" = t then -- cgit v0.10.2-6-g49f6 From d92f1dc63f0582e7cf8dac54d50a2748119a1ce3 Mon Sep 17 00:00:00 2001 From: Peter Hagervall Date: Sun, 7 May 2006 16:50:47 +0200 Subject: Sparse fix for builtin-diff You gotta love sparse: builtin-diff.c:88:4: error: Just how const do you want this type to be? Signed-off-by: Peter Hagervall Signed-off-by: Junio C Hamano diff --git a/builtin-diff.c b/builtin-diff.c index 636edbf..d3ac581 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -84,8 +84,7 @@ static void stuff_change(struct diff_options *opt, if (opt->reverse_diff) { unsigned tmp; - const - const unsigned char *tmp_u; + const unsigned char *tmp_u; const char *tmp_c; tmp = old_mode; old_mode = new_mode; new_mode = tmp; tmp_u = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_u; -- cgit v0.10.2-6-g49f6 From c2f493a4ae159ef99b20be490ae603cd13bab4eb Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Sun, 7 May 2006 20:19:21 +0200 Subject: Transitively read alternatives When adding an alternate object store then add entries from its info/alternates files, too. Relative entries are only allowed in the current repository. Loops and duplicate alternates through multiple repositories are ignored. Just to be sure that nothing breaks it is not allow to build deep nesting levels using info/alternates. Signed-off-by: Martin Waitz Signed-off-by: Junio C Hamano diff --git a/sha1_file.c b/sha1_file.c index 5464828..b62d0e3 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -217,6 +217,8 @@ char *sha1_pack_index_name(const unsigned char *sha1) struct alternate_object_database *alt_odb_list; static struct alternate_object_database **alt_odb_tail; +static void read_info_alternates(const char * alternates, int depth); + /* * Prepare alternate object database registry. * @@ -232,14 +234,85 @@ static struct alternate_object_database **alt_odb_tail; * SHA1, an extra slash for the first level indirection, and the * terminating NUL. */ -static void link_alt_odb_entries(const char *alt, const char *ep, int sep, - const char *relative_base) +static int link_alt_odb_entry(const char * entry, int len, const char * relative_base, int depth) { - const char *cp, *last; - struct alternate_object_database *ent; + struct stat st; const char *objdir = get_object_directory(); + struct alternate_object_database *ent; + struct alternate_object_database *alt; + /* 43 = 40-byte + 2 '/' + terminating NUL */ + int pfxlen = len; + int entlen = pfxlen + 43; int base_len = -1; + if (*entry != '/' && relative_base) { + /* Relative alt-odb */ + if (base_len < 0) + base_len = strlen(relative_base) + 1; + entlen += base_len; + pfxlen += base_len; + } + ent = xmalloc(sizeof(*ent) + entlen); + + if (*entry != '/' && relative_base) { + memcpy(ent->base, relative_base, base_len - 1); + ent->base[base_len - 1] = '/'; + memcpy(ent->base + base_len, entry, len); + } + else + memcpy(ent->base, entry, pfxlen); + + ent->name = ent->base + pfxlen + 1; + ent->base[pfxlen + 3] = '/'; + ent->base[pfxlen] = ent->base[entlen-1] = 0; + + /* Detect cases where alternate disappeared */ + if (stat(ent->base, &st) || !S_ISDIR(st.st_mode)) { + error("object directory %s does not exist; " + "check .git/objects/info/alternates.", + ent->base); + free(ent); + return -1; + } + + /* Prevent the common mistake of listing the same + * thing twice, or object directory itself. + */ + for (alt = alt_odb_list; alt; alt = alt->next) { + if (!memcmp(ent->base, alt->base, pfxlen)) { + free(ent); + return -1; + } + } + if (!memcmp(ent->base, objdir, pfxlen)) { + free(ent); + return -1; + } + + /* add the alternate entry */ + *alt_odb_tail = ent; + alt_odb_tail = &(ent->next); + ent->next = NULL; + + /* recursively add alternates */ + read_info_alternates(ent->base, depth + 1); + + ent->base[pfxlen] = '/'; + + return 0; +} + +static void link_alt_odb_entries(const char *alt, const char *ep, int sep, + const char *relative_base, int depth) +{ + const char *cp, *last; + + if (depth > 5) { + error("%s: ignoring alternate object stores, nesting too deep.", + relative_base); + return; + } + last = alt; while (last < ep) { cp = last; @@ -249,60 +322,15 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep, last = cp + 1; continue; } - for ( ; cp < ep && *cp != sep; cp++) - ; + while (cp < ep && *cp != sep) + cp++; if (last != cp) { - struct stat st; - struct alternate_object_database *alt; - /* 43 = 40-byte + 2 '/' + terminating NUL */ - int pfxlen = cp - last; - int entlen = pfxlen + 43; - - if (*last != '/' && relative_base) { - /* Relative alt-odb */ - if (base_len < 0) - base_len = strlen(relative_base) + 1; - entlen += base_len; - pfxlen += base_len; - } - ent = xmalloc(sizeof(*ent) + entlen); - - if (*last != '/' && relative_base) { - memcpy(ent->base, relative_base, base_len - 1); - ent->base[base_len - 1] = '/'; - memcpy(ent->base + base_len, - last, cp - last); - } - else - memcpy(ent->base, last, pfxlen); - - ent->name = ent->base + pfxlen + 1; - ent->base[pfxlen + 3] = '/'; - ent->base[pfxlen] = ent->base[entlen-1] = 0; - - /* Detect cases where alternate disappeared */ - if (stat(ent->base, &st) || !S_ISDIR(st.st_mode)) { - error("object directory %s does not exist; " - "check .git/objects/info/alternates.", - ent->base); - goto bad; - } - ent->base[pfxlen] = '/'; - - /* Prevent the common mistake of listing the same - * thing twice, or object directory itself. - */ - for (alt = alt_odb_list; alt; alt = alt->next) - if (!memcmp(ent->base, alt->base, pfxlen)) - goto bad; - if (!memcmp(ent->base, objdir, pfxlen)) { - bad: - free(ent); - } - else { - *alt_odb_tail = ent; - alt_odb_tail = &(ent->next); - ent->next = NULL; + if ((*last != '/') && depth) { + error("%s: ignoring relative alternate object store %s", + relative_base, last); + } else { + link_alt_odb_entry(last, cp - last, + relative_base, depth); } } while (cp < ep && *cp == sep) @@ -311,23 +339,14 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep, } } -void prepare_alt_odb(void) +static void read_info_alternates(const char * relative_base, int depth) { - char path[PATH_MAX]; char *map; - int fd; struct stat st; - char *alt; - - alt = getenv(ALTERNATE_DB_ENVIRONMENT); - if (!alt) alt = ""; - - if (alt_odb_tail) - return; - alt_odb_tail = &alt_odb_list; - link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL); + char path[PATH_MAX]; + int fd; - sprintf(path, "%s/info/alternates", get_object_directory()); + sprintf(path, "%s/info/alternates", relative_base); fd = open(path, O_RDONLY); if (fd < 0) return; @@ -340,11 +359,26 @@ void prepare_alt_odb(void) if (map == MAP_FAILED) return; - link_alt_odb_entries(map, map + st.st_size, '\n', - get_object_directory()); + link_alt_odb_entries(map, map + st.st_size, '\n', relative_base, depth); + munmap(map, st.st_size); } +void prepare_alt_odb(void) +{ + char *alt; + + alt = getenv(ALTERNATE_DB_ENVIRONMENT); + if (!alt) alt = ""; + + if (alt_odb_tail) + return; + alt_odb_tail = &alt_odb_list; + link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL, 0); + + read_info_alternates(get_object_directory(), 0); +} + static char *find_sha1_file(const unsigned char *sha1, struct stat *st) { char *name = sha1_file_name(sha1); -- cgit v0.10.2-6-g49f6 From dd05ea1799656024a45017238bbd4857b5256370 Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Sun, 7 May 2006 20:19:47 +0200 Subject: test case for transitive info/alternates Signed-off-by: Martin Waitz Signed-off-by: Junio C Hamano diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh new file mode 100755 index 0000000..097d037 --- /dev/null +++ b/t/t5710-info-alternate.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# +# Copyright (C) 2006 Martin Waitz +# + +test_description='test transitive info/alternate entries' +. ./test-lib.sh + +# test that a file is not reachable in the current repository +# but that it is after creating a info/alternate entry +reachable_via() { + alternate="$1" + file="$2" + if git cat-file -e "HEAD:$file"; then return 1; fi + echo "$alternate" >> .git/objects/info/alternate + git cat-file -e "HEAD:$file" +} + +test_valid_repo() { + git fsck-objects --full > fsck.log && + test `wc -l < fsck.log` = 0 +} + +base_dir=`pwd` + +test_expect_success 'preparing first repository' \ +'test_create_repo A && cd A && +echo "Hello World" > file1 && +git add file1 && +git commit -m "Initial commit" file1 && +git repack -a -d && +git prune' + +cd "$base_dir" + +test_expect_success 'preparing second repository' \ +'git clone -l -s A B && cd B && +echo "foo bar" > file2 && +git add file2 && +git commit -m "next commit" file2 && +git repack -a -d -l && +git prune' + +cd "$base_dir" + +test_expect_success 'preparing third repository' \ +'git clone -l -s B C && cd C && +echo "Goodbye, cruel world" > file3 && +git add file3 && +git commit -m "one more" file3 && +git repack -a -d -l && +git prune' + +cd "$base_dir" + +test_expect_failure 'creating too deep nesting' \ +'git clone -l -s C D && +git clone -l -s D E && +git clone -l -s E F && +git clone -l -s F G && +test_valid_repo' + +cd "$base_dir" + +test_expect_success 'validity of third repository' \ +'cd C && +test_valid_repo' + +cd "$base_dir" + +test_expect_success 'validity of fourth repository' \ +'cd D && +test_valid_repo' + +cd "$base_dir" + +test_expect_success 'breaking of loops' \ +"echo '$base_dir/B/.git/objects' >> '$base_dir'/A/.git/objects/info/alternates&& +cd C && +test_valid_repo" + +cd "$base_dir" + +test_expect_failure 'that info/alternates is neccessary' \ +'cd C && +rm .git/objects/info/alternates && +test_valid_repo' + +cd "$base_dir" + +test_expect_success 'that relative alternate is possible for current dir' \ +'cd C && +echo "../../../B/.git/objects" > .git/objects/info/alternates && +test_valid_repo' + +cd "$base_dir" + +test_expect_failure 'that relative alternate is only possible for current dir' \ +'cd D && +test_valid_repo' + +cd "$base_dir" + +test_done + -- cgit v0.10.2-6-g49f6 From 0438402271cccc1711c603b0a7ba3134f1ce30f1 Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Sun, 7 May 2006 20:19:33 +0200 Subject: clone: don't clone the info/alternates file Now that the cloned alternates file is parsed, too we don't need to copy it into our new repository, we just reference it. Signed-off-by: Martin Waitz Signed-off-by: Junio C Hamano diff --git a/git-clone.sh b/git-clone.sh index b785247..227245c 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -261,11 +261,7 @@ yes,yes) ;; yes) mkdir -p "$GIT_DIR/objects/info" - { - test -f "$repo/objects/info/alternates" && - cat "$repo/objects/info/alternates"; - echo "$repo/objects" - } >>"$GIT_DIR/objects/info/alternates" + echo "$repo/objects" >> "$GIT_DIR/objects/info/alternates" ;; esac git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" -- cgit v0.10.2-6-g49f6