To now document how this effort turned out:
Yes, patch
does overwrite .rej
files, and Leon's suggested script was my very fine starting point. However, I found that the content of the .rej
file was essentially useless to me. Re-reading the patch
documentation (on Linux, but not(!) on Macintosh OS/X!), I saw that there was a --merge
option available which would produce the <<<< ==== >>>>
modifications to the file (as git
routinely does ...)
I used the git format-patch
command to obtain the list of commits as individual patch files, and modified Leon's original script to loop through the contents of that directory.
Instead of using the -r
option, as Leon suggested, I used the --merge
option. Since there would now be no reject-file to test for, I changed the script to use the exit-code ("$?"
) of the patch
command, instead. (As usual, "zero equals success.")
If the patch
command succeeded (returned zero ...), my script would mv
the patch-file into another directory of "patches applied." If not, it would print a message and stop. I resolved each such occurrence in the following way:
One by one, notice which of the files in the patch had errors. Open each of these files and search for the <<<<<
tag. In this way I could see the two alternatives side-by-side, and, case-by-case, I made an individual choice and manual correction.
Then, mv
the patch-file to the "patches applied" directory, just as the script would have done had the patch been entirely applied without error.
Scan the (PHP ...) source-directory for any syntax errors, using a custom tool of my devising. Immediately(!) resolve any issues found.
git commit
the changes ... just in case!
Start the script again ...
And now, an interesting issue . . .
Now, as I said in the original post, I was applying these (hundreds of ...) patches to a source-code base that had been textually copied from it for many months' time. (At the time of the split, a git
repository didn't even exist. The company was still using SVN.) So, patch
almost-never was able to rely on line-numbers.
In every case, patch
did find thought that it had found the correct place to apply each patch, at some "offset" from the line-number listed in the patch. Nevertheless, I found in some cases that patch
had not(!) correctly identified everything. Sometimes, it flagged an "insertion" in front of an identical piece of existing code, where a human being would recognize that it was not an insertion at all.
I am, of course, at this moment "anxiously hoping" that in each case patch
did "recognize its own uncertainty," and that therefore none of the "successfully applied" patches (about two-thirds of them, as it turns out ...) will prove to have duplication issues. (This is one of the primary reasons why we constantly checked for syntax-errors anywhere in the code base, and, as it happens, almost never found any.)