summaryrefslogtreecommitdiff
path: root/sys/src/cmd/patch.c
AgeCommit message (Collapse)Author
2022-11-06patch: preserve permissions of original file when patchingOri Bernstein
2022-10-30patch: improve hunk searchMichael Forney
Keep track of last hunk offset so we are more likely to find future hunks. Start search within the range of lines where we could possibly find the hunk. This fixes a bug where if the file shrunk since the patch was generated, and we start the search past the end of the file and immediately abort the search. Add an extra offset for the end of the file to the lines array so that lines[nlines] is the length of the file. This way, when we start the search at line nlines-oldcnt, we don't access past the end of the array if oldcnt==0. When we find a hunk, set lastln to ln + h->oldcnt; we can't apply another hunk that starts before the previous hunk ends.
2022-10-22patch: fix bounds check for hunk scan in forward directionMichael Forney
Previously, hunks that end exactly at the end of the file could not be found when the matching lines were located at a positive offset.
2022-10-03patch: fix consecutive deletionsMichael Forney
Consecutive delete hunks will both have newpath of /dev/null, but we need to reslurp oldpath between these hunks.
2022-10-03patch: fix uninitialized Fbuf during dry runMichael Forney
2022-10-03patch: make slurp() return voidMichael Forney
It sysfatals if it fails and has no non-success returns.
2022-10-03patch: fix deletion of filesMichael Forney
If we are deleting a file, we do not want to attempt to create an empty /dev/null.tmp$pid. finish() doesn't look at tmp for deletions during a successful run, so leave it set to nil. On a failure, guard tmp removal on tmp != nil.
2022-09-29patch: fix line bounds check when searching for hunkMichael Forney
2022-09-28patch: fix line calculation to avoid redundant searchesMichael Forney
2022-08-16git/rebase: allow rebase without a clean treeOri Bernstein
Here, patch grows a dry run option (-n), which allows git/import to bail out early if it would patch files that are dirty in tree. Once git/import refuses to patch dirty files, git/rebase can skip checking if the whole tree is clean, which is both convenient and much faster on large trees.
2022-08-03patch: apply patches atomicallyOri Bernstein
When applying a patch, we used to write out the patch, rename the file, and then move to the next one. This meant that if a patch failed to apply cleanly, we would leave the patch half-applied. This sucked, so we now apply the patch as a whole unit, or not at all.
2022-07-02patch: handle stripped/empty lines mid-hunkOri Bernstein
Some programs will strip trailing spaces from hunks; in this case we want to treat the line as though it came with a leading space. This fixes applying some patches, such as [PATCH] Permissions for child boards in /srv
2022-06-04patch: implement a new, simpler patch program to replace ape/patchOri Bernstein
ape/patch is a giant, ugly ball of code from almost 25 years ago, which has not and will likely never been updated or maintained. the world has since settled on unified diffs, and we just need a simple program that can parse and apply them.