From: Junio C Hamano Date: Mon, 26 Jul 2010 04:52:48 +0000 (-0700) Subject: Merge branch 'maint-1.6.6' into maint-1.7.0 X-Git-Tag: v1.7.0.7~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/28bf4ba014c9b41679f41580fa9e1cc294b240d9?ds=inline;hp=-c Merge branch 'maint-1.6.6' into maint-1.7.0 * maint-1.6.6: request-pull.txt: Document -p option Check size of path buffer before writing into it rev-parse: fix --parse-opt --keep-dashdash --stop-at-non-option --- 28bf4ba014c9b41679f41580fa9e1cc294b240d9 diff --combined builtin-rev-parse.c index b76f205e62,ee001250f5..935fdeb45e --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@@ -41,7 -41,6 +41,7 @@@ static int is_rev_argument(const char * "--all", "--bisect", "--dense", + "--branches=", "--branches", "--header", "--max-age=", @@@ -52,11 -51,8 +52,11 @@@ "--objects-edge", "--parents", "--pretty", + "--remotes=", "--remotes", + "--glob=", "--sparse", + "--tags=", "--tags", "--topo-order", "--date-order", @@@ -407,8 -403,8 +407,8 @@@ static int cmd_parseopt(int argc, cons ALLOC_GROW(opts, onb + 1, osz); memset(opts + onb, 0, sizeof(opts[onb])); argc = parse_options(argc, argv, prefix, opts, usage, - keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0 | - stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0); + (keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0) | + (stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0)); strbuf_addf(&parsed, " --"); sq_quote_argv(&parsed, argv, 0); @@@ -455,13 -451,6 +455,13 @@@ int cmd_rev_parse(int argc, const char if (argc > 1 && !strcmp("--sq-quote", argv[1])) return cmd_sq_quote(argc - 2, argv + 2); + if (argc == 2 && !strcmp("--local-env-vars", argv[1])) { + int i; + for (i = 0; local_repo_env[i]; i++) + printf("%s\n", local_repo_env[i]); + return 0; + } + if (argc > 1 && !strcmp("-h", argv[1])) usage(builtin_rev_parse_usage); @@@ -580,43 -569,18 +580,43 @@@ for_each_ref_in("refs/bisect/good", anti_reference, NULL); continue; } + if (!prefixcmp(arg, "--branches=")) { + for_each_glob_ref_in(show_reference, arg + 11, + "refs/heads/", NULL); + continue; + } if (!strcmp(arg, "--branches")) { for_each_branch_ref(show_reference, NULL); continue; } + if (!prefixcmp(arg, "--tags=")) { + for_each_glob_ref_in(show_reference, arg + 7, + "refs/tags/", NULL); + continue; + } if (!strcmp(arg, "--tags")) { for_each_tag_ref(show_reference, NULL); continue; } + if (!prefixcmp(arg, "--glob=")) { + for_each_glob_ref(show_reference, arg + 7, NULL); + continue; + } + if (!prefixcmp(arg, "--remotes=")) { + for_each_glob_ref_in(show_reference, arg + 10, + "refs/remotes/", NULL); + continue; + } if (!strcmp(arg, "--remotes")) { for_each_remote_ref(show_reference, NULL); continue; } + if (!strcmp(arg, "--show-toplevel")) { + const char *work_tree = get_git_work_tree(); + if (work_tree) + puts(work_tree); + continue; + } if (!strcmp(arg, "--show-prefix")) { if (prefix) puts(prefix); diff --combined setup.c index fac34f77a7,2fa7969e82..68605954b4 --- a/setup.c +++ b/setup.c @@@ -77,18 -77,6 +77,18 @@@ int check_filename(const char *prefix, die_errno("failed to stat '%s'", arg); } +static void NORETURN die_verify_filename(const char *prefix, const char *arg) +{ + unsigned char sha1[20]; + unsigned mode; + /* try a detailed diagnostic ... */ + get_sha1_with_mode_1(arg, sha1, &mode, 0, prefix); + /* ... or fall back the most general message. */ + die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" + "Use '--' to separate paths from revisions", arg); + +} + /* * Verify a filename that we got as an argument for a pathspec * entry. Note that a filename that begins with "-" never verifies @@@ -102,7 -90,8 +102,7 @@@ void verify_filename(const char *prefix die("bad flag '%s' used after filename", arg); if (check_filename(prefix, arg)) return; - die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" - "Use '--' to separate paths from revisions", arg); + die_verify_filename(prefix, arg); } /* @@@ -169,6 -158,8 +169,8 @@@ static int is_git_directory(const char char path[PATH_MAX]; size_t len = strlen(suspect); + if (PATH_MAX <= len + strlen("/objects")) + die("Too long path: %.*s", 60, suspect); strcpy(path, suspect); if (getenv(DB_ENVIRONMENT)) { if (access(getenv(DB_ENVIRONMENT), X_OK)) @@@ -206,7 -197,7 +208,7 @@@ int is_inside_work_tree(void } /* - * set_work_tree() is only ever called if you set GIT_DIR explicitely. + * set_work_tree() is only ever called if you set GIT_DIR explicitly. * The old behaviour (which we retain here) is to set the work tree root * to the cwd, unless overridden by the config, the command line, or * GIT_WORK_TREE. @@@ -263,8 -254,6 +265,8 @@@ static int check_repository_format_gent const char *read_gitfile_gently(const char *path) { char *buf; + char *dir; + const char *slash; struct stat st; int fd; size_t len; @@@ -289,23 -278,9 +291,23 @@@ if (len < 9) die("No path in gitfile: %s", path); buf[len] = '\0'; - if (!is_git_directory(buf + 8)) - die("Not a git repository: %s", buf + 8); - path = make_absolute_path(buf + 8); + dir = buf + 8; + + if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) { + size_t pathlen = slash+1 - path; + size_t dirlen = pathlen + len - 8; + dir = xmalloc(dirlen + 1); + strncpy(dir, path, pathlen); + strncpy(dir + pathlen, buf + 8, len - 8); + dir[dirlen] = '\0'; + free(buf); + buf = dir; + } + + if (!is_git_directory(dir)) + die("Not a git repository: %s", dir); + path = make_absolute_path(dir); + free(buf); return path; }