On Sun, Mar 8, 2015 at 1:04 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: Sundararajan R <dyoucme@xxxxxxxxx> writes: > diff --git a/builtin/reset.c b/builtin/reset.c > index 4c08ddc..62764d4 100644 > --- a/builtin/reset.c > +++ b/builtin/reset.c > @@ -203,8 +203,16 @@ static void parse_args(struct pathspec *pathspec, > * > * At this point, argv points immediately after [-opts]. > */ > - > + int flag=0; /* > + * "-" may refer to filename in which case we should be giving more precedence > + * to filename than equating argv[0] to "@{-1}" > + */ Comment on a separate line. More importantly, think if you can give the variable a more meaningful name so that you do not have to explain. You are missing SPs requested by the coding guideline everywhere in your patch. > if (argv[0]) { > + if (!strcmp(argv[0], "-") && !argv[1]) /* "-" is the only argument */ > + { > + argv[0]="@{-1}"; > + flag=1; > + } > if (!strcmp(argv[0], "--")) { > argv++; /* reset to HEAD, possibly with paths */ > } else if (argv[1] && !strcmp(argv[1], "--")) { > @@ -226,6 +234,8 @@ static void parse_args(struct pathspec *pathspec, Around here not shown by this patch there are a few uses of argv[0], and the most important one is verify_non_filename(prefix, argv[0]); just before the line below (see below). > rev = *argv++; > } else { > /* Otherwise we treat this as a filename */ > + if(flag) > + argv[0]="-"; > verify_filename(prefix, argv[0], 1); > } > } By the way, do you understand the intent of the existing checks in this codepath that uses verify_filename() and verify_non_filename()? The idea is to allow users to write "git reset X" and "git reset Y Z" safely in an unambiguous way. * X could be a commit (e.g. "git reset master"), to update the current branch to point at the same commit as 'master' and update the index to match. * X could be a pathspec (e.g. "git reset hello.c"), to grab the blob object for X out of the HEAD and put it in the index. * Y could be a tree-ish and Z a pathspec (e.g. "git reset HEAD^ hello.c"), to grab the blob object for Z out of tree-ish Y and put it to the index. * Both Y and Z could be pathspecs (e.g. "git reset hello.c goodbye.c"), to revert the index entries for these two paths to what the HEAD records. If you happen to have a file whose name is 'master', and if you are working on your 'topic' branch, what would this do? $ git reset master Is this a request to revert the index entry for path 'master' from the HEAD? Or is it a request to update the current branch to be the same as the 'master' branch and repopulate the index from there? What does the existing code try to do, and how does it do it? It detects the ambiguity and refuses to do either, to make sure it causes no harm. Now, with your change, does the result still honor this "when ambiguous, stop without causing harm to the user" principle? What happens when your user has a file whose name is "-" in the working tree? What happens when your user has a file whose name is "@{-1}" in the working tree? -------------------------------------------------------------------------- Hi all, I am sorry for the mistakes in the code formatting. It was because I was in a hurry that day and I wanted to submit a working patch. In the new patch I am making, I am using check_filename() to see if there are files named "-" and "@{-1}" in the working tree . Is this an appropriate way to check or is there something else suggested? Thanks a lot. R Sundararajan. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html