make 'got diff' not show a diff header if work tree has no mods
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
diff --git a/got/got.c b/got/got.c
index a2d01e1..3825153 100644
--- a/got/got.c
+++ b/got/got.c
@@ -950,6 +950,8 @@ struct print_diff_arg {
struct got_repository *repo;
struct got_worktree *worktree;
int diff_context;
+ const char *id_str;
+ int header_shown;
};
static const struct got_error *
@@ -966,6 +968,12 @@ print_diff(void *arg, unsigned char status, const char *path,
if (status != GOT_STATUS_MODIFY)
return NULL;
+ if (!a->header_shown) {
+ printf("diff %s %s\n", a->id_str,
+ got_worktree_get_root_path(a->worktree));
+ a->header_shown = 1;
+ }
+
err = got_object_open_as_blob(&blob1, a->repo, id, 8192);
if (err)
goto done;
@@ -1084,9 +1092,9 @@ cmd_diff(int argc, char *argv[])
arg.repo = repo;
arg.worktree = worktree;
arg.diff_context = diff_context;
+ arg.id_str = id_str;
+ arg.header_shown = 0;
- printf("diff %s %s\n", id_str,
- got_worktree_get_root_path(worktree));
error = got_worktree_status(worktree, repo, print_diff,
&arg, check_cancelled, NULL);
free(id_str);