refs/ref-cache.c: remove "mkdir" parameter from find_containing_dir()

Remove the "mkdir" parameter from the find_containing_dir() function, the add_ref_entry() function removed in the preceding commit was its last user. Since "mkdir" is always "0" we can also remove the parameter from search_for_subdir(), which in turn means that we can delete most of that function. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 28, 2021 at 15:02 UTC 5e4546d599abdd1f3bbff0eaef77fe9a0cfcc5c3
1 file changed +12 -24
refs/ref-cache.c
+12 -24
@@ -144,30 +144,19 @@ int search_ref_dir(struct ref_dir *dir, const char *refname, size_t len)
144 /*
145 * Search for a directory entry directly within dir (without
146 * recursing). Sort dir if necessary. subdirname must be a directory
147 - * name (i.e., end in '/'). If mkdir is set, then create the
148 - * directory if it is missing; otherwise, return NULL if the desired
147 + * name (i.e., end in '/'). Returns NULL if the desired
148 * directory cannot be found. dir must already be complete.
149 */
150 static struct ref_dir *search_for_subdir(struct ref_dir *dir,
152 - const char *subdirname, size_t len,
153 - int mkdir)
151 + const char *subdirname, size_t len)
152 {
153 int entry_index = search_ref_dir(dir, subdirname, len);
154 struct ref_entry *entry;
157 - if (entry_index == -1) {
158 - if (!mkdir)
159 - return NULL;
160 - /*
161 - * Since dir is complete, the absence of a subdir
162 - * means that the subdir really doesn't exist;
163 - * therefore, create an empty record for it but mark
164 - * the record complete.
165 - */
166 - entry = create_dir_entry(dir->cache, subdirname, len, 0);
167 - add_entry_to_dir(dir, entry);
168 - } else {
169 - entry = dir->entries[entry_index];
170 - }
155 +
156 + if (entry_index == -1)
157 + return NULL;
158 +
159 + entry = dir->entries[entry_index];
160 return get_ref_dir(entry);
161 }
162
@@ -176,18 +165,17 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
165 * tree that should hold refname. If refname is a directory name
166 * (i.e., it ends in '/'), then return that ref_dir itself. dir must
167 * represent the top-level directory and must already be complete.
179 - * Sort ref_dirs and recurse into subdirectories as necessary. If
180 - * mkdir is set, then create any missing directories; otherwise,
168 + * Sort ref_dirs and recurse into subdirectories as necessary. Will
169 * return NULL if the desired directory cannot be found.
170 */
171 static struct ref_dir *find_containing_dir(struct ref_dir *dir,
184 - const char *refname, int mkdir)
172 + const char *refname)
173 {
174 const char *slash;
175 for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
176 size_t dirnamelen = slash - refname + 1;
177 struct ref_dir *subdir;
190 - subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
178 + subdir = search_for_subdir(dir, refname, dirnamelen);
179 if (!subdir) {
180 dir = NULL;
181 break;
@@ -202,7 +190,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
190 {
191 int entry_index;
192 struct ref_entry *entry;
205 - dir = find_containing_dir(dir, refname, 0);
193 + dir = find_containing_dir(dir, refname);
194 if (!dir)
195 return NULL;
196 entry_index = search_ref_dir(dir, refname, strlen(refname));
@@ -478,7 +466,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
466
467 dir = get_ref_dir(cache->root);
468 if (prefix && *prefix)
481 - dir = find_containing_dir(dir, prefix, 0);
469 + dir = find_containing_dir(dir, prefix);
470 if (!dir)
471 /* There's nothing to iterate over. */
472 return empty_ref_iterator_begin();