tree: Kill the `git_tree_diff` functions These are deprecated and replaced with the diffing code in git2/diff.h
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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
diff --git a/include/git2/tree.h b/include/git2/tree.h
index f75cc1c..3a91505 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -313,40 +313,6 @@ enum git_treewalk_mode {
*/
GIT_EXTERN(int) git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload);
-typedef enum {
- GIT_STATUS_ADDED = 1,
- GIT_STATUS_DELETED = 2,
- GIT_STATUS_MODIFIED = 3,
-} git_status_t;
-
-typedef struct {
- unsigned int old_attr;
- unsigned int new_attr;
- git_oid old_oid;
- git_oid new_oid;
- git_status_t status;
- const char *path;
-} git_tree_diff_data;
-
-typedef int (*git_tree_diff_cb)(const git_tree_diff_data *ptr, void *data);
-
-/**
- * Diff two trees
- *
- * Compare two trees. For each difference in the trees, the callback
- * will be called with a git_tree_diff_data filled with the relevant
- * information.
- *
- * @param old the "old" tree
- * @param newer the "newer" tree
- * @param cb callback
- * @param data data to give to the callback
- * @return GIT_SUCCESS or an error code
- */
-GIT_EXTERN(int) git_tree_diff(git_tree *old, git_tree *newer, git_tree_diff_cb cb, void *data);
-
-GIT_EXTERN(int) git_tree_diff_index_recursive(git_tree *tree, git_index *index, git_tree_diff_cb cb, void *data);
-
/** @} */
GIT_END_DECL
diff --git a/src/tree.c b/src/tree.c
index adbf974..b749481 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -780,273 +780,3 @@ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payl
return error;
}
-static int tree_entry_cmp(const git_tree_entry *a, const git_tree_entry *b)
-{
- int ret;
-
- ret = a->attr - b->attr;
- if (ret != 0)
- return ret;
-
- return git_oid_cmp(&a->oid, &b->oid);
-}
-
-static void mark_del(git_tree_diff_data *diff, git_tree_entry *entry)
-{
- diff->old_attr = entry->attr;
- git_oid_cpy(&diff->old_oid, &entry->oid);
- diff->path = entry->filename;
- diff->status |= GIT_STATUS_DELETED;
-}
-
-static void mark_add(git_tree_diff_data *diff, git_tree_entry *entry)
-{
- diff->new_attr = entry->attr;
- git_oid_cpy(&diff->new_oid, &entry->oid);
- diff->path = entry->filename;
- diff->status |= GIT_STATUS_ADDED;
-}
-
-static int signal_additions(git_tree *tree, int start, int end, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
- git_tree_entry *entry;
- int i;
-
- if (end < 0)
- end = git_tree_entrycount(tree);
-
- for (i = start; i < end; ++i) {
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
- entry = git_vector_get(&tree->entries, i);
- mark_add(&diff, entry);
-
- if (cb(&diff, data) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static int signal_addition(git_tree_entry *entry, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_add(&diff, entry);
-
- return cb(&diff, data);
-}
-
-static int signal_deletions(git_tree *tree, int start, int end, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
- git_tree_entry *entry;
- int i;
-
- if (end < 0)
- end = git_tree_entrycount(tree);
-
- for (i = start; i < end; ++i) {
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
- entry = git_vector_get(&tree->entries, i);
- mark_del(&diff, entry);
-
- if (cb(&diff, data) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static int signal_deletion(git_tree_entry *entry, git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_del(&diff, entry);
-
- return cb(&diff, data);
-}
-
-static int signal_modification(git_tree_entry *a, git_tree_entry *b,
- git_tree_diff_cb cb, void *data)
-{
- git_tree_diff_data diff;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- mark_del(&diff, a);
- mark_add(&diff, b);
-
- return cb(&diff, data);
-}
-
-int git_tree_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
-{
- unsigned int i_a = 0, i_b = 0; /* Counters for trees a and b */
- git_tree_entry *entry_a = NULL, *entry_b = NULL;
- git_tree_diff_data diff;
- int cmp;
-
- while (1) {
- entry_a = a == NULL ? NULL : git_vector_get(&a->entries, i_a);
- entry_b = b == NULL ? NULL : git_vector_get(&b->entries, i_b);
-
- if (!entry_a && !entry_b)
- return 0;
-
- memset(&diff, 0x0, sizeof(git_tree_diff_data));
-
- /*
- * We've run out of tree on one side so the rest of the
- * entries on the tree with remaining entries are all
- * deletions or additions.
- */
- if (entry_a && !entry_b)
- return signal_deletions(a, i_a, -1, cb, data);
- if (!entry_a && entry_b)
- return signal_additions(b, i_b, -1, cb, data);
-
- /*
- * Both trees are sorted with git's almost-alphabetical
- * sorting, so a comparison value < 0 means the entry was
- * deleted in the right tree. > 0 means the entry was added.
- */
- cmp = entry_sort_cmp(entry_a, entry_b);
-
- if (cmp == 0) {
- i_a++;
- i_b++;
-
- /* If everything's the same, jump to next pair */
- if (!tree_entry_cmp(entry_a, entry_b))
- continue;
-
- /* If they're not both dirs or both files, it's add + del */
- if (S_ISDIR(entry_a->attr) != S_ISDIR(entry_b->attr)) {
- if (signal_addition(entry_a, cb, data) < 0)
- return -1;
- if (signal_deletion(entry_b, cb, data) < 0)
- return -1;
- }
-
- /* Otherwise consider it a modification */
- if (signal_modification(entry_a, entry_b, cb, data) < 0)
- return -1;
-
- } else if (cmp < 0) {
- i_a++;
- if (signal_deletion(entry_a, cb, data) < 0)
- return -1;
- } else if (cmp > 0) {
- i_b++;
- if (signal_addition(entry_b, cb, data) < 0)
- return -1;
- }
- }
-
- return 0;
-}
-
-struct diff_index_cbdata {
- git_index *index;
- unsigned int i;
- git_tree_diff_cb cb;
- void *data;
-};
-
-static int cmp_tentry_ientry(git_tree_entry *tentry, git_index_entry *ientry)
-{
- int cmp;
-
- cmp = tentry->attr - ientry->mode;
- if (cmp != 0)
- return cmp;
-
- return git_oid_cmp(&tentry->oid, &ientry->oid);
-}
-
-static void make_tentry(git_tree_entry *tentry, git_index_entry *ientry)
-{
- char *last_slash;
-
- memset(tentry, 0x0, sizeof(git_tree_entry));
- tentry->attr = ientry->mode;
-
- last_slash = strrchr(ientry->path, '/');
- if (last_slash)
- last_slash++;
- else
- last_slash = ientry->path;
- tentry->filename = last_slash;
-
- git_oid_cpy(&tentry->oid, &ientry->oid);
- tentry->filename_len = strlen(tentry->filename);
-}
-
-static int diff_index_cb(const char *root, git_tree_entry *tentry, void *data)
-{
- struct diff_index_cbdata *cbdata = (struct diff_index_cbdata *) data;
- git_index_entry *ientry = git_index_get(cbdata->index, cbdata->i);
- git_tree_entry fake_entry;
- git_buf fn_buf = GIT_BUF_INIT;
- int cmp;
-
- if (entry_is_tree(tentry))
- return 0;
-
- if (!ientry)
- return signal_deletion(tentry, cbdata->cb, cbdata->data);
-
- git_buf_puts(&fn_buf, root);
- git_buf_puts(&fn_buf, tentry->filename);
-
- /* Like with 'git diff-index', the index is the right side*/
- cmp = strcmp(git_buf_cstr(&fn_buf), ientry->path);
- git_buf_free(&fn_buf);
- if (cmp == 0) {
- cbdata->i++;
- if (!cmp_tentry_ientry(tentry, ientry))
- return 0;
- /* modification */
- make_tentry(&fake_entry, ientry);
- if (signal_modification(tentry, &fake_entry, cbdata->cb, cbdata->data) < 0)
- return -1;
- } else if (cmp < 0) {
- /* deletion */
- memcpy(&fake_entry, tentry, sizeof(git_tree_entry));
- if (signal_deletion(tentry, cbdata->cb, cbdata->data) < 0)
- return -1;
- } else {
- /* addition */
- cbdata->i++;
- make_tentry(&fake_entry, ientry);
- if (signal_addition(&fake_entry, cbdata->cb, cbdata->data) < 0)
- return -1;
- /*
- * The index has an addition. This means that we need to use
- * the next entry in the index without advancing the tree
- * walker, so call ourselves with the same tree state.
- */
- if (diff_index_cb(root, tentry, data) < 0)
- return -1;;
- }
-
- return 0;
-}
-
-int git_tree_diff_index_recursive(git_tree *tree, git_index *index, git_tree_diff_cb cb, void *data)
-{
- struct diff_index_cbdata cbdata;
- git_buf dummy_path = GIT_BUF_INIT;
-
- cbdata.index = index;
- cbdata.i = 0;
- cbdata.cb = cb;
- cbdata.data = data;
-
- return tree_walk_post(tree, diff_index_cb, &dummy_path, &cbdata);
-}
diff --git a/tests-clar/object/tree/diff.c b/tests-clar/object/tree/diff.c
deleted file mode 100644
index 631fc3b..0000000
--- a/tests-clar/object/tree/diff.c
+++ /dev/null
@@ -1,168 +0,0 @@
-#include "clar_libgit2.h"
-#include "tree.h"
-#include "repository.h"
-
-static git_repository *repo;
-static git_index *theindex;
-static git_tree *atree, *btree;
-static git_oid aoid, boid;
-
-static void diff_cmp(const git_tree_diff_data *a, const git_tree_diff_data *b)
-{
- cl_assert(a->old_attr - b->old_attr == 0);
-
- cl_assert(a->new_attr - b->new_attr == 0);
-
- cl_assert(git_oid_cmp(&a->old_oid, &b->old_oid) == 0);
- cl_assert(git_oid_cmp(&a->new_oid, &b->new_oid) == 0);
-
- cl_assert(a->status - b->status == 0);
-
- cl_assert_equal_s(a->path, b->path);
-}
-
-static int diff_cb(const git_tree_diff_data *diff, void *data)
-{
- diff_cmp(diff, data);
- return 0;
-}
-
-static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
-{
- cl_must_pass(git_tree_diff(a, b, cb, data));
-
- cl_git_pass(git_index_read_tree(theindex, b));
- cl_git_pass(git_tree_diff_index_recursive(a, theindex, cb, data));
-}
-
-void test_object_tree_diff__initialize(void)
-{
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_repository_index(&theindex, repo));
-}
-
-void test_object_tree_diff__cleanup(void)
-{
- git_tree_free(atree);
- git_tree_free(btree);
- git_index_free(theindex);
- git_repository_free(repo);
-}
-
-void test_object_tree_diff__addition(void)
-{
- char *astr = "181037049a54a1eb5fab404658a3a250b44335d7";
- char *bstr = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
- git_tree_diff_data expect;
-
- memset(&expect, 0x0, sizeof(git_tree_diff_data));
- expect.old_attr = 0;
- expect.new_attr = 0100644;
- git_oid_fromstr(&expect.new_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect.status = GIT_STATUS_ADDED;
- expect.path = "new.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-void test_object_tree_diff__deletion(void)
-{
- char *astr = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
- char *bstr = "181037049a54a1eb5fab404658a3a250b44335d7";
- git_tree_diff_data expect;
-
- memset(&expect, 0x0, sizeof(git_tree_diff_data));
- expect.old_attr = 0100644;
- expect.new_attr = 0;
- git_oid_fromstr(&expect.old_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect.status = GIT_STATUS_DELETED;
- expect.path = "new.txt";
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-void test_object_tree_diff__modification(void)
-{
- char *astr = "1810dff58d8a660512d4832e740f692884338ccd";
- char *bstr = "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162";
- git_tree_diff_data expect;
-
- expect.old_attr = 0100644;
- expect.new_attr = 0100644;
- git_oid_fromstr(&expect.old_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
- git_oid_fromstr(&expect.new_oid, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
- expect.status = GIT_STATUS_MODIFIED;
- expect.path = "branch_file.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_cb, &expect);
-}
-
-struct diff_more_data {
- git_tree_diff_data expect[3];
- int expect_idx;
-};
-
-static int diff_more_cb(const git_tree_diff_data *diff, void *data)
-{
- struct diff_more_data *more_data = data;
- diff_cmp(diff, &more_data->expect[more_data->expect_idx]);
-
- more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect);
-
- return 0;
-}
-
-void test_object_tree_diff__more(void)
-{
- char *astr = "814889a078c031f61ed08ab5fa863aea9314344d";
- char *bstr = "75057dd4114e74cca1d750d0aee1647c903cb60a";
- struct diff_more_data more_data;
- git_tree_diff_data *expect = more_data.expect;
-
- memset(&more_data, 0x0, sizeof(struct diff_more_data));
- /* M README */
- expect[0].old_attr = 0100644;
- expect[0].new_attr = 0100644;
- git_oid_fromstr(&expect[0].old_oid, "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
- git_oid_fromstr(&expect[0].new_oid, "1385f264afb75a56a5bec74243be9b367ba4ca08");
- expect[0].status = GIT_STATUS_MODIFIED;
- expect[0].path = "README";
- /* A branch_file.txt */
- expect[1].old_attr = 0;
- expect[1].new_attr = 0100644;
- git_oid_fromstr(&expect[1].new_oid, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
- expect[1].status = GIT_STATUS_ADDED;
- expect[1].path = "branch_file.txt";
- /* M new.txt */
- expect[2].old_attr = 0100644;
- expect[2].new_attr = 0100644;
- git_oid_fromstr(&expect[2].old_oid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
- git_oid_fromstr(&expect[2].new_oid, "fa49b077972391ad58037050f2a75f74e3671e92");
- expect[2].status = GIT_STATUS_MODIFIED;
- expect[2].path = "new.txt";
-
- cl_must_pass(git_oid_fromstr(&aoid, astr));
- cl_must_pass(git_oid_fromstr(&boid, bstr));
-
- cl_must_pass(git_tree_lookup(&atree, repo, &aoid));
- cl_must_pass(git_tree_lookup(&btree, repo, &boid));
-
- test_diff(atree, btree, diff_more_cb, &more_data);
-}