{"thread":{"id":"29342","subject":"git diff <file> HEAD^:<file> error message","startedAt":"2012-01-11T11:18:31Z","lastAt":"2012-01-12T17:34:50Z","messageCount":4,"participants":["Carlos Martín Nieto","Junio C Hamano","Nguyen Thai Ngoc Duy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"182341","messageId":"20120111111831.GB15232@beez.lab.cmartin.tk","threadId":"29342","inReplyTo":null,"subject":"git diff <file> HEAD^:<file> error message","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2012-01-11T11:18:31Z","receivedAt":"2012-01-11T11:18:31Z","isPatch":false,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"Hello,\n\nI was trying to figure out why running\n\n   git diff HEAD^:RelNotes RelNotes\n\ngives the expected output (on maint it tells me that the stable\nversion changed from 1.7.8.3 to 1.7.8.4) but swapping the arguments\ndoesn't.\n\n   git diff RelNotes HEAD^:RelNotes\n\ndoesn't show the opposite patch but tells me that RelNotes doesn't\nexist in HEAD^ which is clearly a lie (it sounds like it's a\nmisunderstanding on git's part, but it's certainly not the truth). In\nboth cases, verify_filename gets called and tries to stat both\nHEAD^:RelNotes and RelNotes. In the \"bad\" (latter) case, after it\nfails to find a file named \"HEAD^:RelNotes\" it ends up calling\ndiagnose_invalid_sha1_path which is not correct according to the\ncommand just before the function\n\n    /* Must be called only when object_name:filename doesn't exist. */\n\nIt looks like get_sha1_with_context_1 gets confused because we pass it\na filename which looks like object_name:filename even though we\nearlier parsed it simply as a filename which happens to have a colon\ninside it.\n\nAnother issue is that I'm not sure that the error message should even\nget shown. The documentation tells me that I should be able to compare\ntwo random blobs, though this mode doesn't seem to work if the first\nargument is a file. I realise that a file isn't a blob, but since\nspecifying the arguments the other way around (blob, file) does work,\nit looks to me like it should as well.\n\n   cmn\n"},{"id":"182400","messageId":"7vr4z54pwp.fsf@alter.siamese.dyndns.org","threadId":"29342","inReplyTo":"20120111111831.GB15232@beez.lab.cmartin.tk","subject":"Re: git diff <file> HEAD^:<file> error message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-12T02:26:30Z","receivedAt":"2012-01-12T02:26:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlos Martín Nieto <cmn@elego.de> writes:\n\n> I was trying to figure out why running\n>\n>    git diff HEAD^:RelNotes RelNotes\n>\n> gives the expected output (on maint it tells me that the stable\n> version changed from 1.7.8.3 to 1.7.8.4) but swapping the arguments\n> doesn't.\n>\n>    git diff RelNotes HEAD^:RelNotes\n>\n> doesn't show the opposite patch ...\n\nThat comes from the general argument parsing rules of Git, namely, global\noptions (e.g. --paginate) first, then subcommand name, followed by dashed\noptions, revs and finally the paths. Once you give \"RelNotes\", which\ncannot be a rev, you cannot give a rev.\n\nWe _could_ special case the rule for \"diff\", but we simply didn't bother,\nas the resulting code (and the implications of special casing) would be\ntoo ugly to live to support such a corner case usage, especially when you\ncould always say \"-R\" to reverse the output.\n"},{"id":"182426","messageId":"20120112103152.GC11984@beez.lab.cmartin.tk","threadId":"29342","inReplyTo":"7vr4z54pwp.fsf@alter.siamese.dyndns.org","subject":"Re: git diff <file> HEAD^:<file> error message","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2012-01-12T10:31:52Z","receivedAt":"2012-01-12T10:31:52Z","isPatch":false,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"On Wed, Jan 11, 2012 at 06:26:30PM -0800, Junio C Hamano wrote:\n> Carlos Martín Nieto <cmn@elego.de> writes:\n> \n> > I was trying to figure out why running\n> >\n> >    git diff HEAD^:RelNotes RelNotes\n> >\n> > gives the expected output (on maint it tells me that the stable\n> > version changed from 1.7.8.3 to 1.7.8.4) but swapping the arguments\n> > doesn't.\n> >\n> >    git diff RelNotes HEAD^:RelNotes\n> >\n> > doesn't show the opposite patch ...\n> \n> That comes from the general argument parsing rules of Git, namely, global\n> options (e.g. --paginate) first, then subcommand name, followed by dashed\n> options, revs and finally the paths. Once you give \"RelNotes\", which\n> cannot be a rev, you cannot give a rev.\n> \n> We _could_ special case the rule for \"diff\", but we simply didn't bother,\n> as the resulting code (and the implications of special casing) would be\n> too ugly to live to support such a corner case usage, especially when you\n> could always say \"-R\" to reverse the output.\n\nThe rule \"non-rev stops rev parsing\" is fair enough. The error message\nis still very misleading, as it lies about RelNotes not being in HEAD^\nand gives the impression that it was parsed as a rev (which I guess it\nwas, but only to show the message).\n\n   cmn\n\n"},{"id":"182445","messageId":"CACsJy8AFE0R3nfhfJkuZTkvWBmOR8+sPZDqA6SUdH17hgmTnMA@mail.gmail.com","threadId":"29342","inReplyTo":"20120111111831.GB15232@beez.lab.cmartin.tk","subject":"Re: git diff <file> HEAD^:<file> error message","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-12T17:34:50Z","receivedAt":"2012-01-12T17:34:50Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jan 11, 2012 at 6:18 PM, Carlos Martín Nieto <cmn@elego.de> wrote:\n> Hello,\n>\n> I was trying to figure out why running\n>\n>   git diff HEAD^:RelNotes RelNotes\n>\n> gives the expected output (on maint it tells me that the stable\n> version changed from 1.7.8.3 to 1.7.8.4) but swapping the arguments\n> doesn't.\n>\n>   git diff RelNotes HEAD^:RelNotes\n>\n> doesn't show the opposite patch but tells me that RelNotes doesn't\n> exist in HEAD^ which is clearly a lie (it sounds like it's a\n> misunderstanding on git's part, but it's certainly not the truth).\n\nI find Jonathan's comment [1] interesting: \"Meanwhile, there is no\nplumbing command to compare two blobs. Strange\".\n\nI _think_ the main purpose of git diff is to compare a stage (a\nrevision, index, worktree) with another stage, filtered by path and\nblob-to-blob diff is a minor thing that is needed to support \"git diff\n<tag> <tag>\" where both tags point to a tag. It'd be better to start a\nnew command that diff between two blobs (or files in worktree/index).\nSomething pretty close to --no-index. You would not need to mess up\nwith setup_revisions() or verify_filename().\n\n[1] ed84e6d (Documentation: diff can compare blobs - 2010-10-11)\n-- \nDuy\n"}]}