Skip to content

Commit

Permalink
Make git-rev-list and git-rev-parse argument parsing stricter
Browse files Browse the repository at this point in the history
If you pass it a filename without the "--" marker to separate it from
revision information and flags, we now require that the file in question
actually exists. This makes mis-typed revision information not be silently
just considered a strange filename.

With the "--" marker, you can continue to pass in filenames that do not
actually exists - useful for querying what happened to a file that you
no longer have in the repository.

[ All scripts should use the "--" format regardless, to make things
  unambiguous. So this change should not affect any existing tools ]

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jan 25, 2006
1 parent 92643a2 commit d8f6b34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,12 @@ int main(int argc, const char **argv)
arg++;
limited = 1;
}
if (get_sha1(arg, sha1) < 0)
if (get_sha1(arg, sha1) < 0) {
struct stat st;
if (lstat(arg, &st) < 0)
die("'%s': %s", arg, strerror(errno));
break;
}
commit = get_commit_reference(arg, sha1, flags);
handle_one_commit(commit, &list);
}
Expand Down
3 changes: 3 additions & 0 deletions rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ int main(int argc, char **argv)
const char *prefix = setup_git_directory();

for (i = 1; i < argc; i++) {
struct stat st;
char *arg = argv[i];
char *dotdot;

Expand Down Expand Up @@ -293,6 +294,8 @@ int main(int argc, char **argv)
}
if (verify)
die("Needed a single revision");
if (lstat(arg, &st) < 0)
die("'%s': %s", arg, strerror(errno));
as_is = 1;
show_file(arg);
}
Expand Down

0 comments on commit d8f6b34

Please sign in to comment.