{"thread":{"id":"41675","subject":"[PATCH] diff: handle \"-\" as abbreviation of '@{-1}'","startedAt":"2016-03-12T02:11:50Z","lastAt":"2016-03-14T09:17:31Z","messageCount":3,"participants":["Senorsen","Javier Domingo Cansino","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"280655","messageId":"1457748710-79370-1-git-send-email-senorsen.zhang@gmail.com","threadId":"41675","inReplyTo":null,"subject":"[PATCH] diff: handle \"-\" as abbreviation of '@{-1}'","fromName":"Senorsen","fromEmail":"senorsen.zhang@gmail.com","sentAt":"2016-03-12T02:11:50Z","receivedAt":"2016-03-12T02:11:50Z","isPatch":true,"sender":{"key":"senorsen.zhang@gmail.com","avatar":null},"body":"Currently it just replace \"-\" in argv[] into \"@{-1}\".\n\nFor example,\n\n    git diff -\n\nequals to\n\n    git diff @{-1}\n\nSigned-off-by: Senorsen <senorsen.zhang@gmail.com>\n---\nNotes:\n    Hello everyone, I'm Zhang Sen, a college student from Zhejiang University \n    in China, and this is a patch for the microproject of GSoC 2016. I'm \n    looking forward to contributing to Git and participating in GSoC 2016.\n\n    I have learnt some rules and guides from the documents, and carefully \n    wrote this small patch, according to other code from git.\n\n    Thanks a lot!\n\n builtin/diff.c | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 52c98a9..c110141 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n+\tfor (i = 0; i < argc; i++) {\n+\t\tif (!strcmp(argv[i], \"-\"))\n+\t\t\targv[i] = \"@{-1}\";\n+\t}\n+\n \tfor (i = 0; i < rev.pending.nr; i++) {\n \t\tstruct object_array_entry *entry = &rev.pending.objects[i];\n \t\tstruct object *obj = entry->item;\n-- \n2.7.0\n"},{"id":"280656","messageId":"CALZVapk9seKDpLGbyJ23UVxP97WAHkdXS+U+yrJoKf-2cLamAQ@mail.gmail.com","threadId":"41675","inReplyTo":"1457748710-79370-1-git-send-email-senorsen.zhang@gmail.com","subject":"Re: [PATCH] diff: handle \"-\" as abbreviation of '@{-1}'","fromName":"Javier Domingo Cansino","fromEmail":"javierdo1@gmail.com","sentAt":"2016-03-12T02:48:38Z","receivedAt":"2016-03-12T02:48:38Z","isPatch":true,"sender":{"key":"javierdo1@gmail.com","avatar":"https://gravatar.com/avatar/0f43d4d2e5f4320e8b5e1a46914213c5459dd0de261ab1587f222827f863d727?d=mp&s=160"},"body":"dash is usually used for representing stdin / stdout as a file. I\nthink this could drive to error... but I would agree with transforming\n-h1 to @{-1} or -h2 to @{-2} (-h representing head).\n\nI do agree however that all those signs are thought with american\nkeyboards in mind. All those punctuation marks are usually hard to\ntype in other keyboards, and -h1 is way simpler than HEAD~ or @{-1}\n\nThis links provides an example of my worry:\nhttp://stackoverflow.com/questions/15270970/is-it-possible-to-git-diff-a-file-against-standard-input\n\nOn Sat, Mar 12, 2016 at 2:11 AM, Senorsen <senorsen.zhang@gmail.com> wrote:\n>\n> Currently it just replace \"-\" in argv[] into \"@{-1}\".\n>\n> For example,\n>\n>     git diff -\n>\n> equals to\n>\n>     git diff @{-1}\n>\n> Signed-off-by: Senorsen <senorsen.zhang@gmail.com>\n> ---\n> Notes:\n>     Hello everyone, I'm Zhang Sen, a college student from Zhejiang University\n>     in China, and this is a patch for the microproject of GSoC 2016. I'm\n>     looking forward to contributing to Git and participating in GSoC 2016.\n>\n>     I have learnt some rules and guides from the documents, and carefully\n>     wrote this small patch, according to other code from git.\n>\n>     Thanks a lot!\n>\n>  builtin/diff.c | 5 +++++\n>  1 file changed, 5 insertions(+)\n>\n> diff --git a/builtin/diff.c b/builtin/diff.c\n> index 52c98a9..c110141 100644\n> --- a/builtin/diff.c\n> +++ b/builtin/diff.c\n> @@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n>                 }\n>         }\n>\n> +       for (i = 0; i < argc; i++) {\n> +               if (!strcmp(argv[i], \"-\"))\n> +                       argv[i] = \"@{-1}\";\n> +       }\n> +\n>         for (i = 0; i < rev.pending.nr; i++) {\n>                 struct object_array_entry *entry = &rev.pending.objects[i];\n>                 struct object *obj = entry->item;\n> --\n> 2.7.0\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n\n\n\n-- \nJavier Domingo Cansino\n"},{"id":"280705","messageId":"56E681AB.1000201@drmicha.warpmail.net","threadId":"41675","inReplyTo":"CALZVapk9seKDpLGbyJ23UVxP97WAHkdXS+U+yrJoKf-2cLamAQ@mail.gmail.com","subject":"Re: [PATCH] diff: handle \"-\" as abbreviation of '@{-1}'","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2016-03-14T09:17:31Z","receivedAt":"2016-03-14T09:17:31Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Please bottom post - see below.\n\nJavier Domingo Cansino venit, vidit, dixit 12.03.2016 03:48:\n> dash is usually used for representing stdin / stdout as a file. I\n> think this could drive to error... but I would agree with transforming\n> -h1 to @{-1} or -h2 to @{-2} (-h representing head).\n> \n> I do agree however that all those signs are thought with american\n> keyboards in mind. All those punctuation marks are usually hard to\n> type in other keyboards, and -h1 is way simpler than HEAD~ or @{-1}\n> \n> This links provides an example of my worry:\n> http://stackoverflow.com/questions/15270970/is-it-possible-to-git-diff-a-file-against-standard-input\n> \n> On Sat, Mar 12, 2016 at 2:11 AM, Senorsen <senorsen.zhang@gmail.com> wrote:\n>>\n>> Currently it just replace \"-\" in argv[] into \"@{-1}\".\n>>\n>> For example,\n>>\n>>     git diff -\n>>\n>> equals to\n>>\n>>     git diff @{-1}\n>>\n>> Signed-off-by: Senorsen <senorsen.zhang@gmail.com>\n>> ---\n>> Notes:\n>>     Hello everyone, I'm Zhang Sen, a college student from Zhejiang University\n>>     in China, and this is a patch for the microproject of GSoC 2016. I'm\n>>     looking forward to contributing to Git and participating in GSoC 2016.\n>>\n>>     I have learnt some rules and guides from the documents, and carefully\n>>     wrote this small patch, according to other code from git.\n>>\n>>     Thanks a lot!\n>>\n>>  builtin/diff.c | 5 +++++\n>>  1 file changed, 5 insertions(+)\n>>\n>> diff --git a/builtin/diff.c b/builtin/diff.c\n>> index 52c98a9..c110141 100644\n>> --- a/builtin/diff.c\n>> +++ b/builtin/diff.c\n>> @@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n>>                 }\n>>         }\n>>\n>> +       for (i = 0; i < argc; i++) {\n>> +               if (!strcmp(argv[i], \"-\"))\n>> +                       argv[i] = \"@{-1}\";\n>> +       }\n>> +\n>>         for (i = 0; i < rev.pending.nr; i++) {\n>>                 struct object_array_entry *entry = &rev.pending.objects[i];\n>>                 struct object *obj = entry->item;\n>> --\n>> 2.7.0\n>>\n\nPlease bottom post on this list. Thanks.\n\nIn git land, \"checkout\", \"merge\" and \"revert\" know \"-\" as an\nabbreviation for \"@{-1}\" already. No git command knows \"-\" as an\nabbreviation for \"stdin\".\n\nThe analogy here is \"cd -\": switch to the previous directory.\n\nSo, a user can expect git to switch to the previously checked out branch\nwith \"git checkout -\".\n\nThe use of \"-\" in \"merge\" and \"revert\" stress that analogy quite a bit\nalready, and \"diff\" goes even further - I'm not a big fan of this. I\nfeel we should think about the meaning of \"-\":\n\n\"-\" = \"@{-1}\": Then why not implement it at the revision machinery level\n(rather than per command)? Otherwise, we raise expectations that we\ndon't meet.\n\nOR:\n\n\"-\" = \"previous <thing>\", with <thing> depending on the command context:\nThen <thing> may be the content of HEAD or a commit or what not, and,\ncorrespondingly, \"-\" should resolve to \"@{-1}\" (i.e. \"HEAD@{1}\") or\n\"HEAD^\" or what not.\n\n\"git diff\" is already a chameleon, diffing files, commits, blobs, index,\nautomatically choosing the second side in the diff if you specify only\none (or give options), and the questions which \"-\" blends in naturally\nmay very well depend on the actual color of the chameleon :)\n\nMichael\n"}]}