consistently label removed files as "/dev/null" in diff headers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
diff --git a/lib/diff.c b/lib/diff.c
index f48f80f..a1db0da 100644
--- a/lib/diff.c
+++ b/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;
}
diff --git a/lib/diff3.c b/lib/diff3.c
index 7b8449a..0526cfd 100644
--- a/lib/diff3.c
+++ b/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;
diff --git a/lib/diffreg.c b/lib/diffreg.c
index 8683b99..918b50b 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -278,17 +278,23 @@ 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:
rc = diff_output_unidiff(
diff --git a/lib/got_lib_diff.h b/lib/got_lib_diff.h
index f3e58cc..ae0e6d7 100644
--- a/lib/got_lib_diff.h
+++ b/lib/got_lib_diff.h
@@ -52,7 +52,7 @@ const struct got_error *got_diff_prepare_file(FILE *, char **, size_t *,
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(
diff --git a/regress/cmdline/diff.sh b/regress/cmdline/diff.sh
index 92cd8f3..883be7a 100755
--- a/regress/cmdline/diff.sh
+++ b/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
diff --git a/regress/cmdline/unstage.sh b/regress/cmdline/unstage.sh
index 6b88ae0..0533252 100755
--- a/regress/cmdline/unstage.sh
+++ b/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
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 01cca03..543f12c 100755
--- a/regress/cmdline/update.sh
+++ b/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