{"thread":{"id":"1242","subject":"[PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","startedAt":"2005-07-14T21:51:26Z","lastAt":"2005-07-15T05:46:46Z","messageCount":7,"participants":["Matthias Urlichs","Junio C Hamano","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6146","messageId":"20050714215126.GY9915@kiste.smurf.noris.de","threadId":"1242","inReplyTo":null,"subject":"[PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-07-14T21:51:26Z","receivedAt":"2005-07-14T21:51:26Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Junio C Hamano wrote:\n\n> +\t\telse if (!strcmp(arg, \"--name-only-z\"))\n> +\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n\nSpeaking as a user, I would get rather frustrated when I try to do that\nand it doesn't work... so the attached patch allows that usage.\nPlease apply.\n\n---\ndiff --git a/diff-cache.c b/diff-cache.c\n--- a/diff-cache.c\n+++ b/diff-cache.c\n@@ -222,11 +222,17 @@ int main(int argc, const char **argv)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"-z\")) {\n-\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n+\t\t\tif (diff_output_format == DIFF_FORMAT_NAME)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--name-only\")) {\n-\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n+\t\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--name-only-z\")) {\ndiff --git a/diff-files.c b/diff-files.c\n--- a/diff-files.c\n+++ b/diff-files.c\n@@ -55,11 +55,17 @@ int main(int argc, const char **argv)\n \t\t\t; /* no-op */\n \t\telse if (!strcmp(argv[1], \"-s\"))\n \t\t\t; /* no-op */\n-\t\telse if (!strcmp(argv[1], \"-z\"))\n-\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n-\t\telse if (!strcmp(argv[1], \"--name-only\"))\n-\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n-\t\telse if (!strcmp(argv[1], \"--name-only-z\"))\n+\t\telse if (!strcmp(argv[1], \"-z\")) {\n+\t\t\tif (diff_output_format == DIFF_FORMAT_NAME)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n+\t\t} else if (!strcmp(argv[1], \"--name-only\")) {\n+\t\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n+\t\t} else if (!strcmp(argv[1], \"--name-only-z\"))\n \t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n \t\telse if (!strcmp(argv[1], \"-R\"))\n \t\t\tdiff_setup_opt |= DIFF_SETUP_REVERSE;\ndiff --git a/diff-stages.c b/diff-stages.c\n--- a/diff-stages.c\n+++ b/diff-stages.c\n@@ -86,11 +86,17 @@ int main(int ac, const char **av)\n \t\t}\n \t\telse if (!strcmp(arg, \"--find-copies-harder\"))\n \t\t\tfind_copies_harder = 1;\n-\t\telse if (!strcmp(arg, \"-z\"))\n-\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n-\t\telse if (!strcmp(arg, \"--name-only\"))\n-\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n-\t\telse if (!strcmp(arg, \"--name-only-z\"))\n+\t\telse if (!strcmp(arg, \"-z\")) {\n+\t\t\tif (diff_output_format == DIFF_FORMAT_NAME)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n+\t\t} else if (!strcmp(arg, \"--name-only\")) {\n+\t\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n+\t\t} else if (!strcmp(arg, \"--name-only-z\"))\n \t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n \t\telse if (!strcmp(arg, \"-R\"))\n \t\t\tdiff_setup_opt |= DIFF_SETUP_REVERSE;\ndiff --git a/diff-tree.c b/diff-tree.c\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -483,7 +483,10 @@ int main(int argc, const char **argv)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--name-only\")) {\n-\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n+\t\t\tif (diff_output_format == DIFF_FORMAT_MACHINE)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME;\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--name-only-z\")) {\n@@ -491,7 +494,10 @@ int main(int argc, const char **argv)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"-z\")) {\n-\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n+\t\t\tif (diff_output_format == DIFF_FORMAT_NAME)\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_NAME_Z;\n+\t\t\telse\n+\t\t\t\tdiff_output_format = DIFF_FORMAT_MACHINE;\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"-m\")) {\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nWhen The Religious Right Takes Over, We'll All Live In Iran\n"},{"id":"6148","messageId":"7vvf3d6nis.fsf@assigned-by-dhcp.cox.net","threadId":"1242","inReplyTo":"20050714215126.GY9915@kiste.smurf.noris.de","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-14T22:17:15Z","receivedAt":"2005-07-14T22:17:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I've considered it, but what happens if you give -z first and\nthen name-only?\n"},{"id":"6149","messageId":"20050714223622.GZ9915@kiste.smurf.noris.de","threadId":"1242","inReplyTo":"7vvf3d6nis.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-07-14T22:36:23Z","receivedAt":"2005-07-14T22:36:23Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Hi,\n\nJunio C Hamano:\n> I've considered it, but what happens if you give -z first and\n> then name-only?\n> \nExactly the same thing as vice versa.\nOr, even more exactly, my patch *makes* that happen. ;-)\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nIsn't this a beautiful day! Just watch some bastard louse it up.\n"},{"id":"6150","messageId":"7vmzop56fo.fsf@assigned-by-dhcp.cox.net","threadId":"1242","inReplyTo":"20050714223622.GZ9915@kiste.smurf.noris.de","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-14T23:11:39Z","receivedAt":"2005-07-14T23:11:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Urlichs <smurf@smurf.noris.de> writes:\n\n> Exactly the same thing as vice versa.\n> Or, even more exactly, my patch *makes* that happen. ;-)\n\nAh, I was not being careful enough.  Sorry.\n\nThat said, I have been hating that diff options parsing for\nquite a while, and I've been thinking about cleaning it up along\nthe lines I'll outline here, but have not done anything about\nit.  Care to help me out?\n\n - In diff.h introduce these new stuff:\n\n     struct diff_opts {\n     int output_format;\n     int detect_rename;\n     ...\n     };\n     void diff_opts_init(struct diff_opts *);\n     int diff_opts_parse(const char *, struct diff_opts *);\n     int diff_opts_final(struct diff_opts *);\n\n - In diff-* brothers:\n\n   - replace individual diff option variables with a single\n     \"static struct diff_opts diff_opts\";\n\n   - change the argument parsing code to do the following:\n\n     diff_opts_init(&diff_opts);\n     for each arg {\n         /* common options to diff brothers are handled by\n          * diff_opts_parse()\n          */\n         switch (diff_opts_parse(arg, &diff_opts)) {\n         case 1: /* was a diff option and was parsed successfully */\n         \tcontinue;\n         case -1: /* error */\n                usage(diff_*_usage);\n         }\n         if (!strcmp())\n              ... parsing of other options\n     }\n     if (diff_opts_final(&diff_opts))\n         /* defaulting to HUMAN format when nothing specified,\n          * complaining if find-copies-harder is specified but\n          * -C was not, etc. is done in diff_opts_final().\n          *\n          * The complex if() chains that checks if we are in\n          * name or in raw mode and switch output_format around\n          * properly is what I missed in your patch, but I think\n          * you can lose that by recording z-ness of the output\n          * independently from the output format in diff_opts_parse()\n          * and combining diff-raw vs diff-name and z vs non-z\n          * in diff_opts_final().  That would make the code much\n          * simpler.\n          */\n         usage(diff_*_usage);\n\n - In diff.h and diff.c, replace individual option parameters\n   for the following functions to a single pointer to struct\n   diff_opts:\n\n     diff_setup(), diffcore_std(), diffcore_std_no_resolve(), diff_flush().  \n\nWe probably can make diff_scoreopt_parse() function static to\ndiff.c once this is done.\n\nWe may want to rip out the independeant pickaxe, orderfile and\nfilter support for diff-helper while we are at it, making it\ntruly just a \"diff-raw to diff-patch\" converter.\n\nHmm?\n"},{"id":"6151","messageId":"20050714232918.GB9915@kiste.smurf.noris.de","threadId":"1242","inReplyTo":"7vmzop56fo.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-07-14T23:29:19Z","receivedAt":"2005-07-14T23:29:19Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Hi,\n\nJunio C Hamano:\n> That said, I have been hating that diff options parsing for\n> quite a while, and I've been thinking about cleaning it up along\n> the lines I'll outline here, but have not done anything about\n> it.  Care to help me out?\n> \nI saw the problem...\n> \n> Hmm?\n> \nSure -- assuming I find some time to actually do it over the next few days.\n\nThe problem is that this has been a problem lately. :-/\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nIlliterate?  Write today, for free help!\n"},{"id":"6171","messageId":"Pine.LNX.4.58.0507142205580.19183@g5.osdl.org","threadId":"1242","inReplyTo":"7vmzop56fo.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-07-15T05:12:15Z","receivedAt":"2005-07-15T05:12:15Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 14 Jul 2005, Junio C Hamano wrote:\n> \n> That said, I have been hating that diff options parsing for\n> quite a while, and I've been thinking about cleaning it up along\n> the lines I'll outline here, but have not done anything about\n> it.  Care to help me out?\n\nI didn't do what you suggested, but I _did_ split the \"format\" up into \n\"format + line_termination\", which in my opinion cleaned up part of it a \n_lot_.\n\nSo now \"-z\" only sets \"line_termination\" to NUL. \"format\" starts out as \n\"DIFF_FORMAT_RAW\" (which is the old HUMAN/MACHINE format - the difference \nbetween those two are now the line termination) but can be \"PATCH\" and \n\"NAME\".\n\nNow, DIFF_FORMAT_PATCH + -z wouldn't seem to make any sense at all, but\nyou can actually do so, and it actually makes some amount of sense for the \ncase of\n\n\tgit-diff-tree -v -p -z HEAD\n\nwhere the \"-z\" means that the commit _message_ will be terminated by a NUL \ncharacter, while the \"-v\" obviously means that the commit message will be \nprinted at all, and the \"-p\" means that the diff gets printed as a patch.\n\nBut the diff obviously gets printed with newlines (as does any newlines\n_within_ the commit message), not with lines terminated by NUL's.\n\nSo \"--name-only-z\" no longer exists. It's \"-z --name-only\" (in any order,\nquite naturally).\n\n\t\t\tLinus\n"},{"id":"6172","messageId":"7vu0iwy62h.fsf@assigned-by-dhcp.cox.net","threadId":"1242","inReplyTo":"Pine.LNX.4.58.0507142205580.19183@g5.osdl.org","subject":"Re: [PATCH] git-diff-*: Allow \"--name-only -z\" as alias for \"--name-only-z\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-15T05:46:46Z","receivedAt":"2005-07-15T05:46:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> On Thu, 14 Jul 2005, Junio C Hamano wrote:\n>> \n>> That said, I have been hating that diff options parsing for\n>> quite a while, and I've been thinking about cleaning it up along\n>> the lines I'll outline here, but have not done anything about\n>> it.  Care to help me out?\n>\n> I didn't do what you suggested, but I _did_ split the \"format\" up into \n> \"format + line_termination\", which in my opinion cleaned up part of it a \n> _lot_.\n\nAgreed 100%.  Regardless of the further cleanup I suggested,\nwhat you did was something I should have done in the first\nplace.  Thanks for the cleanup.\n"}]}