{"thread":{"id":"43535","subject":"an option to make \"git-diff Z A\" prints Z's diff before A's","startedAt":"2006-10-25T07:15:18Z","lastAt":"2006-10-26T15:16:49Z","messageCount":4,"participants":["Jim Meyering","Linus Torvalds","Karl Hasselström","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"295345","messageId":"871wowzx15.fsf@rho.meyering.net","threadId":"43535","inReplyTo":null,"subject":"an option to make \"git-diff Z A\" prints Z's diff before A's","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2006-10-25T07:15:18Z","receivedAt":"2006-10-25T07:15:18Z","isPatch":false,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Hello,\n\nIn a recent patch set I prepared, I placed the names of the\nmore relevant files at the front of the list given to \"git-diff\".\nSo I was surprised to see diff output in which the blocks of output\nare sorted by file name.  The parts I'd tried to put at the \"top\"\nended up being buried in the latter part of the patch.\n\nHere's a small test case:\n\nmkdir d && cd d && touch x y && git-init-db\ngit-add x y && git-commit -m. x y\necho a > x && echo a > y\ngit-diff y x|grep '^d'\n\nI expected this git-diff output, with \"y's\" diff first:\ndiff --git a/y b/y\ndiff --git a/x b/x\n\nbut got this, where x's come first:\ndiff --git a/x b/x\ndiff --git a/y b/y\n\nI know about the -O<orderfile> option, and it can make git-diff do\nwhat I want, but only if I first create a separate file containing\nthe names that I'm already providing to git-diff in the very same order.\n\nIs there an easier way?\n\nIf not, would you be amenable to a new option enabling this behavior\nwithout requiring a temporary file?\n\n"},{"id":"298242","messageId":"7vd58g9pfs.fsf@assigned-by-dhcp.cox.net","threadId":"43535","inReplyTo":"871wowzx15.fsf@rho.meyering.net","subject":"Re: an option to make \"git-diff Z A\" prints Z's diff before A's","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-25T19:16:07Z","receivedAt":"2006-10-25T19:16:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jim Meyering <jim@meyering.net> writes:\n\n> In a recent patch set I prepared, I placed the names of the\n> more relevant files at the front of the list given to \"git-diff\".\n>...\n> I know about the -O<orderfile> option, and it can make git-diff do\n> what I want, but only if I first create a separate file containing\n> the names that I'm already providing to git-diff in the very same order.\n>\n> Is there an easier way?\n\nNo, not right now.\n\n> If not, would you be amenable to a new option enabling this behavior\n> without requiring a temporary file?\n\nThe thing is, \"git diff -- Z A\" does *not* mean:\n\n\tI know I have a file called Z and a file called A;\n\tplease give diff for these files.\n\nWhat it means is:\n\n\tPlease give me the diff as usual, but I care about paths\n\tthat match these patterns, Z or A.\n\nSo \"git diff -- Documentation\" names all changed files in that\ndirectory; you could also spell it \"Documentation/\" for clarity.\n\ngit-diff traverses two tree-like things (either tree-vs-tree,\ntree-vs-index, or tree-vs-working tree) in parallel in the\ncanonical order, but skips comparing paths that do not match the\nlist of patterns you gave on the command line.  While it does\nso, we do not record which pattern caused the path to be\nincluded in the output anywhere, so there currently is no way to\ntell which ones matched an earlier pattern and which ones\nmatched a later one.\n\nIf somebody wants to do this, the place to modify would be the\nfollowing:\n\n - add a new parameter, \"int match_number\", to change_fn_t and\n   add_remove_fn_t functions, and add a new member to struct\n   diff_filepair to record it.\n\n - update all callers of diff_addremove, diff_change, and\n   diff_unmerge to pass which pathspec the user gave on the\n   command line matched the path to be included (in your example\n   if both Z and A were directory, file Z/foo gets number 1 and\n   file A/bar gets number 2).\n\n - update diff_addremove, diff_change and diff_unmerge to pass\n   that match_number to diff_queue(), and make diff_queue()\n   record the number in the new diff_filepair it creates.\n\n - in places where an existing filepair is split into two and\n   two existing filepairs are merged into one (e.g. \"break\" and\n   \"rename\"), make sure match_number is propagated sensibly from\n   the original filepairs to the modified ones.\n\n - in diffcore_std(), if orderfile is not in use, use the\n   match_number to sort the queued filepairs.\n\n"},{"id":"297355","messageId":"20061026084221.GB13780@diana.vm.bytemark.co.uk","threadId":"43535","inReplyTo":"7vd58g9pfs.fsf@assigned-by-dhcp.cox.net","subject":"Re: an option to make \"git-diff Z A\" prints Z's diff before A's","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2006-10-26T08:42:21Z","receivedAt":"2006-10-26T08:42:21Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2006-10-25 12:16:07 -0700, Junio C Hamano wrote:\n\n> The thing is, \"git diff -- Z A\" does *not* mean:\n>\n>       I know I have a file called Z and a file called A; please give\n>       diff for these files.\n>\n> What it means is:\n>\n>       Please give me the diff as usual, but I care about paths that\n>       match these patterns, Z or A.\n\nA related question: is there a way to limit the path to Z, but\nexcluding Z/B? That is, I'm interested in the changes in Z, but not\nthe changes in its subdirectory B.\n\n-- \nKarl Hasselström, kha@treskal.com\n"},{"id":"296846","messageId":"Pine.LNX.4.64.0610260812120.3962@g5.osdl.org","threadId":"43535","inReplyTo":"20061026084221.GB13780@diana.vm.bytemark.co.uk","subject":"Re: an option to make \"git-diff Z A\" prints Z's diff before A's","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-10-26T15:16:49Z","receivedAt":"2006-10-26T15:16:49Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 26 Oct 2006, Karl Hasselström wrote:\n> \n> A related question: is there a way to limit the path to Z, but\n> excluding Z/B? That is, I'm interested in the changes in Z, but not\n> the changes in its subdirectory B.\n\nWe never did that, no. It's certainly a relevant thing to do, and it would \nbe sensible to have a kind of common logic with revision parsing (where a \ncaret (^) at the beginning would mean \"not\"), but at the same time, it's \nnot been common enough (read: \"I have personally never missed it\") to \nactually become an issue.\n\nSo I _think_ it would fit fairly well into the current code (just teach \nthe stuff that uses \"char **pathspec\" about that new rule), and it might \nnot be too bad. On the other hand, that particular code is pretty dense \nand part of a very core and performance critical subsystem, so unless you \n_really_ want this, you might be better off averting your eyes and just \nignoring this issue ;)\n\n\t\t\tLinus"}]}