commit - 19e4b90712e9a185c4562e0563aa5a34dc6f549c
commit + 4ce46740492b52299407d11c2571029be8ad295e
blob - c140d3621c853710a48a9125b23fc43d77e61798
blob + 79ade469edb490ca280a4a6535c55aae69bee2cd
--- got/got.c
+++ got/got.c
const struct got_error *err = NULL;
struct got_blob_object *blob1 = NULL;
FILE *f2 = NULL;
- char *abspath = NULL;
+ char *abspath = NULL, *label1 = NULL;
struct stat sb;
if (a->diff_staged) {
}
if (staged_status == GOT_STATUS_ADD ||
- staged_status == GOT_STATUS_MODIFY)
+ staged_status == GOT_STATUS_MODIFY) {
+ char *id_str;
err = got_object_open_as_blob(&blob1, a->repo, staged_blob_id,
8192);
- else if (status != GOT_STATUS_ADD)
+ if (err)
+ goto done;
+ err = got_object_id_str(&id_str, staged_blob_id);
+ if (err)
+ goto done;
+ if (asprintf(&label1, "%s (staged)", id_str) == -1) {
+ err = got_error_from_errno("asprintf");
+ free(id_str);
+ goto done;
+ }
+ free(id_str);
+ } else if (status != GOT_STATUS_ADD) {
err = got_object_open_as_blob(&blob1, a->repo, blob_id, 8192);
- if (err)
- goto done;
+ if (err)
+ goto done;
+ }
if (status != GOT_STATUS_DELETE) {
if (asprintf(&abspath, "%s/%s",
} else
sb.st_size = 0;
- err = got_diff_blob_file(blob1, f2, sb.st_size, path, a->diff_context,
- stdout);
+ err = got_diff_blob_file(blob1, label1, f2, sb.st_size, path,
+ a->diff_context, stdout);
done:
if (blob1)
got_object_blob_close(blob1);
blob - 0d86e3c0ca9aac48559bab6118c9bcac82470866
blob + 927863bea9c15cfb8336083f49201f2c717f2c89
--- include/got_diff.h
+++ include/got_diff.h
* Compute the differences between a blob and a file and write unified diff
* text to the provided output file. The file's size must be provided, as
* well as a const char * diff header label which identifies the file.
+ * An optional const char * diff header label for the blob may be provided, too.
* The number of context lines to show in the diff must be specified as well.
*/
-const struct got_error *got_diff_blob_file(struct got_blob_object *, FILE *,
- size_t, const char *, int, FILE *);
+const struct got_error *got_diff_blob_file(struct got_blob_object *,
+ const char *, FILE *, size_t, const char *, int, FILE *);
/*
* A callback function invoked to handle the differences between two blobs
blob - 6b7e4d457bb9821c3ae3352917a57558486181b0
blob + 6d6f3dec0067739174d0bd9beae75cd22a7d7fe9
--- lib/diff.c
+++ lib/diff.c
static const struct got_error *
diff_blob_file(struct got_diff_changes **changes,
- struct got_blob_object *blob1, FILE *f2, size_t size2,
+ struct got_blob_object *blob1, const char *label1, FILE *f2, size_t size2,
const char *label2, int diff_context, FILE *outfile)
{
struct got_diff_state ds;
flags |= D_PROTOTYPE;
if (outfile) {
- fprintf(outfile, "blob - %s\n", idstr1);
+ fprintf(outfile, "blob - %s\n", label1 ? label1 : idstr1);
fprintf(outfile, "file + %s\n",
f2 == NULL ? "/dev/null" : label2);
}
}
const struct got_error *
-got_diff_blob_file(struct got_blob_object *blob1, FILE *f2, size_t size2,
- const char *label2, int diff_context, FILE *outfile)
+got_diff_blob_file(struct got_blob_object *blob1, const char *label1,
+ FILE *f2, size_t size2, const char *label2, int diff_context,
+ FILE *outfile)
{
- return diff_blob_file(NULL, blob1, f2, size2, label2, diff_context,
- outfile);
+ return diff_blob_file(NULL, blob1, label1, f2, size2, label2,
+ diff_context, outfile);
}
const struct got_error *
blob - f743dbf50f1eccc4c81a1a1f4775856cce86fa07
blob + 9ef34a4c6457e4c828e91308a00f248632f7ef1d
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
echo -n 'blob - ' >> $testroot/stdout.expected
- (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
+ (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
>> $testroot/stdout.expected
+ echo ' (staged)' >> $testroot/stdout.expected
echo 'file + alpha' >> $testroot/stdout.expected
echo '--- alpha' >> $testroot/stdout.expected
echo '+++ alpha' >> $testroot/stdout.expected
echo '-modified file' >> $testroot/stdout.expected
echo '+modified file again' >> $testroot/stdout.expected
echo -n 'blob - ' >> $testroot/stdout.expected
- (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
+ (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
>> $testroot/stdout.expected
+ echo " (staged)" >> $testroot/stdout.expected
echo 'file + foo' >> $testroot/stdout.expected
echo '--- foo' >> $testroot/stdout.expected
echo '+++ foo' >> $testroot/stdout.expected
blob - 07c730e3c86b7e3438b0a1816df6c880fc5644fd
blob + 9c6d712c170e967cce17f30f21f7152824868767
--- regress/cmdline/unstage.sh
+++ regress/cmdline/unstage.sh
(cd $testroot/wt && got diff > $testroot/stdout)
echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
echo -n 'blob - ' >> $testroot/stdout.expected
- (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
- >> $testroot/stdout.expected
+ (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
+ tr -d '\n' >> $testroot/stdout.expected
+ echo " (staged)" >> $testroot/stdout.expected
echo "file + numbers" >> $testroot/stdout.expected
cat >> $testroot/stdout.expected <<EOF
--- numbers
(cd $testroot/wt && got diff > $testroot/stdout)
echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
echo -n 'blob - ' >> $testroot/stdout.expected
- (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
- >> $testroot/stdout.expected
+ (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
+ tr -d '\n' >> $testroot/stdout.expected
+ echo " (staged)" >> $testroot/stdout.expected
echo "file + numbers" >> $testroot/stdout.expected
cat >> $testroot/stdout.expected <<EOF
--- numbers
echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
echo -n 'blob - ' >> $testroot/stdout.expected
- (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
- >> $testroot/stdout.expected
+ (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
+ tr -d '\n' >> $testroot/stdout.expected
+ echo " (staged)" >> $testroot/stdout.expected
echo "file + numbers" >> $testroot/stdout.expected
echo "--- numbers" >> $testroot/stdout.expected
echo "+++ numbers" >> $testroot/stdout.expected