@matheusbsbs / matheus-bagliano / commits / d8f6b342ae
Fork 0

Make git-rev-list and git-rev-parse argument parsing stricter

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>

Linus Torvalds committed Jan 25, 2006 at 17:00 UTC d8f6b342ae200b2eb72e2f81afea7fe0d41aec0b
2 files changed +8 -1
rev-list.c
+5 -1
@@ -844,8 +844,12 @@ int main(int argc, const char **argv)
844 arg++;
845 limited = 1;
846 }
847 - if (get_sha1(arg, sha1) < 0)
847 + if (get_sha1(arg, sha1) < 0) {
848 + struct stat st;
849 + if (lstat(arg, &st) < 0)
850 + die("'%s': %s", arg, strerror(errno));
851 break;
852 + }
853 commit = get_commit_reference(arg, sha1, flags);
854 handle_one_commit(commit, &list);
855 }
rev-parse.c
+3
@@ -154,6 +154,7 @@ int main(int argc, char **argv)
154 const char *prefix = setup_git_directory();
155
156 for (i = 1; i < argc; i++) {
157 + struct stat st;
158 char *arg = argv[i];
159 char *dotdot;
160
@@ -293,6 +294,8 @@ int main(int argc, char **argv)
294 }
295 if (verify)
296 die("Needed a single revision");
297 + if (lstat(arg, &st) < 0)
298 + die("'%s': %s", arg, strerror(errno));
299 as_is = 1;
300 show_file(arg);
301 }