commit dbc68eedb1de26bf5a444ecad5150b0a243d422b from: Omar Polo date: Tue Jun 21 16:52:34 2022 UTC 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@ commit - 63ba1a3a6f40953d1636e718c0e0000a3d626159 commit + dbc68eedb1de26bf5a444ecad5150b0a243d422b blob - 9209e54ce7111b54b69980a44a48a92a333e5888 blob + 1fc82c6604c60d1e3961f7d6670b26b781db97cc --- lib/patch.c +++ lib/patch.c @@ -643,7 +643,11 @@ apply_patch(int *overlapcnt, struct got_worktree *work /* don't run the diff3 merge on creations/deletions */ if (*p->blob != '\0' && p->old != NULL && p->new != NULL) { err = open_blob(&apath, &afile, p->blob, repo); - if (err && err->code != GOT_ERR_NOT_REF) + /* + * ignore failures to open this blob, we might have + * parsed gibberish. + */ + if (err && !(err->code == GOT_ERR_ERRNO && errno == ENOENT)) return err; else if (err == NULL) do_merge = 1; blob - 20e899eab3a352dc9e8636b15e894c186595d20a blob + 5d79b58c66cb3e7160cfdb8ce13e13901219e70e --- regress/cmdline/patch.sh +++ regress/cmdline/patch.sh @@ -1588,9 +1588,11 @@ test_patch_merge_unknown_blob() { cat < $testroot/wt/patch I've got a +diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar +with a blob - aaaabbbbccccddddeeeeffff0000111122223333 and also a -blob + 0000111122223333444455556666888899990000 +blob + 0000111122223333444455556666777788889999 for this dummy diff --- alpha +++ alpha @@ -1612,7 +1614,40 @@ EOF ret=$? if [ $ret -ne 0 ]; then diff -u $testroot/stdout.expected $testroot/stdout + test_done $testroot $ret + return 1 fi + + # try again without a `diff' header + + cat < $testroot/wt/patch +I've got a +blob - aaaabbbbccccddddeeeeffff0000111122223333 +and also a +blob + 0000111122223333444455556666777788889999 +for this dummy diff +--- alpha ++++ alpha +@@ -1 +1 @@ +-alpha ++ALPHA +will it work? +EOF + + (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \ + > $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + test_done $testroot $ret + return 1 + fi + + echo 'M alpha' > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi test_done $testroot $ret }