commit 1cb46f007dad47a45d2c2d32aaeee11372f95309 from: Stefan Sperling date: Sat Nov 21 15:34:19 2020 UTC consistently label removed files as "/dev/null" in diff headers commit - c4cd9c5b87f894217b6aee09f12884f3db44aaf4 commit + 1cb46f007dad47a45d2c2d32aaeee11372f95309 blob - f48f80f88a4377e0ddd59fea3e98da4649a1d494 blob + a1db0dab0c21289d579451ec66a2883d5af498a6 --- lib/diff.c +++ lib/diff.c @@ -166,7 +166,8 @@ diff_blobs(off_t **line_offsets, size_t *nlines, goto done; if (outfile) { - err = got_diffreg_output(line_offsets, nlines, result, f1, f2, + err = got_diffreg_output(line_offsets, nlines, result, + blob1 != NULL, blob2 != NULL, label1 ? label1 : idstr1, label2 ? label2 : idstr2, GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile); @@ -255,9 +256,11 @@ diff_blob_file(struct got_diffreg_result **resultp, goto done; if (outfile) { - err = got_diffreg_output(NULL, NULL, result, f1, f2, - label2, label2, GOT_DIFF_OUTPUT_UNIDIFF, diff_context, - outfile); + err = got_diffreg_output(NULL, NULL, result, + blob1 != NULL, f2 != NULL, + label2, /* show local file's path, not a blob ID */ + label2, GOT_DIFF_OUTPUT_UNIDIFF, + diff_context, outfile); if (err) goto done; } @@ -862,8 +865,8 @@ got_diff_files(struct got_diffreg_result **resultp, if (outfile) { err = got_diffreg_output(NULL, NULL, diffreg_result, - f1, f2, label1, label2, GOT_DIFF_OUTPUT_UNIDIFF, - diff_context, outfile); + f1 != NULL, f2 != NULL, label1, label2, + GOT_DIFF_OUTPUT_UNIDIFF, diff_context, outfile); if (err) goto done; } blob - 7b8449a42173543736e1f5d0836bb64451ab832f blob + 0526cfdab94262bbc3d44a427af97d56d5deb7b8 --- lib/diff3.c +++ lib/diff3.c @@ -227,7 +227,7 @@ diffreg(BUF **d, const char *path1, const char *path2) if (err) goto done; - err = got_diffreg_output(NULL, NULL, diffreg_result, f1, f2, "", "", + err = got_diffreg_output(NULL, NULL, diffreg_result, 1, 1, "", "", GOT_DIFF_OUTPUT_EDSCRIPT, 0, outfile); if (err) goto done; blob - 8683b991a4378f8e61d26b25a83570f7cf3a3351 blob + 918b50bbce65306ade20a6e42612dd9e4ad88aac --- lib/diffreg.c +++ lib/diffreg.c @@ -278,16 +278,22 @@ done: const struct got_error * got_diffreg_output(off_t **line_offsets, size_t *nlines, - struct got_diffreg_result *diff_result, FILE *f1, FILE *f2, + struct got_diffreg_result *diff_result, int f1_exists, int f2_exists, const char *path1, const char *path2, enum got_diff_output_format output_format, int context_lines, FILE *outfile) { struct diff_input_info info = { .left_path = path1, .right_path = path2, + .flags = 0, }; int rc; struct diff_output_info *output_info; + + if (!f1_exists) + info.flags |= DIFF_INPUT_LEFT_NONEXISTENT; + if (!f2_exists) + info.flags |= DIFF_INPUT_RIGHT_NONEXISTENT; switch (output_format) { case GOT_DIFF_OUTPUT_UNIDIFF: blob - f3e58cc505cffa4e06ca6a0ec16396a3e5307747 blob + ae0e6d73bc7b11bc4dac33b1f7aca5cda1ce9071 --- lib/got_lib_diff.h +++ lib/got_lib_diff.h @@ -52,7 +52,7 @@ const struct got_error *got_diff_prepare_file(FILE *, const struct got_error *got_diffreg(struct got_diffreg_result **, FILE *, FILE *, enum got_diff_algorithm, int, int); const struct got_error *got_diffreg_output(off_t **, size_t *, - struct got_diffreg_result *, FILE *, FILE *, const char *, const char *, + struct got_diffreg_result *, int, int, const char *, const char *, enum got_diff_output_format, int, FILE *); const struct got_error *got_diffreg_result_free(struct got_diffreg_result *); const struct got_error *got_diffreg_result_free_left( blob - 92cd8f39cbdc7a59932a05599b57b808a8814472 blob + 883be7a1fb5bdd2de7ed9df74a676c22d4a2c869 --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -47,12 +47,12 @@ test_diff_basic() { >> $testroot/stdout.expected echo 'file + /dev/null' >> $testroot/stdout.expected echo '--- beta' >> $testroot/stdout.expected - echo '+++ beta' >> $testroot/stdout.expected + echo '+++ /dev/null' >> $testroot/stdout.expected echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected echo '-beta' >> $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + new' >> $testroot/stdout.expected - echo '--- new' >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected echo '+++ new' >> $testroot/stdout.expected echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected echo '+new file' >> $testroot/stdout.expected @@ -446,13 +446,13 @@ test_diff_symlinks_in_work_tree() { cut -d' ' -f 1 >> $testroot/stdout.expected echo 'file + /dev/null' >> $testroot/stdout.expected echo '--- nonexistent.link' >> $testroot/stdout.expected - echo '+++ nonexistent.link' >> $testroot/stdout.expected + echo '+++ /dev/null' >> $testroot/stdout.expected echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected echo '-nonexistent' >> $testroot/stdout.expected echo '\ No newline at end of file' >> $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + zeta.link' >> $testroot/stdout.expected - echo '--- zeta.link' >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected echo '+++ zeta.link' >> $testroot/stdout.expected echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected echo '+epsilon/zeta' >> $testroot/stdout.expected @@ -600,7 +600,8 @@ test_diff_binary_files() { echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + foo' >> $testroot/stdout.expected - echo "Binary files foo and foo differ" >> $testroot/stdout.expected + echo "Binary files /dev/null and foo differ" \ + >> $testroot/stdout.expected (cd $testroot/wt && got diff > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout @@ -614,7 +615,7 @@ test_diff_binary_files() { echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + foo' >> $testroot/stdout.expected - echo '--- foo' >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected echo '+++ foo' >> $testroot/stdout.expected echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected blob - 6b88ae02ec91ba9a708d70c67ddc62cdcfe66a03 blob + 053325225ecc1c55962ba876ee2610f161762fa3 --- regress/cmdline/unstage.sh +++ regress/cmdline/unstage.sh @@ -721,7 +721,7 @@ test_unstage_patch_added() { echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + epsilon/new' >> $testroot/stdout.expected - echo "--- epsilon/new" >> $testroot/stdout.expected + echo "--- /dev/null" >> $testroot/stdout.expected echo "+++ epsilon/new" >> $testroot/stdout.expected echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected echo "+new" >> $testroot/stdout.expected @@ -791,7 +791,7 @@ test_unstage_patch_removed() { >> $testroot/stdout.expected echo 'file + /dev/null' >> $testroot/stdout.expected echo "--- beta" >> $testroot/stdout.expected - echo "+++ beta" >> $testroot/stdout.expected + echo "+++ /dev/null" >> $testroot/stdout.expected echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected echo "-beta" >> $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout blob - 01cca03963ab7106310fd5a83a41dcce92cfe2d2 blob + 543f12cdcea65ac0fd3cc061ea7e25cac98e6d08 --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -1016,7 +1016,7 @@ test_update_conflict_wt_rm_vs_repo_edit() { >> $testroot/stdout.expected echo 'file + /dev/null' >> $testroot/stdout.expected echo '--- beta' >> $testroot/stdout.expected - echo '+++ beta' >> $testroot/stdout.expected + echo '+++ /dev/null' >> $testroot/stdout.expected echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected echo '-modified beta' >> $testroot/stdout.expected