* [PATCH] diff: handle "-" as abbreviation of '@{-1}'
@ 2016-03-12 2:11 Senorsen
2016-03-12 2:48 ` Javier Domingo Cansino
0 siblings, 1 reply; 3+ messages in thread
From: Senorsen @ 2016-03-12 2:11 UTC (permalink / raw)
To: git; +Cc: Senorsen
Currently it just replace "-" in argv[] into "@{-1}".
For example,
git diff -
equals to
git diff @{-1}
Signed-off-by: Senorsen <senorsen.zhang@gmail.com>
---
Notes:
Hello everyone, I'm Zhang Sen, a college student from Zhejiang University
in China, and this is a patch for the microproject of GSoC 2016. I'm
looking forward to contributing to Git and participating in GSoC 2016.
I have learnt some rules and guides from the documents, and carefully
wrote this small patch, according to other code from git.
Thanks a lot!
builtin/diff.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/builtin/diff.c b/builtin/diff.c
index 52c98a9..c110141 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
}
}
+ for (i = 0; i < argc; i++) {
+ if (!strcmp(argv[i], "-"))
+ argv[i] = "@{-1}";
+ }
+
for (i = 0; i < rev.pending.nr; i++) {
struct object_array_entry *entry = &rev.pending.objects[i];
struct object *obj = entry->item;
--
2.7.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] diff: handle "-" as abbreviation of '@{-1}'
2016-03-12 2:11 [PATCH] diff: handle "-" as abbreviation of '@{-1}' Senorsen
@ 2016-03-12 2:48 ` Javier Domingo Cansino
2016-03-14 9:17 ` Michael J Gruber
0 siblings, 1 reply; 3+ messages in thread
From: Javier Domingo Cansino @ 2016-03-12 2:48 UTC (permalink / raw)
To: Senorsen; +Cc: git@vger.kernel.org
dash is usually used for representing stdin / stdout as a file. I
think this could drive to error... but I would agree with transforming
-h1 to @{-1} or -h2 to @{-2} (-h representing head).
I do agree however that all those signs are thought with american
keyboards in mind. All those punctuation marks are usually hard to
type in other keyboards, and -h1 is way simpler than HEAD~ or @{-1}
This links provides an example of my worry:
http://stackoverflow.com/questions/15270970/is-it-possible-to-git-diff-a-file-against-standard-input
On Sat, Mar 12, 2016 at 2:11 AM, Senorsen <senorsen.zhang@gmail.com> wrote:
>
> Currently it just replace "-" in argv[] into "@{-1}".
>
> For example,
>
> git diff -
>
> equals to
>
> git diff @{-1}
>
> Signed-off-by: Senorsen <senorsen.zhang@gmail.com>
> ---
> Notes:
> Hello everyone, I'm Zhang Sen, a college student from Zhejiang University
> in China, and this is a patch for the microproject of GSoC 2016. I'm
> looking forward to contributing to Git and participating in GSoC 2016.
>
> I have learnt some rules and guides from the documents, and carefully
> wrote this small patch, according to other code from git.
>
> Thanks a lot!
>
> builtin/diff.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/builtin/diff.c b/builtin/diff.c
> index 52c98a9..c110141 100644
> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
> }
> }
>
> + for (i = 0; i < argc; i++) {
> + if (!strcmp(argv[i], "-"))
> + argv[i] = "@{-1}";
> + }
> +
> for (i = 0; i < rev.pending.nr; i++) {
> struct object_array_entry *entry = &rev.pending.objects[i];
> struct object *obj = entry->item;
> --
> 2.7.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Javier Domingo Cansino
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] diff: handle "-" as abbreviation of '@{-1}'
2016-03-12 2:48 ` Javier Domingo Cansino
@ 2016-03-14 9:17 ` Michael J Gruber
0 siblings, 0 replies; 3+ messages in thread
From: Michael J Gruber @ 2016-03-14 9:17 UTC (permalink / raw)
To: Javier Domingo Cansino, Senorsen; +Cc: git@vger.kernel.org
Please bottom post - see below.
Javier Domingo Cansino venit, vidit, dixit 12.03.2016 03:48:
> dash is usually used for representing stdin / stdout as a file. I
> think this could drive to error... but I would agree with transforming
> -h1 to @{-1} or -h2 to @{-2} (-h representing head).
>
> I do agree however that all those signs are thought with american
> keyboards in mind. All those punctuation marks are usually hard to
> type in other keyboards, and -h1 is way simpler than HEAD~ or @{-1}
>
> This links provides an example of my worry:
> http://stackoverflow.com/questions/15270970/is-it-possible-to-git-diff-a-file-against-standard-input
>
> On Sat, Mar 12, 2016 at 2:11 AM, Senorsen <senorsen.zhang@gmail.com> wrote:
>>
>> Currently it just replace "-" in argv[] into "@{-1}".
>>
>> For example,
>>
>> git diff -
>>
>> equals to
>>
>> git diff @{-1}
>>
>> Signed-off-by: Senorsen <senorsen.zhang@gmail.com>
>> ---
>> Notes:
>> Hello everyone, I'm Zhang Sen, a college student from Zhejiang University
>> in China, and this is a patch for the microproject of GSoC 2016. I'm
>> looking forward to contributing to Git and participating in GSoC 2016.
>>
>> I have learnt some rules and guides from the documents, and carefully
>> wrote this small patch, according to other code from git.
>>
>> Thanks a lot!
>>
>> builtin/diff.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/builtin/diff.c b/builtin/diff.c
>> index 52c98a9..c110141 100644
>> --- a/builtin/diff.c
>> +++ b/builtin/diff.c
>> @@ -389,6 +389,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
>> }
>> }
>>
>> + for (i = 0; i < argc; i++) {
>> + if (!strcmp(argv[i], "-"))
>> + argv[i] = "@{-1}";
>> + }
>> +
>> for (i = 0; i < rev.pending.nr; i++) {
>> struct object_array_entry *entry = &rev.pending.objects[i];
>> struct object *obj = entry->item;
>> --
>> 2.7.0
>>
Please bottom post on this list. Thanks.
In git land, "checkout", "merge" and "revert" know "-" as an
abbreviation for "@{-1}" already. No git command knows "-" as an
abbreviation for "stdin".
The analogy here is "cd -": switch to the previous directory.
So, a user can expect git to switch to the previously checked out branch
with "git checkout -".
The use of "-" in "merge" and "revert" stress that analogy quite a bit
already, and "diff" goes even further - I'm not a big fan of this. I
feel we should think about the meaning of "-":
"-" = "@{-1}": Then why not implement it at the revision machinery level
(rather than per command)? Otherwise, we raise expectations that we
don't meet.
OR:
"-" = "previous <thing>", with <thing> depending on the command context:
Then <thing> may be the content of HEAD or a commit or what not, and,
correspondingly, "-" should resolve to "@{-1}" (i.e. "HEAD@{1}") or
"HEAD^" or what not.
"git diff" is already a chameleon, diffing files, commits, blobs, index,
automatically choosing the second side in the diff if you specify only
one (or give options), and the questions which "-" blends in naturally
may very well depend on the actual color of the chameleon :)
Michael
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-14 9:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-12 2:11 [PATCH] diff: handle "-" as abbreviation of '@{-1}' Senorsen
2016-03-12 2:48 ` Javier Domingo Cansino
2016-03-14 9:17 ` Michael J Gruber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).