From d2dadfe890b5da6f65fe061a414b6ec67c5efe9c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 15 Dec 2008 00:36:56 -0800 Subject: [PATCH 1/3] git-show: do not segfault when showing a bad tag When a tag points at a bad or nonexistent object, we should diagnose the breakage and exit. An earlier commit 4f3dcc2 (Fix 'git show' on signed tag of signed tag of commit, 2008-07-01) lost this check and made it segfault instead; not good. This fixes it. Signed-off-by: Junio C Hamano --- builtin-log.c | 8 +++++++- t/t7007-show.sh | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 t/t7007-show.sh diff --git a/builtin-log.c b/builtin-log.c index 2efe593734..db71e0da74 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -356,7 +356,13 @@ int cmd_show(int argc, const char **argv, const char *prefix) t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); ret = show_object(o->sha1, 1, &rev); - objects[i].item = parse_object(t->tagged->sha1); + if (ret) + break; + o = parse_object(t->tagged->sha1); + if (!o) + ret = error("Could not read object %s", + sha1_to_hex(t->tagged->sha1)); + objects[i].item = o; i--; break; } diff --git a/t/t7007-show.sh b/t/t7007-show.sh new file mode 100755 index 0000000000..cce222f052 --- /dev/null +++ b/t/t7007-show.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='git show' + +. ./test-lib.sh + +test_expect_success setup ' + echo hello world >foo && + H=$(git hash-object -w foo) && + git tag -a foo-tag -m "Tags $H" $H && + HH=$(expr "$H" : "\(..\)") && + H38=$(expr "$H" : "..\(.*\)") && + rm -f .git/objects/$HH/$H38 +' + +test_expect_success 'showing a tag that point at a missing object' ' + test_must_fail git --no-pager show foo-tag +' + +test_done From a8335024c294db470e16e9df3aaa346bfcfbeacb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 15 Dec 2008 00:33:34 -0800 Subject: [PATCH 2/3] pager: do not dup2 stderr if it is already redirected An earlier commit 61b8050 (sending errors to stdout under $PAGER, 2008-02-16) avoided losing the error messages that are sent to the standard error when $PAGER is in effect by dup2'ing fd 2 to the pager. his way, showing a tag object that points to a bad object: $ git show tag-foo would give the error message to the pager. However, it was not quite right if the user did: $ git show 2>error.log tag-foo i.e. use the pager but store the errors in a separate file. Signed-off-by: Junio C Hamano --- pager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pager.c b/pager.c index 6b5c9e44b4..0b7e55f476 100644 --- a/pager.c +++ b/pager.c @@ -102,7 +102,8 @@ void setup_pager(void) /* original process continues, but writes to the pipe */ dup2(pager_process.in, 1); - dup2(pager_process.in, 2); + if (isatty(2)) + dup2(pager_process.in, 2); close(pager_process.in); /* this makes sure that the parent terminates after the pager */ From 87c8a56e4f71cc7e22c16caa4adc2ae17f6aa93d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 15 Dec 2008 22:11:40 +0100 Subject: [PATCH 3/3] fast-import: close pack before unlinking it This is sort of a companion patch to 4723ee9(Close files opened by lock_file() before unlinking.): on Windows, you cannot delete what is still open. This makes test 9300-fast-import pass on Windows for me; quite a few fast-imports leave temporary packs until the test "blank lines not necessary after other commands" actually tests for the number of files in .git/objects/pack/, which has a few temporary packs now. I guess that 8b4eb6b(Do not perform cross-directory renames when creating packs) was "responsible" for the breakage. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- fast-import.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fast-import.c b/fast-import.c index 5473cd4d62..13b36147a4 100644 --- a/fast-import.c +++ b/fast-import.c @@ -982,8 +982,10 @@ static void end_packfile(void) pack_id++; } - else + else { + close(old_p->pack_fd); unlink(old_p->pack_name); + } free(old_p); /* We can't carry a delta across packfiles. */