Commit Briefs
refactor got_patch / got_worktree_patch_complete
let got_patch own fileindex_path and call got_worktree_patch_complete only if got_wokrtree_patch_prepare hasn't failed. suggested by stsp@
got patch: avoid open/sync/close the fileindex over and over again
Instead of flushing the fileindex after every patch in the patchfile just reuse the same fileindex and sync it only at the end of the patch operation. This speeds up 'got patch' on large repositories by quite a lot.
got patch: allow to reverse a patch
add a flag to got_patch to reverse a patch before applying and the -R flag for `got patch'. ok stsp@
got-read-patch: preserve all \ lines
as a cheap optimization got-read-patch was sending only the "\ No newline at end of file" lines that follows an addition (a "+" line). To be able to reverse patches in the future got_patch needs to know about all of these lines instead. No functional changes intended. ok stsp@
got patch: resolve paths from the current working directory
this allow to apply patches from subdirectories of the work tree root. Prodded by naddy@, ok stsp@.
got patch: allow to strip path components
Move some bits from the libexec helper to the main process so we know if the patch was generated by git or not and finally document the automatic stripping of a/ and b/ prefixes added by git-diff(1). ok stsp@
move got_patch file status checking in worktree.c
check_file_status used got_worktree_status to check if the file was in an allowed state, but it's wrong since the callback is not invoked on unchanged files. While here also fix a relate bug: unlink(newpath) is in the wrong spot and ends up removing files even when it shouldn't, so move it early in the got_worktree_schedule_* error handling. Finally, update the appropriate test case. It was passing before because got_worktree_schedule_add returned GOT_ERR_FILE_STATUS, not because check_file_status failed. ok stsp@
augment patch progress callback with hunks info; recover from errors
Augment got_patch_progress_cb by providing the hunks that were applied with offset (or that failed) and the recoverable error encountered during the operation (bad status, missing file, ...) got_patch now proceeds when a file fails to be patched and exits with GOT_ERR_PATCH_FAILED if no other errors are encountered. While here, also add a test for the 'hunk applied with offset' case and shrink test_patch_dont_apply and illegal_status by taking advantage that 'got patch' doesn't stop at the first error. (And add some other cases to illegal_status too.) discussed with and ok stsp@
introduce got_patch_progress_cb
This introduce a proper got_patch specific progress callback that is invoked after processing a patch. It also drops the hackish printf in the modified case and takes `nop' out of the struct got_patch. ok stsp
add a dry-run/nop mode for got patch
with lots of help from stsp for the manpage bits!
check file status before applying the patch
Don't allow `got patch' to delete files that are not known, or add files that are already known and to edit files that are known, not obstructed and without conflicts.
refactor apply_patch to support renaming files
add two helper functions (schedule_add, schedule_del) and move the guts of apply_patch into a new function `patch_file'. This simplifies apply_patch and makes easier to figure out what happens. Then, drop GOT_ERR_PATCH_PATHS_DIFFER since we allow the to rename files.
save `pos' in locate_hunk instead of calling ftello again
ok thomas, stsp