| @@ -298,12 +297,14 @@ int cache_tree_fully_valid(struct index_state *istate) |
|
298
|
297
|
|
istate->cache_tree); |
|
299
|
298
|
|
} |
|
300
|
299
|
|
|
|
301
|
|
- |
static int must_check_existence(const struct cache_entry *ce) |
|
|
300
|
+ |
static int must_check_existence(const struct cache_entry *ce, void *cb_data) |
|
302
|
301
|
|
{ |
|
303
|
|
- |
return !(repo_has_promisor_remote(the_repository) && ce_skip_worktree(ce)); |
|
|
302
|
+ |
struct repository *repo = cb_data; |
|
|
303
|
+ |
return !(repo_has_promisor_remote(repo) && ce_skip_worktree(ce)); |
|
304
|
304
|
|
} |
|
305
|
305
|
|
|
|
306
|
|
- |
static int update_one(struct cache_tree *it, |
|
|
306
|
+ |
static int update_one(struct repository *repo, |
|
|
307
|
+ |
struct cache_tree *it, |
|
307
|
308
|
|
struct cache_entry **cache, |
|
308
|
309
|
|
int entries, |
|
309
|
310
|
|
const char *base, |
| @@ -382,7 +383,8 @@ static int update_one(struct cache_tree *it, |
|
382
|
383
|
|
sub = find_subtree(it, path + baselen, sublen, 1); |
|
383
|
384
|
|
if (!sub->cache_tree) |
|
384
|
385
|
|
sub->cache_tree = cache_tree(); |
|
385
|
|
- |
subcnt = update_one(sub->cache_tree, |
|
|
386
|
+ |
subcnt = update_one(repo, |
|
|
387
|
+ |
sub->cache_tree, |
|
386
|
388
|
|
cache + i, entries - i, |
|
387
|
389
|
|
path, |
|
388
|
390
|
|
baselen + sublen + 1, |
| @@ -446,10 +448,10 @@ static int update_one(struct cache_tree *it, |
|
446
|
448
|
|
} |
|
447
|
449
|
|
|
|
448
|
450
|
|
ce_missing_ok = mode == S_IFGITLINK || missing_ok || |
|
449
|
|
- |
!must_check_existence(ce); |
|
|
451
|
+ |
!must_check_existence(ce, repo); |
|
450
|
452
|
|
if (is_null_oid(oid) || |
|
451
|
453
|
|
(!ce_missing_ok && |
|
452
|
|
- |
!odb_has_object(the_repository->objects, oid, |
|
|
454
|
+ |
!odb_has_object(repo->objects, oid, |
|
453
|
455
|
|
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))) { |
|
454
|
456
|
|
strbuf_release(&buffer); |
|
455
|
457
|
|
if (expected_missing) |
| @@ -481,12 +483,12 @@ static int update_one(struct cache_tree *it, |
|
481
|
483
|
|
/* |
|
482
|
484
|
|
* "sub" can be an empty tree if all subentries are i-t-a. |
|
483
|
485
|
|
*/ |
|
484
|
|
- |
if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo)) |
|
|
486
|
+ |
if (contains_ita && is_empty_tree_oid(oid, repo->hash_algo)) |
|
485
|
487
|
|
continue; |
|
486
|
488
|
|
|
|
487
|
489
|
|
strbuf_grow(&buffer, entlen + 100); |
|
488
|
490
|
|
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0'); |
|
489
|
|
- |
strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz); |
|
|
491
|
+ |
strbuf_add(&buffer, oid->hash, repo->hash_algo->rawsz); |
|
490
|
492
|
|
|
|
491
|
493
|
|
#if DEBUG_CACHE_TREE |
|
492
|
494
|
|
fprintf(stderr, "cache-tree update-one %o %.*s\n", |
| @@ -496,16 +498,16 @@ static int update_one(struct cache_tree *it, |
|
496
|
498
|
|
|
|
497
|
499
|
|
if (repair) { |
|
498
|
500
|
|
struct object_id oid; |
|
499
|
|
- |
hash_object_file(the_hash_algo, buffer.buf, buffer.len, |
|
|
501
|
+ |
hash_object_file(repo->hash_algo, buffer.buf, buffer.len, |
|
500
|
502
|
|
OBJ_TREE, &oid); |
|
501
|
|
- |
if (odb_has_object(the_repository->objects, &oid, ODB_HAS_OBJECT_RECHECK_PACKED)) |
|
|
503
|
+ |
if (odb_has_object(repo->objects, &oid, ODB_HAS_OBJECT_RECHECK_PACKED)) |
|
502
|
504
|
|
oidcpy(&it->oid, &oid); |
|
503
|
505
|
|
else |
|
504
|
506
|
|
to_invalidate = 1; |
|
505
|
507
|
|
} else if (dryrun) { |
|
506
|
|
- |
hash_object_file(the_hash_algo, buffer.buf, buffer.len, |
|
|
508
|
+ |
hash_object_file(repo->hash_algo, buffer.buf, buffer.len, |
|
507
|
509
|
|
OBJ_TREE, &it->oid); |
|
508
|
|
- |
} else if (odb_write_object_ext(the_repository->objects, buffer.buf, buffer.len, OBJ_TREE, |
|
|
510
|
+ |
} else if (odb_write_object_ext(repo->objects, buffer.buf, buffer.len, OBJ_TREE, |
|
509
|
511
|
|
&it->oid, NULL, flags & WRITE_TREE_SILENT ? ODB_WRITE_OBJECT_SILENT : 0)) { |
|
510
|
512
|
|
strbuf_release(&buffer); |
|
511
|
513
|
|
return -1; |
| @@ -535,14 +537,14 @@ int cache_tree_update(struct index_state *istate, int flags) |
|
535
|
537
|
|
if (!istate->cache_tree) |
|
536
|
538
|
|
istate->cache_tree = cache_tree(); |
|
537
|
539
|
|
|
|
538
|
|
- |
if (!(flags & WRITE_TREE_MISSING_OK) && repo_has_promisor_remote(the_repository)) |
|
539
|
|
- |
prefetch_cache_entries(istate, must_check_existence); |
|
|
540
|
+ |
if (!(flags & WRITE_TREE_MISSING_OK) && repo_has_promisor_remote(istate->repo)) |
|
|
541
|
+ |
prefetch_cache_entries(istate, must_check_existence, istate->repo); |
|
540
|
542
|
|
|
|
541
|
543
|
|
trace_performance_enter(); |
|
542
|
544
|
|
trace2_region_enter("cache_tree", "update", istate->repo); |
|
543
|
545
|
|
if (!inflight) |
|
544
|
|
- |
odb_transaction_begin_or_die(the_repository->objects, &transaction, 0); |
|
545
|
|
- |
i = update_one(istate->cache_tree, istate->cache, istate->cache_nr, |
|
|
546
|
+ |
odb_transaction_begin_or_die(istate->repo->objects, &transaction, 0); |
|
|
547
|
+ |
i = update_one(istate->repo, istate->cache_tree, istate->cache, istate->cache_nr, |
|
546
|
548
|
|
"", 0, &skip, flags); |
|
547
|
549
|
|
if (!inflight) |
|
548
|
550
|
|
odb_transaction_commit_and_finalize_or_die(transaction); |
| @@ -554,7 +556,8 @@ int cache_tree_update(struct index_state *istate, int flags) |
|
554
|
556
|
|
return 0; |
|
555
|
557
|
|
} |
|
556
|
558
|
|
|
|
557
|
|
- |
static void write_one(struct strbuf *buffer, struct cache_tree *it, |
|
|
559
|
+ |
static void write_one(struct repository *repo, |
|
|
560
|
+ |
struct strbuf *buffer, struct cache_tree *it, |
|
558
|
561
|
|
const char *path, int pathlen) |
|
559
|
562
|
|
{ |
|
560
|
563
|
|
int i; |
| @@ -580,7 +583,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it, |
|
580
|
583
|
|
#endif |
|
581
|
584
|
|
|
|
582
|
585
|
|
if (0 <= it->entry_count) { |
|
583
|
|
- |
strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz); |
|
|
586
|
+ |
strbuf_add(buffer, it->oid.hash, repo->hash_algo->rawsz); |
|
584
|
587
|
|
} |
|
585
|
588
|
|
for (i = 0; i < it->subtree_nr; i++) { |
|
586
|
589
|
|
struct cache_tree_sub *down = it->down[i]; |
| @@ -590,15 +593,16 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it, |
|
590
|
593
|
|
prev->name, prev->namelen) <= 0) |
|
591
|
594
|
|
die("fatal - unsorted cache subtree"); |
|
592
|
595
|
|
} |
|
593
|
|
- |
write_one(buffer, down->cache_tree, down->name, down->namelen); |
|
|
596
|
+ |
write_one(repo, buffer, down->cache_tree, down->name, down->namelen); |
|
594
|
597
|
|
} |
|
595
|
598
|
|
} |
|
596
|
599
|
|
|
|
597
|
|
- |
void cache_tree_write(struct strbuf *sb, struct cache_tree *root) |
|
|
600
|
+ |
void cache_tree_write(struct repository *repo, |
|
|
601
|
+ |
struct strbuf *sb, struct cache_tree *root) |
|
598
|
602
|
|
{ |
|
599
|
|
- |
trace2_region_enter("cache_tree", "write", the_repository); |
|
600
|
|
- |
write_one(sb, root, "", 0); |
|
601
|
|
- |
trace2_region_leave("cache_tree", "write", the_repository); |
|
|
603
|
+ |
trace2_region_enter("cache_tree", "write", repo); |
|
|
604
|
+ |
write_one(repo, sb, root, "", 0); |
|
|
605
|
+ |
trace2_region_leave("cache_tree", "write", repo); |
|
602
|
606
|
|
} |
|
603
|
607
|
|
|
|
604
|
608
|
|
static int parse_int(const char **ptr, unsigned long *len_p, int *out) |
| @@ -632,13 +636,14 @@ static int parse_int(const char **ptr, unsigned long *len_p, int *out) |
|
632
|
636
|
|
return 0; |
|
633
|
637
|
|
} |
|
634
|
638
|
|
|
|
635
|
|
- |
static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) |
|
|
639
|
+ |
static struct cache_tree *read_one(struct repository *repo, |
|
|
640
|
+ |
const char **buffer, unsigned long *size_p) |
|
636
|
641
|
|
{ |
|
637
|
642
|
|
const char *buf = *buffer; |
|
638
|
643
|
|
unsigned long size = *size_p; |
|
639
|
644
|
|
struct cache_tree *it; |
|
640
|
645
|
|
int i, subtree_nr; |
|
641
|
|
- |
const unsigned rawsz = the_hash_algo->rawsz; |
|
|
646
|
+ |
const unsigned rawsz = repo->hash_algo->rawsz; |
|
642
|
647
|
|
|
|
643
|
648
|
|
it = NULL; |
|
644
|
649
|
|
/* skip name, but make sure name exists */ |
| @@ -710,16 +715,17 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) |
|
710
|
715
|
|
return NULL; |
|
711
|
716
|
|
} |
|
712
|
717
|
|
|
|
713
|
|
- |
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size) |
|
|
718
|
+ |
struct cache_tree *cache_tree_read(struct repository *repo, |
|
|
719
|
+ |
const char *buffer, unsigned long size) |
|
714
|
720
|
|
{ |
|
715
|
721
|
|
struct cache_tree *result; |
|
716
|
722
|
|
|
|
717
|
723
|
|
if (buffer[0]) |
|
718
|
724
|
|
return NULL; /* not the whole tree */ |
|
719
|
725
|
|
|
|
720
|
|
- |
trace2_region_enter("cache_tree", "read", the_repository); |
|
721
|
|
- |
result = read_one(&buffer, &size); |
|
722
|
|
- |
trace2_region_leave("cache_tree", "read", the_repository); |
|
|
726
|
+ |
trace2_region_enter("cache_tree", "read", repo); |
|
|
727
|
+ |
result = read_one(repo, &buffer, &size); |
|
|
728
|
+ |
trace2_region_leave("cache_tree", "read", repo); |
|
723
|
729
|
|
|
|
724
|
730
|
|
return result; |
|
725
|
731
|
|
} |
| @@ -810,7 +816,7 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, |
|
810
|
816
|
|
hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); |
|
811
|
817
|
|
|
|
812
|
818
|
|
entries = read_index_from(index_state, index_path, |
|
813
|
|
- |
repo_get_git_dir(the_repository)); |
|
|
819
|
+ |
repo_get_git_dir(index_state->repo)); |
|
814
|
820
|
|
if (entries < 0) { |
|
815
|
821
|
|
ret = WRITE_TREE_UNREADABLE_INDEX; |
|
816
|
822
|
|
goto out; |
| @@ -866,7 +872,7 @@ static void prime_cache_tree_rec(struct repository *r, |
|
866
|
872
|
|
struct cache_tree_sub *sub; |
|
867
|
873
|
|
struct tree *subtree = lookup_tree(r, &entry.oid); |
|
868
|
874
|
|
|
|
869
|
|
- |
if (repo_parse_tree(the_repository, subtree) < 0) |
|
|
875
|
+ |
if (repo_parse_tree(r, subtree) < 0) |
|
870
|
876
|
|
exit(128); |
|
871
|
877
|
|
sub = cache_tree_sub(it, entry.path); |
|
872
|
878
|
|
sub->cache_tree = cache_tree(); |