git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Problem with git format-patch and --src-prefix and --dst-prefix

From
PPPhil Pokorny <ppokorny@penguincomputing.com>
Date
Aug 12, 2021, 17:43 UTC
Message-ID
<CAAek22FLBGWAM_MJmUag7YgfGCXLd58pruwLm2AsqMtohdmBLA@mail.gmail.com>

I'm trying to use git format-patch -> git am to port commits between two repositories

In the source repository, the files are in the root directory of the repository (./file) In the destination repository, the files are in a sub-directory (./dir/file).

The --src-prefix and --dst-prefix seem to be the perfect tool for the job of getting the patch stream output by format-patch to have the right format to apply in the destination repository.

Like so:
git format-patch -N -p --src-prefix=a/dir/ --dst-prefix=/b/dir/ -o ../xfer.1
and then in the destination.
git am ../xfer.1

But in the resulting diff's in addition to the requested prefix changes, there were also 'deleted file mode 100644' lines added.

It's subtle, but I now realize this was because of a typo (vs my intent) in the above command. The --dst-prefix starts with a slash "/" not "b/dir/" as I intended.

So I think I stumbled into a problem with the builtin_diff code here: https://git.kernel.org/pub/scm/git/git.git/tree/diff.c?id=eab9a40b6dd5c1c571b1deb264133db47bb4794d#n1216

It uses the short-hand of testing just the first character of lbl[0] and lbl[1] to decide if the source is /dev/null or the destination is /dev/null to print "new file" or "deleted file" lines. But with src-prefix and dst-prefix, those lines could be triggered incorrectly with a prefix that begins with / which might have a legitimate reason for others to do.

I'm new to git development, but I'm willing to try and work up a patch if this is a valid issue and someone can help guide me through the submission process.

Thanks, Phil P.

Message 1 of 1 in “Problem with git format-patch and --src-prefix and --dst-prefix”
  1. Phil PokornyAug 12, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.