Download raw body.
two small fixes for got patch
Hello,
these are two unrelated tweaks but small enought that I'm sending them
together.
The first one re-adds a lost lseek in patch_from_stdin. That function
copies the patch given on standard input to a temp file; during the
refactoring before the addition of `got patch' i lost the lseek call.
Without it, `got patch < diff' always fails with "no patch found".
(while here also actually return the error...)
The second one is just a tweak: there's no need to call ftello after
locate_hunk because it already knows the current position and can just
return that to the caller.
OK?
diff refs/remotes/origin/main refs/heads/main
blob - 175740d9c6f4b9443624418107f8b2314f6f44b0
blob + 7a5b68602669bd5b67c37c03000ec4c0e5e8568f
--- got/got.c
+++ got/got.c
@@ -7150,9 +7150,12 @@ patch_from_stdin(int *patchfd)
signal(SIGINT, sigint);
signal(SIGQUIT, sigquit);
+ if (err == NULL && lseek(*patchfd, 0, SEEK_SET) == -1)
+ err = got_error_from_errno("lseek");
+
if (err != NULL)
close(*patchfd);
- return NULL;
+ return err;
}
static const struct got_error *
blob - 9bfe37463cbe64005617a3395ea55e551360f8d1
blob + 6cc85331d4129d6f7dfec267d04e16173c9608a6
--- lib/patch.c
+++ lib/patch.c
@@ -269,7 +269,7 @@ copy(FILE *tmp, FILE *orig, off_t copypos, off_t pos)
}
static const struct got_error *
-locate_hunk(FILE *orig, struct got_patch_hunk *h, long *lineno)
+locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, long *lineno)
{
const struct got_error *err = NULL;
char *line = NULL;
@@ -307,6 +307,7 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, long
}
if (err == NULL) {
+ *pos = match;
*lineno = match_lineno;
if (fseek(orig, match, SEEK_SET) == -1)
err = got_error_from_errno("fseek");
@@ -452,13 +453,9 @@ apply_patch(struct got_worktree *worktree, struct got_
copypos = 0;
STAILQ_FOREACH(h, &p->head, entries) {
tryagain:
- err = locate_hunk(orig, h, &lineno);
+ err = locate_hunk(orig, h, &pos, &lineno);
if (err != NULL)
goto done;
- if ((pos = ftello(orig)) == -1) {
- err = got_error_from_errno("ftello");
- goto done;
- }
err = copy(tmp, orig, copypos, pos);
if (err != NULL)
goto done;
two small fixes for got patch