tree-walk.c: remove the_repo from get_tree_entry()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jun 27, 2019 at 16:28 UTC
50ddb089ff68dfe1e3d9bd9a108d9015c176f761
11 files changed
+38
-26
archive.c
+3
-1
@@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,
418
unsigned short mode;
419
int err;
420
421
- err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
421
+ err = get_tree_entry(ar_args->repo,
422
+ &tree->object.oid,
423
+ prefix, &tree_oid,
424
&mode);
425
if (err || !S_ISDIR(mode))
426
die(_("current working directory is untracked"));
blame.c
+2
-2
@@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,
101
struct object_id blob_oid;
102
unsigned short mode;
103
104
- if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
104
+ if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
105
oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
106
return;
107
}
@@ -532,7 +532,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
532
{
533
if (!is_null_oid(&origin->blob_oid))
534
return 0;
535
- if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
535
+ if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
536
goto error_out;
537
if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
538
goto error_out;
builtin/rm.c
+1
-1
@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)
179
* way as changed from the HEAD.
180
*/
181
if (no_head
182
- || get_tree_entry(head, name, &oid, &mode)
182
+ || get_tree_entry(the_repository, head, name, &oid, &mode)
183
|| ce->ce_mode != create_ce_mode(mode)
184
|| !oideq(&ce->oid, &oid))
185
staged_changes = 1;
builtin/update-index.c
+1
-1
@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
601
struct object_id oid;
602
struct cache_entry *ce;
603
604
- if (get_tree_entry(ent, path, &oid, &mode)) {
604
+ if (get_tree_entry(the_repository, ent, path, &oid, &mode)) {
605
if (which)
606
error("%s: not in %s branch.", path, which);
607
return NULL;
line-log.c
+4
-3
@@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)
496
return (struct commit *) commit;
497
}
498
499
-static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
499
+static void fill_blob_sha1(struct repository *r, struct commit *commit,
500
+ struct diff_filespec *spec)
501
{
502
unsigned short mode;
503
struct object_id oid;
504
504
- if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
505
+ if (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode))
506
die("There is no path %s in the commit", spec->path);
507
fill_filespec(spec, &oid, 1, mode);
508
@@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,
586
name_part);
587
588
spec = alloc_filespec(full_name);
588
- fill_blob_sha1(commit, spec);
589
+ fill_blob_sha1(r, commit, spec);
590
fill_line_ends(r, spec, &lines, &ends);
591
cb_data.spec = spec;
592
cb_data.lines = lines;
match-trees.c
+3
-3
@@ -290,7 +290,7 @@ void shift_tree(const struct object_id *hash1,
290
if (!*del_prefix)
291
return;
292
293
- if (get_tree_entry(hash2, del_prefix, shifted, &mode))
293
+ if (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))
294
die("cannot find path %s in tree %s",
295
del_prefix, oid_to_hex(hash2));
296
return;
@@ -317,12 +317,12 @@ void shift_tree_by(const struct object_id *hash1,
317
unsigned candidate = 0;
318
319
/* Can hash2 be a tree at shift_prefix in tree hash1? */
320
- if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
320
+ if (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&
321
S_ISDIR(mode1))
322
candidate |= 1;
323
324
/* Can hash1 be a tree at shift_prefix in tree hash2? */
325
- if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
325
+ if (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&
326
S_ISDIR(mode2))
327
candidate |= 2;
328
merge-recursive.c
+5
-3
@@ -475,7 +475,7 @@ static int get_tree_entry_if_blob(const struct object_id *tree,
475
{
476
int ret;
477
478
- ret = get_tree_entry(tree, path, &dfs->oid, &dfs->mode);
478
+ ret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);
479
if (S_ISDIR(dfs->mode)) {
480
oidcpy(&dfs->oid, &null_oid);
481
dfs->mode = 0;
@@ -1905,7 +1905,8 @@ static int tree_has_path(struct tree *tree, const char *path)
1905
struct object_id hashy;
1906
unsigned short mode_o;
1907
1908
- return !get_tree_entry(&tree->object.oid, path,
1908
+ return !get_tree_entry(the_repository,
1909
+ &tree->object.oid, path,
1910
&hashy, &mode_o);
1911
}
1912
@@ -2500,7 +2501,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
2501
* the various handle_rename_*() functions update the index
2502
* explicitly rather than relying on unpack_trees() to have done it.
2503
*/
2503
- get_tree_entry(&tree->object.oid,
2504
+ get_tree_entry(opt->repo,
2505
+ &tree->object.oid,
2506
pair->two->path,
2507
&re->dst_entry->stages[stage].oid,
2508
&re->dst_entry->stages[stage].mode);
notes.c
+1
-1
@@ -1015,7 +1015,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1015
return;
1016
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
1017
die("Cannot use notes ref %s", notes_ref);
1018
- if (get_tree_entry(&object_oid, "", &oid, &mode))
1018
+ if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
1019
die("Failed to read notes tree referenced by %s (%s)",
1020
notes_ref, oid_to_hex(&object_oid));
1021
sha1-name.c
+5
-4
@@ -1677,7 +1677,8 @@ int repo_get_oid_blob(struct repository *r,
1677
}
1678
1679
/* Must be called only when object_name:filename doesn't exist. */
1680
-static void diagnose_invalid_oid_path(const char *prefix,
1680
+static void diagnose_invalid_oid_path(struct repository *r,
1681
+ const char *prefix,
1682
const char *filename,
1683
const struct object_id *tree_oid,
1684
const char *object_name,
@@ -1695,7 +1696,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
1696
if (is_missing_file_error(errno)) {
1697
char *fullname = xstrfmt("%s%s", prefix, filename);
1698
1698
- if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {
1699
+ if (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) {
1700
die("Path '%s' exists, but not '%s'.\n"
1701
"Did you mean '%.*s:%s' aka '%.*s:./%s'?",
1702
fullname,
@@ -1902,10 +1903,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1903
filename, oid, &oc->symlink_path,
1904
&oc->mode);
1905
} else {
1905
- ret = get_tree_entry(&tree_oid, filename, oid,
1906
+ ret = get_tree_entry(repo, &tree_oid, filename, oid,
1907
&oc->mode);
1908
if (ret && only_to_die) {
1908
- diagnose_invalid_oid_path(prefix,
1909
+ diagnose_invalid_oid_path(repo, prefix,
1910
filename,
1911
&tree_oid,
1912
name, len);
tree-walk.c
+12
-6
@@ -502,7 +502,9 @@ struct dir_state {
502
struct object_id oid;
503
};
504
505
-static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode)
505
+static int find_tree_entry(struct repository *r, struct tree_desc *t,
506
+ const char *name, struct object_id *result,
507
+ unsigned short *mode)
508
{
509
int namelen = strlen(name);
510
while (t->size) {
@@ -532,19 +534,23 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
534
oidcpy(result, &oid);
535
return 0;
536
}
535
- return get_tree_entry(&oid, name + entrylen, result, mode);
537
+ return get_tree_entry(r, &oid, name + entrylen, result, mode);
538
}
539
return -1;
540
}
541
540
-int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned short *mode)
542
+int get_tree_entry(struct repository *r,
543
+ const struct object_id *tree_oid,
544
+ const char *name,
545
+ struct object_id *oid,
546
+ unsigned short *mode)
547
{
548
int retval;
549
void *tree;
550
unsigned long size;
551
struct object_id root;
552
547
- tree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root);
553
+ tree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);
554
if (!tree)
555
return -1;
556
@@ -559,7 +565,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
565
} else {
566
struct tree_desc t;
567
init_tree_desc(&t, tree, size);
562
- retval = find_tree_entry(&t, name, oid, mode);
568
+ retval = find_tree_entry(r, &t, name, oid, mode);
569
}
570
free(tree);
571
return retval;
@@ -681,7 +687,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c
687
}
688
689
/* Look up the first (or only) path component in the tree. */
684
- find_result = find_tree_entry(&t, namebuf.buf,
690
+ find_result = find_tree_entry(the_repository, &t, namebuf.buf,
691
¤t_tree_oid, mode);
692
if (find_result) {
693
goto done;
tree-walk.h
+1
-1
@@ -68,7 +68,7 @@ struct traverse_info {
68
int show_all_errors;
69
};
70
71
-int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned short *);
71
+int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *);
72
char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
73
void setup_traverse_info(struct traverse_info *info, const char *base);
74