Commit graph

6 commits

Author SHA1 Message Date
Shannon Booth
dd373eacbc LibDiff+patch: Support multiple patches in a single patch file
Multiple patches may be concatenated in the same patch file, such as git
commits which are changing multiple files at the same time. To handle
this, parse each patch in order in the patch file, and apply each patch
sequentially.

To determine whether we are at the end of a patch (and not just parsing
another hunk) the parser will look for a leading '@@ ' after every hunk.
If that is found, there is another hunk. Otherwise, we must be at the
end of this patch.
2023-07-30 07:47:22 +01:00
Shannon Booth
f893e0820f patch: Support creation of a file
Previously patch would always expect the file that it was patching to
exist (even it were empty). If we know that the patch is creating a file
from nothing (i.e has a start line of '0'), then we treat a file that
doesn't exist as if it has no content lines.
2023-07-30 07:47:22 +01:00
Shannon Booth
81df0278b1 patch+LibDiff: Implement 'strip' of filenames when parsing patch
Implement the patch '-p' / '--strip' option, which strips the given
number of leading components from filenames parsed in the patch header.
If not given this option defaults to the basename of that path.
2023-07-29 17:09:09 -06:00
Shannon Booth
4d8a59f34b patch: Implement d, --directory option
When given, patch will chdir into the given directory before processing
the patch file.
2023-07-29 17:09:09 -06:00
Shannon Booth
2b46e6f664 Everywhere: Update copyrights with my new serenityos.org e-mail :^) 2023-07-15 16:21:29 +02:00
Shannon Booth
e838b6c8cc patch: Add the beginnings of a patch utility
This is still very bare bones, and there is _much_ more to still
handle. However, this implements enough functionality to parse a single
unified patch read from stdin, and apply it to a file.
2023-07-13 10:29:30 +01:00