Re: [PATCH 4/4] Clean up work-tree handling

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Wednesday, August 1, 2007 - 1:59 am

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:


Similarly to this change, I am wondering if we would want to fix
verify_non_filename() in setup.c, which does this:

/*
 * 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)
{
...
}

/*
 * Opposite of the above: the command line did not have -- marker
 * and we parsed the arg as a refname.  It should not be interpretable
 * as a filename.
 */
void verify_non_filename(const char *prefix, const char *arg)
{
        const char *name;
        struct stat st;

        if (!is_inside_work_tree() || is_inside_git_dir())
                return;
        if (*arg == '-')
                return; /* flag */
        name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
        if (!lstat(name, &st))
                die("ambiguous argument '%s': both revision and filename\n"
                    "Use '--' to separate filenames from revisions", arg);
        if (errno != ENOENT)
                die("'%s': %s", arg, strerror(errno));
}

At this point, we are given an ambiguous parameter, that could
be naming a path in the work tree.  If we are not in the work
tree, then it is understandable that we do not have to barf.
The other check (i.e. "|| is_inside_git_dir()") does not hurt
(iow, it is not an incorrect check per-se), because if you did
"cd .git && git log HEAD" then the HEAD parameter cannot be
naming the path ".git/HEAD" in the work tree, but (1) that is
already covered by .git/ being "outside of work tree", and (2)
it is not something this function wants to check anyway
(i.e. "can the parameter be naming a file in the work tree?").

Am I mistaken and/or confused?



-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/9] work-tree clean ups, Johannes Schindelin, (Sun Jul 29, 4:23 pm)
[PATCH 1/9] Add is_absolute_path() and make_absolute_path(), Johannes Schindelin, (Sun Jul 29, 4:24 pm)
[PATCH 2/9] Add functions get_relative_cwd() and is_inside ..., Johannes Schindelin, (Sun Jul 29, 4:24 pm)
[PATCH 3/9] white space fixes in setup.c, Johannes Schindelin, (Sun Jul 29, 4:24 pm)
[PATCH 4/9] Clean up work-tree handling, Johannes Schindelin, (Sun Jul 29, 4:25 pm)
[PATCH 5/9] Add set_git_dir() function, Johannes Schindelin, (Sun Jul 29, 4:25 pm)
[PATCH 6/9] work-trees are allowed inside a git-dir, Johannes Schindelin, (Sun Jul 29, 4:25 pm)
[PATCH 7/9] init: use get_git_work_tree() instead of rolli ..., Johannes Schindelin, (Sun Jul 29, 4:25 pm)
[PATCH 8/9] Fix t1501 for updated work-tree logic, Johannes Schindelin, (Sun Jul 29, 4:26 pm)
[PATCH 9/9] Fix t1500 for sane work-tree behavior, Johannes Schindelin, (Sun Jul 29, 4:26 pm)
[UNWANTED PATCH] Die if core.bare = true and core.worktree ..., Johannes Schindelin, (Sun Jul 29, 4:29 pm)
Re: [PATCH 0/9] work-tree clean ups, Johannes Schindelin, (Tue Jul 31, 5:28 pm)
[PATCH 1/4] Add is_absolute_path() and make_absolute_path(), Johannes Schindelin, (Tue Jul 31, 5:28 pm)
[PATCH 2/4] Add functions get_relative_cwd() and is_inside ..., Johannes Schindelin, (Tue Jul 31, 5:29 pm)
[PATCH 3/4] Add set_git_dir() function, Johannes Schindelin, (Tue Jul 31, 5:29 pm)
[PATCH 4/4] Clean up work-tree handling, Johannes Schindelin, (Tue Jul 31, 5:30 pm)
Re: [PATCH 0/9] work-tree clean ups, Junio C Hamano, (Tue Jul 31, 5:55 pm)
Re: [PATCH 0/9] work-tree clean ups, Johannes Schindelin, (Tue Jul 31, 6:13 pm)
Re: [PATCH 4/4] Clean up work-tree handling, Junio C Hamano, (Tue Jul 31, 10:17 pm)
Re: [PATCH 4/4] Clean up work-tree handling, Junio C Hamano, (Wed Aug 1, 1:59 am)
Re: [PATCH 0/9] work-tree clean ups, Johannes Schindelin, (Wed Aug 1, 3:56 am)
Re: [PATCH 2/4] Add functions get_relative_cwd() and is_in ..., Johannes Schindelin, (Wed Aug 1, 4:38 am)
Re: [PATCH 4/4] Clean up work-tree handling, Johannes Schindelin, (Wed Aug 1, 4:46 am)
Re: [PATCH 4/4] Clean up work-tree handling, Johannes Schindelin, (Wed Aug 1, 4:53 am)
[NOT-SERIOUS PATCH] Make get_relative_cwd() not accept NUL ..., Johannes Schindelin, (Wed Aug 1, 8:26 am)
[PATCH] get_relative_cwd(): clarify why it handles dir == NULL, Johannes Schindelin, (Wed Aug 1, 11:26 am)
Re: [PATCH 4/4] Clean up work-tree handling, Junio C Hamano, (Thu Aug 2, 12:04 am)