lib/patch.c


Log

Author Commit Date CI Message
Tracey Emery eb81bc23 2022-06-28T13:27:12 move got_opentempfd out of open_blob. ok stsp@
Omar Polo 497a5915 2022-06-27T18:47:02 handle blob ids without corresponding blob ids ok stsp@
Omar Polo db0dfdd7 2022-06-27T18:47:02 got patch: handle git-style diffs for the 3-way merge too tweak and ok stsp@
Omar Polo 9802c41c 2022-06-21T16:52:34 got patch: use status G for merged files (and document it) Suggested by stsp@. This makes possible to tell if 'got patch' used a merge-base from the repository for the 3-way merge or did a simple search/replace operation. While here update the tests to look for the 'G' status and the manpage, which was also missing the documentation for the 'C' status in got patch. ok stsp@
Omar Polo dbc68eed 2022-06-21T16:52:34 got patch: ignore blobs not found since diffs are often enclosed in other formats (e.g. emails) we might parse something and think it's a blob id when it's not. This should already happens, but apply_patch is looking for the wrong error due to a leftover from previous attempts. Reported by stsp@ while here tweak the test_patch_merge_unknown_blob to also try with a dummy commit id, as now got-read-patch requires it in order to consider a blob id. ok stsp@
Omar Polo d8b5af43 2022-06-19T11:51:33 use the commitid in the patch diff3 conflict header suggested by and ok stsp@
Omar Polo 55e9459f 2022-06-19T11:51:32 got patch: use diff3 to merge the changes Parse the "blob -" metadata in diffs produced by 'got diff' and use the original file for patching. Then, use the diff3 with the current version of the file to merge the differences. This solves many failures automagically or at least turns them into a conflict. ok/improvements stsp@
Omar Polo 05737d49 2022-06-19T11:51:32 patch_file: fill tmp with the patched file even in nop mode future work with diff3 merge will need the fully patched file even in the nop mode ok stsp@
Omar Polo 827bcd6c 2022-06-19T11:51:32 patch_file: move file ownership to parent ok stsp@
Omar Polo 1b1b91ab 2022-06-15T21:21:27 style: remove double semicolon
Stefan Sperling 06c44edc 2022-06-15T13:10:50 check for errors from fclose() in patch_file()
Omar Polo 11ce22a1 2022-06-15T12:50:10 plug memory and fd leak in got patch
Omar Polo 35095610 2022-06-14T10:35:07 got patch: use ints for line offsets instead of longs ints have the advantage that their size is more likely to be the same across the various architecture supported by OpenBSD, thus introducing less possible differences. INT_MAX is still (at least) a few order of magnitudes higher than the patches we dealt with (even abnormal ones.) suggested by stsp@
Omar Polo 5b7126c5 2022-06-14T08:31:16 actually guarding against negative line offsets previous commit looked at some pretty zeroes returned from calloc instead of the actual numbers received.
Omar Polo 2399b53d 2022-06-14T08:26:27 style; set datalen only once
Omar Polo 71393b5c 2022-06-14T08:10:55 got patch: guard against invalid (negative) line offsets under normal circumstances got-read-patch can't send negative line offsets; that's not an excuse not to guard the main process from those as well. This makes sure we bail out early instead of trying to apply the diff.
Omar Polo 0e07a2a1 2022-06-13T20:57:43 free patch on error
Omar Polo 99b94ad7 2022-06-13T20:30:09 got patch: ensure new and old paths are NUL-terminated
Omar Polo 4bcdc895 2022-05-17T17:35:17 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@
Omar Polo f2dd7807 2022-05-17T13:28:02 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.
Christian Weisgerber e45f7eba 2022-05-14T18:55:37 got patch: switch from fseek() to fseeko(), use unary minus while here ok op
Omar Polo be33dff7 2022-05-13T15:28:04 got patch: fail when reading empty hunks
Omar Polo bad961bf 2022-04-23T10:39:47 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@
Omar Polo b2832778 2022-04-23T10:39:47 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@
Omar Polo ed3bff83 2022-04-23T07:56:18 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@.
Omar Polo 41a37a44 2022-04-23T07:49:42 fix wrong path in error message
Omar Polo 9d6cabd5 2022-04-07T09:28:59 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@
Omar Polo fbbb53b9 2022-03-25T23:08:27 remove trailing whitespaces
Omar Polo b3c57ab2 2022-03-22T11:20:46 got patch: handle "\ No newline at end of file"
Omar Polo 4027dbc2 2022-03-22T11:20:46 reuse apply_hunk in patch_file when creating a file
Omar Polo 78f5ac24 2022-03-19T15:06:37 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@
Omar Polo 46ebad13 2022-03-17T16:38:43 style
Omar Polo 60aa1fa0 2022-03-17T16:38:43 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@
Omar Polo 95d68340 2022-03-16T18:23:03 got patch: create missing directories when adding files ok stsp@
Omar Polo 2be5e1a2 2022-03-16T18:23:03 got patch: keep permissions after patching a file ok stsp@
Omar Polo b22138f5 2022-03-16T15:41:10 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
Omar Polo 899fcfdf 2022-03-13T20:31:44 add a dry-run/nop mode for got patch with lots of help from stsp for the manpage bits!
Omar Polo 5b67f96e 2022-03-13T15:36:59 got patch: require exact match when removing files
Omar Polo dbda770b 2022-03-13T15:36:56 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.
Omar Polo 6e96b326 2022-03-12T16:02:51 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.
Omar Polo b95c53df 2022-03-12T16:01:09 apply_patch: move sanity check early in recv_patch
Omar Polo 33df9995 2022-03-11T17:25:33 save `pos' in locate_hunk instead of calling ftello again ok thomas, stsp
Omar Polo d955343d 2022-03-08T16:01:03 pass the callback data instead of hardcoding NULL, ok stsp
Omar Polo 6f5cb1bd 2022-03-08T12:22:36 fix path to the temp file used to accumulate the patch edits ok stsp
Omar Polo e9ce266e 2022-03-07T22:26:08 add `got patch' command for applying unified diffs