From 7d09fbe4ab7f080a8f8f5dcef7e0f3edf5e26019 Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Tue, 18 Apr 2006 08:11:06 -0500 Subject: [PATCH 1/4] socksetup: don't return on set_reuse_addr() error The set_reuse_addr() error case was the only error case in socklist() where we returned rather than continued. Not sure why. Either we must free the socklist, or continue. This patch continues on error. Signed-off-by: Serge E. Hallyn Signed-off-by: Junio C Hamano (cherry picked from 0032d548db56eac9ea09b4ba05843365f6325b85 commit) --- daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon.c b/daemon.c index a1ccda30e2..776749e343 100644 --- a/daemon.c +++ b/daemon.c @@ -535,7 +535,7 @@ static int socksetup(int port, int **socklist_p) if (set_reuse_addr(sockfd)) { close(sockfd); - return 0; /* not fatal */ + continue; } if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) { From b176e6ba5bc37466ffcb6c8c0f38c47ec6e9e73a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Apr 2006 12:07:42 -0700 Subject: [PATCH 2/4] rebase: typofix. Noticed by Sean. Signed-off-by: Junio C Hamano --- git-rebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-rebase.sh b/git-rebase.sh index 86dfe9cb96..f7b2b9401a 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -107,7 +107,7 @@ onto=$(git-rev-parse --verify "${onto_name}^0") || exit # Check if we are already based on $onto, but this should be # done only when upstream and onto are the same. -if test "$upstream" = "onto" +if test "$upstream" = "$onto" then mb=$(git-merge-base "$onto" "$branch") if test "$mb" = "$onto" From e23d0b4a4a55cc07e133905f0e9526b3550dd61b Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 26 Apr 2006 10:15:54 -0700 Subject: [PATCH 3/4] Fix filename verification when in a subdirectory When we are in a subdirectory of a git archive, we need to take the prefix of that subdirectory into accoung when we verify filename arguments. Noted by Matthias Lederhofer This also uses the improved error reporting for all the other git commands that use the revision parsing interfaces, not just git-rev-parse. Also, it makes the error reporting for mixed filenames and argument flags clearer (you cannot put flags after the start of the pathname list). [jc: with fix to a trivial typo noticed by Timo Hirvonen] Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + rev-parse.c | 15 ++------------- revision.c | 8 +++----- setup.c | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/cache.h b/cache.h index 69801b02d5..4d8fabc6d8 100644 --- a/cache.h +++ b/cache.h @@ -134,6 +134,7 @@ extern const char *setup_git_directory_gently(int *); extern const char *setup_git_directory(void); extern const char *prefix_path(const char *prefix, int len, const char *path); extern const char *prefix_filename(const char *prefix, int len, const char *path); +extern void verify_filename(const char *prefix, const char *name); #define alloc_nr(x) (((x)+16)*3/2) diff --git a/rev-parse.c b/rev-parse.c index 7f66ae2db8..62e16af33c 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -160,14 +160,6 @@ static int show_file(const char *arg) return 0; } -static void die_badfile(const char *arg) -{ - if (errno != ENOENT) - die("'%s': %s", arg, strerror(errno)); - die("'%s' is ambiguous - revision name or file/directory name?\n" - "Please put '--' before the list of filenames.", arg); -} - int main(int argc, char **argv) { int i, as_is = 0, verify = 0; @@ -177,14 +169,12 @@ int main(int argc, char **argv) git_config(git_default_config); for (i = 1; i < argc; i++) { - struct stat st; char *arg = argv[i]; char *dotdot; if (as_is) { if (show_file(arg) && as_is < 2) - if (lstat(arg, &st) < 0) - die_badfile(arg); + verify_filename(prefix, arg); continue; } if (!strcmp(arg,"-n")) { @@ -350,8 +340,7 @@ int main(int argc, char **argv) continue; if (verify) die("Needed a single revision"); - if (lstat(arg, &st) < 0) - die_badfile(arg); + verify_filename(prefix, arg); } show_default(); if (verify && revs_count != 1) diff --git a/revision.c b/revision.c index e1f9816bd7..03dd238939 100644 --- a/revision.c +++ b/revision.c @@ -675,17 +675,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch arg++; } if (get_sha1(arg, sha1) < 0) { - struct stat st; int j; if (seen_dashdash || local_flags) die("bad revision '%s'", arg); /* If we didn't have a "--", all filenames must exist */ - for (j = i; j < argc; j++) { - if (lstat(argv[j], &st) < 0) - die("'%s': %s", argv[j], strerror(errno)); - } + for (j = i; j < argc; j++) + verify_filename(revs->prefix, argv[j]); + revs->prune_data = get_pathspec(revs->prefix, argv + i); break; } diff --git a/setup.c b/setup.c index 36ede3d874..cce9bb8069 100644 --- a/setup.c +++ b/setup.c @@ -62,6 +62,29 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) return path; } +/* + * Verify a filename that we got as an argument for a pathspec + * entry. Note that a filename that begins with "-" never verifies + * as true, because even if such a filename were to exist, we want + * it to be preceded by the "--" marker (or we want the user to + * use a format like "./-filename") + */ +void verify_filename(const char *prefix, const char *arg) +{ + const char *name; + struct stat st; + + if (*arg == '-') + die("bad flag '%s' used after filename", arg); + name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg; + if (!lstat(name, &st)) + return; + if (errno == ENOENT) + die("ambiguous argument '%s': unknown revision or filename\n" + "Use '--' to separate filenames from revisions", arg); + die("'%s': %s", arg, strerror(errno)); +} + const char **get_pathspec(const char *prefix, const char **pathspec) { const char *entry = *pathspec; From 5981e09999e90b389a02843671529a0faaf72143 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Apr 2006 16:55:25 -0700 Subject: [PATCH 4/4] commit-tree.c: check_valid() microoptimization. There is no point reading the whole object just to make sure it exists and it is of the expected type. We added sha1_object_info() for such need after this code was written, so use it. Signed-off-by: Junio C Hamano --- commit-tree.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/commit-tree.c b/commit-tree.c index 2d8651894a..2595850970 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -45,14 +45,13 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...) static void check_valid(unsigned char *sha1, const char *expect) { - void *buf; char type[20]; - unsigned long size; - buf = read_sha1_file(sha1, type, &size); - if (!buf || strcmp(type, expect)) - die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect); - free(buf); + if (sha1_object_info(sha1, type, NULL)) + die("%s is not a valid object", sha1_to_hex(sha1)); + if (expect && strcmp(type, expect)) + die("%s is not a valid '%s' object", sha1_to_hex(sha1), + expect); } /*