From b909a15edef8c79b2b045bd90d25e19ea58f299c Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 20 Aug 2005 18:02:16 +0200 Subject: [PATCH 1/4] [PATCH] Fix git-commit-script to output on stderr when -v fails When git-commit-script is called with -v option and verify test fails result is print on stdout instead of stderr. [jc: The original patch from Marco updated git-commit-script that still had the piece of code in question, which has been moved to an example hook script on its own, so I transplanted the patch to that new file instead.] Signed-off-by: Marco Costalba Signed-off-by: Junio C Hamano --- templates/hooks--pre-commit | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit index dad99bcf10..075eb3c1f4 100644 --- a/templates/hooks--pre-commit +++ b/templates/hooks--pre-commit @@ -19,17 +19,17 @@ perl -e ' sub bad_line { my ($why, $line) = @_; if (!$found_bad) { - print "*\n"; - print "* You have some suspicious patch lines:\n"; - print "*\n"; + print STDERR "*\n"; + print STDERR "* You have some suspicious patch lines:\n"; + print STDERR "*\n"; $found_bad = 1; } if ($reported_filename ne $filename) { - print "* In $filename\n"; + print STDERR "* In $filename\n"; $reported_filename = $filename; } - print "* $why (line $lineno)\n"; - print "$filename:$lineno:$line\n"; + print STDERR "* $why (line $lineno)\n"; + print STDERR "$filename:$lineno:$line\n"; } open $fh, "-|", qw(git-diff-cache -p -M --cached HEAD); while (<$fh>) { From d57306c7945becfba70d3139af0a3a8f525a6bb5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 20 Aug 2005 02:05:31 -0700 Subject: [PATCH 2/4] Create objects/info/ directory in init-db. Signed-off-by: Junio C Hamano --- init-db.c | 2 ++ t/t0000-basic.sh | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/init-db.c b/init-db.c index 1fb3f7fa79..50b16b34b0 100644 --- a/init-db.c +++ b/init-db.c @@ -249,5 +249,7 @@ int main(int argc, char **argv) } strcpy(path+len, "/pack"); safe_create_dir(path); + strcpy(path+len, "/info"); + safe_create_dir(path); return 0; } diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 547488bd25..142b7bf388 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -28,11 +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 257 subdirectories. 258 is counting "objects" +# also it should have 258 subdirectories; 256 fan-out, pack, and info. +# 259 is counting "objects" itself find .git/objects -type d -print >full-of-directories test_expect_success \ - '.git/objects should have 257 subdirectories.' \ - 'test $(wc -l < full-of-directories) = 258' + '.git/objects should have 258 subdirectories.' \ + 'test $(wc -l < full-of-directories) = 259' ################################################################ # Basics of the basics From 90a734dc7f37a7bd1f3beec4d33acad559360f6c Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Sun, 21 Aug 2005 16:14:16 +0900 Subject: [PATCH 3/4] [PATCH] possible memory leak in diff.c::diff_free_filepair() Here is a patch to fix the problem in the simplest way. --- diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diff.c b/diff.c index bb2a43b5b0..137d0d0c0c 100644 --- a/diff.c +++ b/diff.c @@ -1010,9 +1010,8 @@ void diff_flush(int diff_output_style, int line_termination) diff_flush_name(p, line_termination); break; } - } - for (i = 0; i < q->nr; i++) diff_free_filepair(q->queue[i]); + } free(q->queue); q->queue = NULL; q->nr = q->alloc = 0; From 1dfcfbce2d643b7c7b56dc828f36ced9de2bf9f2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 21 Aug 2005 02:43:08 -0700 Subject: [PATCH 4/4] [PATCH] sha1_name: do not accept .git/refs/snap/. I think Linus did a cut & paste from an early JIT code while developing the current extended SHA1 notation, and left it there as a courtesy, but the directory does not deserve to be treated any more specially than, say, .git/refs/bisect. If the subdirectories under .git/refs proliferate, we may want to switch to scanning that hierarchy at runtime, instead of the current hard-coded set, although I think that would be overkill. Signed-off-by: Junio C Hamano From nobody Mon Sep 17 00:00:00 2001 Subject: [PATCH] Add a new extended SHA1 syntax : From: Junio C Hamano Date: 1124617434 -0700 The new notation is a short-hand for followed by caret ('^') characters. E.g. "master:4" is the fourth generation ancestor of the current "master" branch head, following the first parents; same as "master^^^^" but a bit more readable. This will be used in the updated "git show-branch" command. Signed-off-by: Junio C Hamano --- sha1_name.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) d5098ce769da46df6d45dc8f41b06dd758fdaea7 diff --git a/sha1_name.c b/sha1_name.c --- a/sha1_name.c +++ b/sha1_name.c @@ -191,9 +191,29 @@ static int get_parent(const char *name, return -1; } +static int get_nth_ancestor(const char *name, int len, + unsigned char *result, int generation) +{ + unsigned char sha1[20]; + int ret = get_sha1_1(name, len, sha1); + if (ret) + return ret; + + while (generation--) { + struct commit *commit = lookup_commit_reference(sha1); + + if (!commit || parse_commit(commit) || !commit->parents) + return -1; + memcpy(sha1, commit->parents->item->object.sha1, 20); + } + memcpy(result, sha1, 20); + return 0; +} + static int get_sha1_1(const char *name, int len, unsigned char *sha1) { int parent, ret; + const char *cp; /* foo^[0-9] or foo^ (== foo^1); we do not do more than 9 parents. */ if (len > 2 && name[len-2] == '^' && @@ -210,6 +230,27 @@ static int get_sha1_1(const char *name, if (parent >= 0) return get_parent(name, len, sha1, parent); + /* name:3 is name^^^, + * name:12 is name^^^^^^^^^^^^, and + * name: is name + */ + parent = 0; + for (cp = name + len - 1; name <= cp; cp--) { + int ch = *cp; + if ('0' <= ch && ch <= '9') + continue; + if (ch != ':') + parent = -1; + break; + } + if (!parent && *cp == ':') { + int len1 = cp - name; + cp++; + while (cp < name + len) + parent = parent * 10 + *cp++ - '0'; + return get_nth_ancestor(name, len1, sha1, parent); + } + ret = get_sha1_basic(name, len, sha1); if (!ret) return 0; --- sha1_name.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sha1_name.c b/sha1_name.c index fdd321448c..6744bbbef5 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -143,7 +143,6 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) "refs", "refs/tags", "refs/heads", - "refs/snap", NULL }; const char **p;