cache,tree: move cmp_cache_name_compare from tree.[ch] to read-cache.c

Since cmp_cache_name_compare() was comparing cache_entry structs, it was associated with the cache rather than with trees. Move the function. As a side effect, we can make cache_name_stage_compare() static as well. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 22, 2023 at 20:17 UTC aabc5617cdfb29ccf98048b0d99cae2a811df51f
4 files changed +13 -13
cache.h
+1 -1
@@ -562,7 +562,7 @@ int base_name_compare(const char *name1, size_t len1, int mode1,
562 int df_name_compare(const char *name1, size_t len1, int mode1,
563 const char *name2, size_t len2, int mode2);
564 int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
565 -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
565 +int cmp_cache_name_compare(const void *a_, const void *b_);
566
567 /* add */
568 /*
read-cache.c
+12 -1
@@ -567,7 +567,8 @@ int name_compare(const char *name1, size_t len1, const char *name2, size_t len2)
567 return 0;
568 }
569
570 -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
570 +static int cache_name_stage_compare(const char *name1, int len1, int stage1,
571 + const char *name2, int len2, int stage2)
572 {
573 int cmp;
574
@@ -582,6 +583,16 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
583 return 0;
584 }
585
586 +int cmp_cache_name_compare(const void *a_, const void *b_)
587 +{
588 + const struct cache_entry *ce1, *ce2;
589 +
590 + ce1 = *((const struct cache_entry **)a_);
591 + ce2 = *((const struct cache_entry **)b_);
592 + return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1),
593 + ce2->name, ce2->ce_namelen, ce_stage(ce2));
594 +}
595 +
596 static int index_name_stage_pos(struct index_state *istate,
597 const char *name, int namelen,
598 int stage,
tree.c
-10
@@ -94,16 +94,6 @@ int read_tree(struct repository *r,
94 return ret;
95 }
96
97 -int cmp_cache_name_compare(const void *a_, const void *b_)
98 -{
99 - const struct cache_entry *ce1, *ce2;
100 -
101 - ce1 = *((const struct cache_entry **)a_);
102 - ce2 = *((const struct cache_entry **)b_);
103 - return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1),
104 - ce2->name, ce2->ce_namelen, ce_stage(ce2));
105 -}
106 -
97 struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
98 {
99 struct object *obj = lookup_object(r, oid);
tree.h
-1
@@ -29,7 +29,6 @@ void free_tree_buffer(struct tree *tree);
29 /* Parses and returns the tree in the given ent, chasing tags and commits. */
30 struct tree *parse_tree_indirect(const struct object_id *oid);
31
32 -int cmp_cache_name_compare(const void *a_, const void *b_);
32
33 #define READ_TREE_RECURSIVE 1
34 typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *);