{"thread":{"id":"38756","subject":"Re: [PATCH] [GSoC Microproject]Adding \"-\" shorthand for \"@{-1}\" in RESET command","startedAt":"2015-03-08T11:09:45Z","lastAt":"2015-03-08T21:59:09Z","messageCount":2,"participants":["Sundararajan R","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"257321","messageId":"loom.20150308T120618-983@post.gmane.org","threadId":"38756","inReplyTo":null,"subject":"Re: [PATCH] [GSoC Microproject]Adding \"-\" shorthand for \"@{-1}\" in RESET command","fromName":"Sundararajan R","fromEmail":"dyoucme@gmail.com","sentAt":"2015-03-08T11:09:45Z","receivedAt":"2015-03-08T11:09:45Z","isPatch":true,"sender":{"key":"dyoucme@gmail.com","avatar":null},"body":"On Sun, Mar 8, 2015 at 1:04 PM Junio C Hamano <gitster@pobox.com> wrote:\nSundararajan R <dyoucme@gmail.com> writes:\n\n> diff --git a/builtin/reset.c b/builtin/reset.c\n> index 4c08ddc..62764d4 100644\n> --- a/builtin/reset.c\n> +++ b/builtin/reset.c\n> @@ -203,8 +203,16 @@ static void parse_args(struct pathspec *pathspec,\n>        *\n>        * At this point, argv points immediately after [-opts].\n>        */\n> -\n> +     int flag=0; /*\n> +                  *  \"-\" may refer to filename in which case we should be \ngiving more precedence\n> +                  *  to filename than equating argv[0] to \"@{-1}\"\n> +                  */\n\nComment on a separate line.  More importantly, think if you can give\nthe variable a more meaningful name so that you do not have to\nexplain.\n\nYou are missing SPs requested by the coding guideline everywhere in\nyour patch.\n\n\n>       if (argv[0]) {\n> +             if (!strcmp(argv[0], \"-\") && !argv[1])  /* \"-\" is the only \nargument */\n> +             {\n> +                     argv[0]=\"@{-1}\";\n> +                     flag=1;\n> +             }\n>               if (!strcmp(argv[0], \"--\")) {\n>                       argv++; /* reset to HEAD, possibly with paths */\n>               } else if (argv[1] && !strcmp(argv[1], \"--\")) {\n> @@ -226,6 +234,8 @@ static void parse_args(struct pathspec *pathspec,\n\nAround here not shown by this patch there are a few uses of argv[0],\nand the most important one is\n\n                        verify_non_filename(prefix, argv[0]);\n\njust before the line below (see below).\n\n>                       rev = *argv++;\n>               } else {\n>                       /* Otherwise we treat this as a filename */\n> +                     if(flag)\n> +                             argv[0]=\"-\";\n>                       verify_filename(prefix, argv[0], 1);\n>               }\n>       }\n\nBy the way, do you understand the intent of the existing checks in\nthis codepath that uses verify_filename() and verify_non_filename()?\n\nThe idea is to allow users to write \"git reset X\" and \"git reset Y\nZ\" safely in an unambiguous way.\n\n * X could be a commit (e.g. \"git reset master\"), to update the\n   current branch to point at the same commit as 'master' and update\n   the index to match.\n\n * X could be a pathspec (e.g. \"git reset hello.c\"), to grab the\n   blob object for X out of the HEAD and put it in the index.\n\n * Y could be a tree-ish and Z a pathspec (e.g. \"git reset HEAD^\n   hello.c\"), to grab the blob object for Z out of tree-ish Y and\n   put it to the index.\n\n * Both Y and Z could be pathspecs (e.g. \"git reset hello.c\n   goodbye.c\"), to revert the index entries for these two paths to\n   what the HEAD records.\n\nIf you happen to have a file whose name is 'master', and if you are\nworking on your 'topic' branch, what would this do?\n\n    $ git reset master\n\nIs this a request to revert the index entry for path 'master' from\nthe HEAD?  Or is it a request to update the current branch to be the\nsame as the 'master' branch and repopulate the index from there?\n\nWhat does the existing code try to do, and how does it do it?  It\ndetects the ambiguity and refuses to do either, to make sure it\ncauses no harm.\n\nNow, with your change, does the result still honor this \"when\nambiguous, stop without causing harm to the user\" principle?  What\nhappens when your user has a file whose name is \"-\" in the working\ntree?  What happens when your user has a file whose name is \"@{-1}\"\nin the working tree?\n\n--------------------------------------------------------------------------\nHi all,\n\nI am sorry for the mistakes in the code formatting. It was because I was in \na hurry that day and I wanted to submit a working patch. In the new patch I \nam making, I am using check_filename() to see if there are files named \"-\" \nand \"@{-1}\" in the working tree . Is this an appropriate way to check or is \nthere something else suggested? \n\nThanks a lot.\nR Sundararajan.\n"},{"id":"257346","messageId":"xmqqpp8j882a.fsf@gitster.dls.corp.google.com","threadId":"38756","inReplyTo":"loom.20150308T120618-983@post.gmane.org","subject":"Re: [PATCH] [GSoC Microproject]Adding \"-\" shorthand for \"@{-1}\" in RESET command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-08T21:59:09Z","receivedAt":"2015-03-08T21:59:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sundararajan R <dyoucme@gmail.com> writes:\n\n> I am sorry for the mistakes in the code formatting. It was because I was in \n> a hurry that day and I wanted to submit a working patch.\n\nNo need to apologize for mistakes.  Mistakes are expected part of\nbeing human and the review process is designed to catch exactly\nthat.\n\nThe development is not a race to see who gets there first.  It is a\ncollaborative process to get to a better place together.  Once you\ngot something \"working\", stop and review your work to see if your\ndefinition of \"working\" is sensible.  Is there a corner case you\nmissed?  Is the code formatted in a similar way as the existing code\naround the area you are touching?  Are there better ways to do what\nyou did?  Take your time to make sure you would be happy with what\nyou are sending out.\n\n> In the new patch I \n> am making, I am using check_filename() to see if there are files named \"-\" \n> and \"@{-1}\" in the working tree . Is this an appropriate way to check or is \n> there something else suggested? \n\nI think you are making it unnecessarily hard.  With your patch, the\ncode would look like this:\n\n \tif (argv[0]) {\n+\t\tif (!strcmp(argv[0], \"-\") && !argv[1])  /* \"-\" is the only argument */\n+\t\t{\n+\t\t\targv[0]=\"@{-1}\";\n+\t\t\tflag=1;\n+\t\t}\n \t\tif (!strcmp(argv[0], \"--\")) {\n \t\t\targv++; /* reset to HEAD, possibly with paths */\n \t\t} else if (argv[1] && !strcmp(argv[1], \"--\")) {\n \t\t\trev = argv[0];\n \t\t\targv += 2;\n \t\t}\n \t\t/*\n \t\t * Otherwise, argv[0] could be either <rev> or <paths> and\n \t\t * has to be unambiguous. If there is a single argument, it\n \t\t * can not be a tree\n \t\t */\n \t\telse if ((!argv[1] && !get_sha1_committish(argv[0], unused)) ||\n \t\t\t (argv[1] && !get_sha1_treeish(argv[0], unused))) {\n \t\t\t/*\n \t\t\t * Ok, argv[0] looks like a commit/tree; it should not\n \t\t\t * be a filename.\n \t\t\t */\n \t\t\tverify_non_filename(prefix, argv[0]);\n \t\t\trev = *argv++;\n \t\t} else {\n \t\t\t/* Otherwise we treat this as a filename */\n+\t\t\tif(flag)\n+\t\t\t\targv[0]=\"-\";\n \t\t\tverify_filename(prefix, argv[0], 1);\n \t\t}\n \t}\n\nI was wondering what you are passing to verify_non_filename() that\nyou did not touch.  It would see \"@{-1}\", try to make sure that the\nworking tree does not have a file with that name, and if there is\nthe end user would be warned about ambiguity.\n\nIf the user typed \"git reset @{-1}\", then that warning is very\nsensible, but when the end user only typed \"git reset -\", is there\nany ambiguity?\n"}]}