{"thread":{"id":"56271","subject":"Problem with git format-patch and --src-prefix and --dst-prefix","startedAt":"2021-08-12T17:43:21Z","lastAt":"2021-08-12T17:43:21Z","messageCount":1,"participants":["Phil Pokorny"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"432587","messageId":"CAAek22FLBGWAM_MJmUag7YgfGCXLd58pruwLm2AsqMtohdmBLA@mail.gmail.com","threadId":"56271","inReplyTo":null,"subject":"Problem with git format-patch and --src-prefix and --dst-prefix","fromName":"Phil Pokorny","fromEmail":"ppokorny@penguincomputing.com","sentAt":"2021-08-12T17:43:07Z","receivedAt":"2021-08-12T17:43:21Z","isPatch":false,"sender":{"key":"ppokorny@penguincomputing.com","avatar":null},"body":"I'm trying to use git format-patch -> git am to port commits between\ntwo repositories\n\nIn the source repository, the files are in the root directory of the\nrepository (./file) In the destination repository, the files are in a\nsub-directory (./dir/file).\n\nThe --src-prefix and --dst-prefix seem to be the perfect tool for the\njob of getting the patch stream output by format-patch to have the\nright format to apply in the destination repository.\n\nLike so:\n\ngit format-patch -N -p --src-prefix=a/dir/ --dst-prefix=/b/dir/ -o ../xfer.1\n\nand then in the destination.\n\ngit am ../xfer.1\n\nBut in the resulting diff's in addition to the requested prefix\nchanges, there were also\n'deleted file mode 100644' lines added.\n\nIt's subtle, but I now realize this was because of a typo (vs my\nintent) in the above command. The --dst-prefix starts with a slash \"/\"\nnot \"b/dir/\" as I intended.\n\nSo I think I stumbled into a problem with the builtin_diff code here:\nhttps://git.kernel.org/pub/scm/git/git.git/tree/diff.c?id=eab9a40b6dd5c1c571b1deb264133db47bb4794d#n1216\n\nIt uses the short-hand of testing just the first character of  lbl[0]\nand lbl[1] to decide if the source is /dev/null or the destination is\n/dev/null to print \"new file\" or \"deleted file\" lines.  But with\nsrc-prefix and dst-prefix, those lines could be triggered incorrectly\nwith a prefix that begins with / which might have a legitimate reason\nfor others to do.\n\nI'm new to git development, but I'm willing to try and work up a patch\nif this is a valid issue and someone can help guide me through the\nsubmission process.\n\nThanks,\nPhil P.\n"}]}