speed up rebase and histedit path prefix check: skip blob content diffs
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
diff --git a/got/got.c b/got/got.c
index 0d710de..753ca96 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1273,7 +1273,7 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
arg.diff_context = diff_context;
arg.outfile = stdout;
err = got_diff_tree(tree1, tree2, "", "", repo,
- got_diff_blob_output_unidiff, &arg);
+ got_diff_blob_output_unidiff, &arg, 1);
done:
if (tree1)
got_object_tree_close(tree1);
@@ -3738,7 +3738,7 @@ check_path_prefix(struct got_object_id *parent_id,
cpp_arg.len = strlen(cpp_arg.path_prefix);
cpp_arg.errcode = errcode;
err = got_diff_tree(tree1, tree2, "", "", repo,
- check_path_prefix_in_diff, &cpp_arg);
+ check_path_prefix_in_diff, &cpp_arg, 0);
done:
if (tree1)
got_object_tree_close(tree1);
diff --git a/include/got_diff.h b/include/got_diff.h
index 8ab2399..0d86e3c 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -64,10 +64,13 @@ const struct got_error *got_diff_blob_output_unidiff(void *,
/*
* Compute the differences between two trees and invoke the provided
* got_diff_blob_cb() callback when content differs.
+ * Diffing of blob content can be suppressed by passing zero for the
+ * 'diff_content' parameter. The callback will then only receive blob
+ * object IDs and diff labels, but NULL pointers instead of blob objects.
*/
const struct got_error *got_diff_tree(struct got_tree_object *,
struct got_tree_object *, const char *, const char *,
- struct got_repository *, got_diff_blob_cb cb, void *cb_arg);
+ struct got_repository *, got_diff_blob_cb cb, void *cb_arg, int);
/*
* Diff two objects, assuming both objects are blobs. Two const char * diff
diff --git a/lib/diff.c b/lib/diff.c
index 241a941..d572937 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -325,7 +325,8 @@ done:
static const struct got_error *
diff_added_tree(struct got_object_id *id, const char *label,
- struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
+ struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
+ int diff_content)
{
const struct got_error *err = NULL;
struct got_object *treeobj = NULL;
@@ -344,7 +345,8 @@ diff_added_tree(struct got_object_id *id, const char *label,
if (err)
goto done;
- err = got_diff_tree(NULL, tree, NULL, label, repo, cb, cb_arg);
+ err = got_diff_tree(NULL, tree, NULL, label, repo, cb, cb_arg,
+ diff_content);
done:
if (tree)
got_object_tree_close(tree);
@@ -356,7 +358,7 @@ done:
static const struct got_error *
diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
const char *label1, const char *label2, struct got_repository *repo,
- got_diff_blob_cb cb, void *cb_arg)
+ got_diff_blob_cb cb, void *cb_arg, int diff_content)
{
const struct got_error *err;
struct got_object *treeobj1 = NULL;
@@ -390,7 +392,8 @@ diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
if (err)
goto done;
- err = got_diff_tree(tree1, tree2, label1, label2, repo, cb, cb_arg);
+ err = got_diff_tree(tree1, tree2, label1, label2, repo, cb, cb_arg,
+ diff_content);
done:
if (tree1)
@@ -406,7 +409,8 @@ done:
static const struct got_error *
diff_deleted_tree(struct got_object_id *id, const char *label,
- struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
+ struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
+ int diff_content)
{
const struct got_error *err;
struct got_object *treeobj = NULL;
@@ -425,7 +429,8 @@ diff_deleted_tree(struct got_object_id *id, const char *label,
if (err)
goto done;
- err = got_diff_tree(tree, NULL, label, NULL, repo, cb, cb_arg);
+ err = got_diff_tree(tree, NULL, label, NULL, repo, cb, cb_arg,
+ diff_content);
done:
if (tree)
got_object_tree_close(tree);
@@ -446,7 +451,8 @@ diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
static const struct got_error *
diff_entry_old_new(const struct got_tree_entry *te1,
const struct got_tree_entry *te2, const char *label1, const char *label2,
- struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
+ struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
+ int diff_content)
{
const struct got_error *err = NULL;
int id_match;
@@ -454,10 +460,15 @@ diff_entry_old_new(const struct got_tree_entry *te1,
if (te2 == NULL) {
if (S_ISDIR(te1->mode))
err = diff_deleted_tree(te1->id, label1, repo,
- cb, cb_arg);
- else
- err = diff_deleted_blob(te1->id, label1, repo,
- cb, cb_arg);
+ cb, cb_arg, diff_content);
+ else {
+ if (diff_content)
+ err = diff_deleted_blob(te1->id, label1, repo,
+ cb, cb_arg);
+ else
+ err = cb(cb_arg, NULL, NULL, te1->id, NULL,
+ label1, NULL, repo);
+ }
return err;
}
@@ -465,11 +476,16 @@ diff_entry_old_new(const struct got_tree_entry *te1,
if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
if (!id_match)
return diff_modified_tree(te1->id, te2->id,
- label1, label2, repo, cb, cb_arg);
+ label1, label2, repo, cb, cb_arg, diff_content);
} else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
- if (!id_match)
- return diff_modified_blob(te1->id, te2->id,
- label1, label2, repo, cb, cb_arg);
+ if (!id_match) {
+ if (diff_content)
+ return diff_modified_blob(te1->id, te2->id,
+ label1, label2, repo, cb, cb_arg);
+ else
+ return cb(cb_arg, NULL, NULL, te1->id,
+ te2->id, label1, label2, repo);
+ }
}
if (id_match)
@@ -482,21 +498,26 @@ diff_entry_old_new(const struct got_tree_entry *te1,
static const struct got_error *
diff_entry_new_old(const struct got_tree_entry *te2,
const struct got_tree_entry *te1, const char *label2,
- struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg)
+ struct got_repository *repo, got_diff_blob_cb cb, void *cb_arg,
+ int diff_content)
{
if (te1 != NULL) /* handled by diff_entry_old_new() */
return NULL;
if (S_ISDIR(te2->mode))
- return diff_added_tree(te2->id, label2, repo, cb, cb_arg);
+ return diff_added_tree(te2->id, label2, repo, cb, cb_arg,
+ diff_content);
- return diff_added_blob(te2->id, label2, repo, cb, cb_arg);
+ if (diff_content)
+ return diff_added_blob(te2->id, label2, repo, cb, cb_arg);
+
+ return cb(cb_arg, NULL, NULL, NULL, te2->id, NULL, label2, repo);
}
const struct got_error *
got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
const char *label1, const char *label2, struct got_repository *repo,
- got_diff_blob_cb cb, void *cb_arg)
+ got_diff_blob_cb cb, void *cb_arg, int diff_content)
{
const struct got_error *err = NULL;
struct got_tree_entry *te1 = NULL;
@@ -535,7 +556,7 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
got_error_from_errno("asprintf");
}
err = diff_entry_old_new(te1, te, l1, l2, repo, cb,
- cb_arg);
+ cb_arg, diff_content);
if (err)
break;
}
@@ -557,7 +578,8 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
return
got_error_from_errno("asprintf");
}
- err = diff_entry_new_old(te2, te, l2, repo, cb, cb_arg);
+ err = diff_entry_new_old(te2, te, l2, repo,
+ cb, cb_arg, diff_content);
if (err)
break;
}
@@ -641,7 +663,7 @@ got_diff_objects_as_trees(struct got_object_id *id1, struct got_object_id *id2,
arg.diff_context = diff_context;
arg.outfile = outfile;
err = got_diff_tree(tree1, tree2, label1, label2, repo,
- got_diff_blob_output_unidiff, &arg);
+ got_diff_blob_output_unidiff, &arg, 1);
done:
if (tree1)
got_object_tree_close(tree1);
diff --git a/lib/worktree.c b/lib/worktree.c
index 102a998..b40be45 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2112,7 +2112,7 @@ merge_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
arg.cancel_cb = cancel_cb;
arg.cancel_arg = cancel_arg;
arg.commit_id2 = commit_id2;
- err = got_diff_tree(tree1, tree2, "", "", repo, merge_file_cb, &arg);
+ err = got_diff_tree(tree1, tree2, "", "", repo, merge_file_cb, &arg, 1);
sync_err = sync_fileindex(fileindex, fileindex_path);
if (sync_err && err == NULL)
err = sync_err;
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index b6001e3..c195445 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -397,7 +397,7 @@ repo_diff_tree(const char *repo_path)
arg.diff_context = 3;
arg.outfile = outfile;
got_diff_tree(tree1, tree2, "", "", repo,
- got_diff_blob_output_unidiff, &arg);
+ got_diff_blob_output_unidiff, &arg, 1);
test_printf("\n");
got_object_tree_close(tree1);