{"thread":{"id":"14162","subject":"git-diff/git-format-patch safe for GNU (or POSIX) patch?","startedAt":"2008-06-26T10:27:39Z","lastAt":"2008-06-26T13:44:00Z","messageCount":5,"participants":["Flavio Poletti","Karl Hasselström","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"81263","messageId":"58230.213.203.159.164.1214476059.squirrel@upmail.polettix.it","threadId":"14162","inReplyTo":null,"subject":"git-diff/git-format-patch safe for GNU (or POSIX) patch?","fromName":"Flavio Poletti","fromEmail":"flavio@polettix.it","sentAt":"2008-06-26T10:27:39Z","receivedAt":"2008-06-26T10:27:39Z","isPatch":false,"sender":{"key":"flavio@polettix.it","avatar":"https://gravatar.com/avatar/5466f4891265e5b9f386e334a5a1100866c8a74148e8144a49e4ffef735bf22a?d=mp&s=160"},"body":"Hi,\n\n   I had to dig a problem in Glib (\"base\" library for GTK) in Debian Etch\nrecently and I decided to manage changes/diffs with git. It's just so\neasy to use and avoids all the usual copy-the-tree-then-diff that I\nused before.\n\nWhen I was happy with the modifications, I used git-format-patch to\nproduce the message and the patch to send. I then saw that the format is a\nlittle different with respect to what diff -u produces; in particular, I\nnoticed that there was an added line between the \"diff --git...\" line and\nthe one stating the \"origin\" file:\n\n                   diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c\n*** this one ***   index 61d11ed..7786f10 100644\n                   --- a/glib/gstrfuncs.c\n                   +++ b/glib/gstrfuncs.c\n\nMoreover, each chunk's header contained added stuff, like the\n\"g_ascii_strtoll...\" stuff in the following example line:\n\n    @@ -813,6 +813,8 @@ g_ascii_strtoll (const gchar *nptr,\n\nBefore sending the patch, I tried to \"reverse\" these \"deviations\" from the\nnormal diff output, but I was quite sure there was no need to do this. I\nthen tried to use GNU patch with the unaltered message, and it seemed\nquite happy with all the extra stuff.\n\nJust to be on the safe side, I tried to look for:\n1. the \"official\" unified diff spec\n2. a description of what patch is willing to consider valid input\n3. some notes about how git-diff copes with patch compatibility\n4. some hints to use git for working on projects that do not use any other\nVCS, or for which one only wants to produce and send a quick patch\nstarting from a tarball.\n\nI had no luck with the first two attempts, and a moderate luck with the\nthird: there is more than one email from Junio C. Hamano either stating\nthat git-diff strives to be nice with patch, or containing patches to\naddress possible conformance issues. I was also quite unluck with the\nfourth attempt, even if this is surely due to my poor websurfing-fu.\n\nAnyway, the messages from Mr. Hamano kind-of answer the question in the\nsubject, but in a somehow \"implicit\" way rather than explicitly. In\nparticular, I wonder if there is any document about how a \"valid\" unified\ndiff should look like (including optional valid extensions) that was used\nas input and reference for git-diff development. Or had you just to figure\nit out from diff/patch sources?\n\nThank you,\n\n   Flavio.\n"},{"id":"81265","messageId":"20080626103607.GA16525@diana.vm.bytemark.co.uk","threadId":"14162","inReplyTo":"58230.213.203.159.164.1214476059.squirrel@upmail.polettix.it","subject":"Re: git-diff/git-format-patch safe for GNU (or POSIX) patch?","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-06-26T10:36:07Z","receivedAt":"2008-06-26T10:36:07Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-06-26 12:27:39 +0200, Flavio Poletti wrote:\n\n> When I was happy with the modifications, I used git-format-patch to\n> produce the message and the patch to send. I then saw that the\n> format is a little different with respect to what diff -u produces;\n> in particular, I noticed that there was an added line between the\n> \"diff --git...\" line and the one stating the \"origin\" file:\n>\n>                    diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c\n> *** this one ***   index 61d11ed..7786f10 100644\n>                    --- a/glib/gstrfuncs.c\n>                    +++ b/glib/gstrfuncs.c\n\npatch ignores any junk it doesn't understand, including this line.\n\n> Moreover, each chunk's header contained added stuff, like the\n> \"g_ascii_strtoll...\" stuff in the following example line:\n>\n>     @@ -813,6 +813,8 @@ g_ascii_strtoll (const gchar *nptr,\n\nYou get this by giving the -p flag to GNU diff; git diff just does it\nby default, is all.\n\n> 4. some hints to use git for working on projects that do not use any\n> other VCS, or for which one only wants to produce and send a quick\n> patch starting from a tarball.\n\nYou can use git/contrib/fast-import/import-tars.perl to import the\nlast few releases into git (possibly just the last release, if you\ndon't need the history) and then just build on that, and send patches\nback to the project when you're done.\n\nWhen the project makes another release, use import-tars to import the\nnew tarball, and then rebase if you have any patches they haven't\naccepted yet.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"81274","messageId":"58284.213.203.159.164.1214480989.squirrel@upmail.polettix.it","threadId":"14162","inReplyTo":"20080626103607.GA16525@diana.vm.bytemark.co.uk","subject":"Re: git-diff/git-format-patch safe for GNU (or POSIX) patch?","fromName":"Flavio Poletti","fromEmail":"flavio@polettix.it","sentAt":"2008-06-26T11:49:49Z","receivedAt":"2008-06-26T11:49:49Z","isPatch":false,"sender":{"key":"flavio@polettix.it","avatar":"https://gravatar.com/avatar/5466f4891265e5b9f386e334a5a1100866c8a74148e8144a49e4ffef735bf22a?d=mp&s=160"},"body":"Thanks for the feedback! I wonder if this feature of patch \"ignoring\"\nstuff it doesn't understand is a GNU feature or a POSIX feature, but I'm\nabusing your patience here. (Incidentally, I also saw that POSIX has no\n\"unified\" format, but this \"ignoring\" feature might apply in a wider\nsense).\n\n>> 4. some hints to use git for working on projects that do not use any\n>> other VCS, or for which one only wants to produce and send a quick\n>> patch starting from a tarball.\n>\n> You can use git/contrib/fast-import/import-tars.perl to import the\n> last few releases into git (possibly just the last release, if you\n> don't need the history) and then just build on that, and send patches\n> back to the project when you're done.\n>\n> When the project makes another release, use import-tars to import the\n> new tarball, and then rebase if you have any patches they haven't\n> accepted yet.\n\nImporting wasn't actually an issue, just a matter of init/add/commit. I\nwas more scared about the patch production process, i.e. producing a patch\nthat could be perfectly usable by the project's maintainers. But given\nwhat you kindly said, I think I can dismiss this as excess of caution by\nme.\n\nThanks,\n\n   Flavio.\n"},{"id":"81286","messageId":"20080626124927.GA17731@diana.vm.bytemark.co.uk","threadId":"14162","inReplyTo":"58284.213.203.159.164.1214480989.squirrel@upmail.polettix.it","subject":"Re: git-diff/git-format-patch safe for GNU (or POSIX) patch?","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-06-26T12:49:27Z","receivedAt":"2008-06-26T12:49:27Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-06-26 13:49:49 +0200, Flavio Poletti wrote:\n\n> Importing wasn't actually an issue, just a matter of\n> init/add/commit. I was more scared about the patch production\n> process, i.e. producing a patch that could be perfectly usable by\n> the project's maintainers. But given what you kindly said, I think I\n> can dismiss this as excess of caution by me.\n\nYes, patch is one of the most permissive programs around. It will eat\n_anything_. (And throw up on the carpet if it was just too wrong.)\n\nThere are two things in git patches that patch won't grok: rename/copy\npatches, and binary patches. Neither feature is on by default, IIRC --\nyou have to give command line flags -- precisely so that \"git diff\"\ndefault output will be patch compatible.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"81289","messageId":"20080626134400.GC12567@machine.or.cz","threadId":"14162","inReplyTo":"58284.213.203.159.164.1214480989.squirrel@upmail.polettix.it","subject":"Re: git-diff/git-format-patch safe for GNU (or POSIX) patch?","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-06-26T13:44:00Z","receivedAt":"2008-06-26T13:44:00Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Thu, Jun 26, 2008 at 01:49:49PM +0200, Flavio Poletti wrote:\n> Thanks for the feedback! I wonder if this feature of patch \"ignoring\"\n> stuff it doesn't understand is a GNU feature or a POSIX feature, but I'm\n> abusing your patience here. (Incidentally, I also saw that POSIX has no\n> \"unified\" format, but this \"ignoring\" feature might apply in a wider\n> sense).\n\nAs you say, POSIX does not specify unified diffs at all. I'm not sure if\npatch's policy is as relaxed for other formats and I didn't find\nany mention of this relaxed policy in the SUS spec, but unified diffs\nwith extraneous information intertwined are extremely widespread; about\nany VCSes out there append extra information to the diffs.\n\nIncidentally, does anyone actually know about _any_ other patch tool in\nthe wild that is _not_ based on the original Larry Wall's patch?\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nThe last good thing written in C++ was the Pachelbel Canon. -- J. Olson\n"}]}