commit - dea26038f390e6141c544ce678baaa0b69043d9e
commit + 72254787333eeb9d226c5341bbfee1b48c1c0f30
blob - 8e431b84cef0e76870b8054c4318dfac9bc02177
blob + 845c023388414d92a90603c95d5cc8f070cdf23b
--- lib/diff.c
+++ lib/diff.c
goto done;
} else {
idstr1 = "/dev/null";
+ f1_created = 1;
+ f1 = got_opentemp();
+ if (f1 == NULL) {
+ err = got_error_from_errno("got_opentemp");
+ goto done;
+ }
}
- err = got_diff_prepare_file(&f1, &p1, &f1_created, &size,
- data1, cfg, ignore_whitespace);
+ err = got_diff_prepare_file(f1, &p1, &size, data1, cfg,
+ ignore_whitespace);
if (err)
goto done;
blob - e28256d18d0db2487bd4309cedd59f285ca9af44
blob + f986eb1b1518f1d74f60a7bf8f8fbedaec2e678f
--- lib/diffreg.c
+++ lib/diffreg.c
}
const struct got_error *
-got_diff_prepare_file(FILE **f, char **p, int *f_created, size_t *size,
+got_diff_prepare_file(FILE *f, char **p, size_t *size,
struct diff_data *diff_data, const struct diff_config *cfg,
int ignore_whitespace)
{
if (ignore_whitespace)
diff_flags |= DIFF_FLAG_IGNORE_WHITESPACE;
- if (f && *f) {
- if (fstat(fileno(*f), &st) == -1) {
- err = got_error_from_errno("fstat");
- goto done;
- }
- #ifndef GOT_DIFF_NO_MMAP
- *p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE,
- fileno(*f), 0);
- if (*p == MAP_FAILED)
- #endif
- *p = NULL; /* fall back on file I/O */
- } else {
- *f_created = 1;
- st.st_size = 0;
- *f = got_opentemp();
- if (*f == NULL) {
- err = got_error_from_errno("got_opentemp");
- goto done;
- }
+ if (fstat(fileno(f), &st) == -1) {
+ err = got_error_from_errno("fstat");
+ goto done;
}
+#ifndef GOT_DIFF_NO_MMAP
+ *p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE,
+ fileno(f), 0);
+ if (*p == MAP_FAILED)
+#endif
+ *p = NULL; /* fall back on file I/O */
- rc = diff_atomize_file(diff_data, cfg, *f, *p, st.st_size, diff_flags);
+ rc = diff_atomize_file(diff_data, cfg, f, *p, st.st_size, diff_flags);
if (rc) {
err = got_error_set_errno(rc, "diff_atomize_file");
goto done;
left = &d_left;
right = &d_right;
}
-
+
cfg = got_diff_get_config(algorithm);
if (cfg == NULL) {
err = got_error(GOT_ERR_NOT_IMPL);
goto done;
}
- err = got_diff_prepare_file(&f1, &p1, &f1_created, &size1,
- left, cfg, ignore_whitespace);
+ if (f1 == NULL) {
+ f1_created = 1;
+ f1 = got_opentemp();
+ if (f1 == NULL) {
+ err = got_error_from_errno("got_opentemp");
+ goto done;
+ }
+ }
+ if (f2 == NULL) {
+ f2_created = 1;
+ f2 = got_opentemp();
+ if (f2 == NULL) {
+ err = got_error_from_errno("got_opentemp");
+ goto done;
+ }
+ }
+
+ err = got_diff_prepare_file(f1, &p1, &size1, left, cfg,
+ ignore_whitespace);
if (err)
goto done;
- err = got_diff_prepare_file(&f2, &p2, &f2_created, &size2,
- right, cfg, ignore_whitespace);
+ err = got_diff_prepare_file(f2, &p2, &size2, right, cfg,
+ ignore_whitespace);
if (err)
goto done;
blob - 6a883974dd0e6fdff376ed0855b7599ddec46936
blob + f78de6a872b9a4f3b8c187da196913eea1817653
--- lib/got_lib_diff.h
+++ lib/got_lib_diff.h
#define GOT_DIFF_CONFLICT_MARKER_END ">>>>>>>"
const struct diff_config *got_diff_get_config(enum got_diff_algorithm);
-const struct got_error *got_diff_prepare_file(FILE **, char **, int *,
- size_t *, struct diff_data *, const struct diff_config *, int);
+const struct got_error *got_diff_prepare_file(FILE *, char **, size_t *,
+ struct diff_data *, const struct diff_config *, int);
const struct got_error *got_diffreg_prepared_files(struct got_diffreg_result **,
const struct diff_config *, struct diff_data *, FILE *, char *, size_t,
struct diff_data *, FILE *, char *, size_t);