From c5ced64578a82b9d172aceb2f67c6fb9e639f6d9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 22 Dec 2005 22:57:20 -0800 Subject: check_packed_git_idx(): check integrity of the idx file itself. Although pack-check.c had routine to verify the checksum for the pack index file itself, the core did not check it before using it. This is stolen from the patch to tighten packname requirements. Signed-off-by: Junio C Hamano (cherry picked from 797bd6f490c91c07986382b9f268e0df712cb246 commit) --- sha1_file.c | 16 +++++++++++++++- t/t5300-pack-object.sh | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sha1_file.c b/sha1_file.c index d451a94efe..6b7577dbc4 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -321,12 +321,16 @@ struct packed_git *packed_git; static int check_packed_git_idx(const char *path, unsigned long *idx_size_, void **idx_map_) { + SHA_CTX ctx; + unsigned char sha1[20]; void *idx_map; unsigned int *index; unsigned long idx_size; int nr, i; - int fd = open(path, O_RDONLY); + int fd; struct stat st; + + fd = open(path, O_RDONLY); if (fd < 0) return -1; if (fstat(fd, &st)) { @@ -364,6 +368,16 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_, if (idx_size != 4*256 + nr * 24 + 20 + 20) return error("wrong index file size"); + /* + * File checksum. + */ + SHA1_Init(&ctx); + SHA1_Update(&ctx, idx_map, idx_size-20); + SHA1_Final(sha1, &ctx); + + if (memcmp(sha1, idx_map + idx_size - 20, 20)) + return error("index checksum mismatch"); + return 0; } diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 5b50536b54..7dfb1ab77b 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -163,6 +163,13 @@ test_expect_success \ else :; fi && + cp test-1-${packname_1}.pack test-3.pack && + dd if=/dev/zero of=test-3.idx count=1 bs=1 conv=notrunc seek=1200 && + if git-verify-pack test-3.pack + then false + else :; + fi && + :' test_expect_success \ -- cgit v1.2.3 From bb5ebed731378f9ebec9bcd438aa69e086d73359 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Dec 2005 12:47:18 -0800 Subject: show-branch: usability updates. This does three things: . It simplifies the logic to handle the case in which no refs are given on the command line, and fixes the bug when only "--heads" is specified. Earlier we showed them twice. . It avoids to add the same ref twice. . It sorts the glob result (e.g. "git show-branch 'tags/v1.0*'") according to a more version friendly sort order. Signed-off-by: Junio C Hamano --- show-branch.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/show-branch.c b/show-branch.c index 3fe62b7177..15b1968781 100644 --- a/show-branch.c +++ b/show-branch.c @@ -284,10 +284,54 @@ static void show_one_commit(struct commit *commit, int no_name) static char *ref_name[MAX_REVS + 1]; static int ref_name_cnt; +static const char *find_digit_prefix(const char *s, int *v) +{ + const char *p; + int ver; + char ch; + + for (p = s, ver = 0; + '0' <= (ch = *p) && ch <= '9'; + p++) + ver = ver * 10 + ch - '0'; + *v = ver; + return p; +} + + +static int version_cmp(const char *a, const char *b) +{ + while (1) { + int va, vb; + + a = find_digit_prefix(a, &va); + b = find_digit_prefix(b, &vb); + if (va != vb) + return va - vb; + + while (1) { + int ca = *a; + int cb = *b; + if ('0' <= ca && ca <= '9') + ca = 0; + if ('0' <= cb && cb <= '9') + cb = 0; + if (ca != cb) + return ca - cb; + if (!ca) + break; + a++; + b++; + } + if (!*a && !*b) + return 0; + } +} + static int compare_ref_name(const void *a_, const void *b_) { const char * const*a = a_, * const*b = b_; - return strcmp(*a, *b); + return version_cmp(*a, *b); } static void sort_ref_range(int bottom, int top) @@ -299,8 +343,15 @@ static void sort_ref_range(int bottom, int top) static int append_ref(const char *refname, const unsigned char *sha1) { struct commit *commit = lookup_commit_reference_gently(sha1, 1); + int i; + if (!commit) return 0; + /* Avoid adding the same thing twice */ + for (i = 0; i < ref_name_cnt; i++) + if (!strcmp(refname, ref_name[i])) + return 0; + if (MAX_REVS <= ref_name_cnt) { fprintf(stderr, "warning: ignoring %s; " "cannot handle more than %d refs\n", @@ -512,19 +563,17 @@ int main(int ac, char **av) if (1 < independent + merge_base + (extra != 0)) usage(show_branch_usage); + /* If nothing is specified, show all branches by default */ + if (ac + all_heads + all_tags == 0) + all_heads = 1; + if (all_heads + all_tags) snarf_refs(all_heads, all_tags); - - if (ac) { - while (0 < ac) { - append_one_rev(*av); - ac--; av++; - } - } - else { - /* If no revs given, then add heads */ - snarf_refs(1, 0); + while (0 < ac) { + append_one_rev(*av); + ac--; av++; } + if (!ref_name_cnt) { fprintf(stderr, "No revs to be shown.\n"); exit(0); -- cgit v1.2.3 From 695bf722da848e0cd2692bc07c4a2773c52b4216 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Dec 2005 15:48:09 -0800 Subject: merge --no-commit: tweak message We did not distinguish the case the user asked not to make a commit with --no-commit flag and the automerge failed. Tell these cases apart and phrase dying message differently. Signed-off-by: Junio C Hamano --- git-merge.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/git-merge.sh b/git-merge.sh index e50fbb1160..0a158ef779 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -209,6 +209,7 @@ case "$use_strategies" in esac result_tree= best_cnt=-1 best_strategy= wt_strategy= +merge_was_ok= for strategy in $use_strategies do test "$wt_strategy" = '' || { @@ -228,6 +229,7 @@ do exit=$? if test "$no_commit" = t && test "$exit" = 0 then + merge_was_ok=t exit=1 ;# pretend it left conflicts. fi @@ -293,4 +295,11 @@ do done >"$GIT_DIR/MERGE_HEAD" echo $merge_msg >"$GIT_DIR/MERGE_MSG" -die "Automatic merge failed/prevented; fix up by hand" +if test "$merge_was_ok" = t +then + echo >&2 \ + "Automatic merge went well; stopped before committing as requested" + exit 0 +else + die "Automatic merge failed; fix up by hand" +fi -- cgit v1.2.3 From 9a84074d08e2e816a3310eb34ac69b584faf817b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Dec 2005 15:51:33 -0800 Subject: ls-files --full-name: usage string and documentation. Somehow this option was not mentioned anywhere in the documentation nor the usage string. Signed-off-by: Junio C Hamano --- Documentation/git-ls-files.txt | 9 ++++++++- ls-files.c | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 2f308ecda9..186f3bb57a 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -13,7 +13,8 @@ SYNOPSIS (-[c|d|o|i|s|u|k|m])\* [-x |--exclude=] [-X |--exclude-from=] - [--exclude-per-directory=] [--] []\* + [--exclude-per-directory=] + [--full-name] [--] []\* DESCRIPTION ----------- @@ -77,6 +78,12 @@ OPTIONS K:: to be killed ? other +--full-name:: + When run from a subdirectory, the command usually + outputs paths relative to the current directory. This + option forces paths to be output relative to the project + top directory. + --:: Do not interpret any more arguments as options. diff --git a/ls-files.c b/ls-files.c index f3f1a6a663..5e9ac712af 100644 --- a/ls-files.c +++ b/ls-files.c @@ -562,7 +562,7 @@ static void verify_pathspec(void) static const char ls_files_usage[] = "git-ls-files [-z] [-t] (--[cached|deleted|others|stage|unmerged|killed|modified])* " "[ --ignored ] [--exclude=] [--exclude-from=] " - "[ --exclude-per-directory= ] [--] []*"; + "[ --exclude-per-directory= ] [--full-name] [--] []*"; int main(int argc, const char **argv) { -- cgit v1.2.3 From ac44f3e7c05390531004d567481004c96d1b262c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 Dec 2005 23:56:52 -0800 Subject: mailinfo: iconv does not like "latin-1" -- should spell it "latin1" This was a stupid typo that did not follow http://www.iana.org/assignments/character-sets Long noticed but neglected by JC, but finally reported by Marco. Signed-off-by: Junio C Hamano --- mailinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailinfo.c b/mailinfo.c index 9f95f37651..0265a29a38 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -472,7 +472,7 @@ static void convert_to_utf8(char *line, char *charset) char *in, *out; size_t insize, outsize, nrc; char outbuf[4096]; /* cheat */ - static char latin_one[] = "latin-1"; + static char latin_one[] = "latin1"; char *input_charset = *charset ? charset : latin_one; iconv_t conv = iconv_open(metainfo_charset, input_charset); -- cgit v1.2.3