Skip to content

Commit 870de59

Browse files
committed
Merge branch 'ab/retire-refs-unused-funcs'
Code cleanup. * ab/retire-refs-unused-funcs: refs/ref-cache.[ch]: remove "incomplete" from create_dir_entry() refs/ref-cache.c: remove "mkdir" parameter from find_containing_dir() refs/ref-cache.[ch]: remove unused add_ref_entry() refs/ref-cache.[ch]: remove unused remove_entry_from_dir() refs.[ch]: remove unused ref_storage_backend_exists()
2 parents d3347c4 + 750036c commit 870de59

File tree

5 files changed

+19
-107
lines changed

5 files changed

+19
-107
lines changed

refs.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ static struct ref_storage_be *find_ref_storage_backend(const char *name)
3333
return NULL;
3434
}
3535

36-
int ref_storage_backend_exists(const char *name)
37-
{
38-
return find_ref_storage_backend(name) != NULL;
39-
}
40-
4136
/*
4237
* How to handle various characters in refnames:
4338
* 0: An acceptable character for refs

refs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,6 @@ int reflog_expire(const char *refname,
835835
reflog_expiry_cleanup_fn cleanup_fn,
836836
void *policy_cb_data);
837837

838-
int ref_storage_backend_exists(const char *name);
839-
840838
struct ref_store *get_main_ref_store(struct repository *r);
841839

842840
/**

refs/files-backend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static void add_per_worktree_entries_to_dir(struct ref_dir *dir, const char *dir
227227
pos = search_ref_dir(dir, prefix, prefix_len);
228228
if (pos >= 0)
229229
continue;
230-
child_entry = create_dir_entry(dir->cache, prefix, prefix_len, 1);
230+
child_entry = create_dir_entry(dir->cache, prefix, prefix_len);
231231
add_entry_to_dir(dir, child_entry);
232232
}
233233
}
@@ -278,7 +278,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
278278
strbuf_addch(&refname, '/');
279279
add_entry_to_dir(dir,
280280
create_dir_entry(dir->cache, refname.buf,
281-
refname.len, 1));
281+
refname.len));
282282
} else {
283283
if (!refs_resolve_ref_unsafe(&refs->base,
284284
refname.buf,
@@ -336,7 +336,7 @@ static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
336336
* lazily):
337337
*/
338338
add_entry_to_dir(get_ref_dir(refs->loose->root),
339-
create_dir_entry(refs->loose, "refs/", 5, 1));
339+
create_dir_entry(refs->loose, "refs/", 5));
340340
}
341341
return refs->loose;
342342
}

refs/ref-cache.c

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct ref_cache *create_ref_cache(struct ref_store *refs,
4949

5050
ret->ref_store = refs;
5151
ret->fill_ref_dir = fill_ref_dir;
52-
ret->root = create_dir_entry(ret, "", 0, 1);
52+
ret->root = create_dir_entry(ret, "", 0);
5353
return ret;
5454
}
5555

@@ -86,14 +86,13 @@ static void clear_ref_dir(struct ref_dir *dir)
8686
}
8787

8888
struct ref_entry *create_dir_entry(struct ref_cache *cache,
89-
const char *dirname, size_t len,
90-
int incomplete)
89+
const char *dirname, size_t len)
9190
{
9291
struct ref_entry *direntry;
9392

9493
FLEX_ALLOC_MEM(direntry, name, dirname, len);
9594
direntry->u.subdir.cache = cache;
96-
direntry->flag = REF_DIR | (incomplete ? REF_INCOMPLETE : 0);
95+
direntry->flag = REF_DIR | REF_INCOMPLETE;
9796
return direntry;
9897
}
9998

@@ -144,30 +143,19 @@ int search_ref_dir(struct ref_dir *dir, const char *refname, size_t len)
144143
/*
145144
* Search for a directory entry directly within dir (without
146145
* 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
146+
* name (i.e., end in '/'). Returns NULL if the desired
149147
* directory cannot be found. dir must already be complete.
150148
*/
151149
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
152-
const char *subdirname, size_t len,
153-
int mkdir)
150+
const char *subdirname, size_t len)
154151
{
155152
int entry_index = search_ref_dir(dir, subdirname, len);
156153
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-
}
154+
155+
if (entry_index == -1)
156+
return NULL;
157+
158+
entry = dir->entries[entry_index];
171159
return get_ref_dir(entry);
172160
}
173161

@@ -176,18 +164,17 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
176164
* tree that should hold refname. If refname is a directory name
177165
* (i.e., it ends in '/'), then return that ref_dir itself. dir must
178166
* 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,
167+
* Sort ref_dirs and recurse into subdirectories as necessary. Will
181168
* return NULL if the desired directory cannot be found.
182169
*/
183170
static struct ref_dir *find_containing_dir(struct ref_dir *dir,
184-
const char *refname, int mkdir)
171+
const char *refname)
185172
{
186173
const char *slash;
187174
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
188175
size_t dirnamelen = slash - refname + 1;
189176
struct ref_dir *subdir;
190-
subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
177+
subdir = search_for_subdir(dir, refname, dirnamelen);
191178
if (!subdir) {
192179
dir = NULL;
193180
break;
@@ -202,7 +189,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
202189
{
203190
int entry_index;
204191
struct ref_entry *entry;
205-
dir = find_containing_dir(dir, refname, 0);
192+
dir = find_containing_dir(dir, refname);
206193
if (!dir)
207194
return NULL;
208195
entry_index = search_ref_dir(dir, refname, strlen(refname));
@@ -212,50 +199,6 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
212199
return (entry->flag & REF_DIR) ? NULL : entry;
213200
}
214201

215-
int remove_entry_from_dir(struct ref_dir *dir, const char *refname)
216-
{
217-
int refname_len = strlen(refname);
218-
int entry_index;
219-
struct ref_entry *entry;
220-
int is_dir = refname[refname_len - 1] == '/';
221-
if (is_dir) {
222-
/*
223-
* refname represents a reference directory. Remove
224-
* the trailing slash; otherwise we will get the
225-
* directory *representing* refname rather than the
226-
* one *containing* it.
227-
*/
228-
char *dirname = xmemdupz(refname, refname_len - 1);
229-
dir = find_containing_dir(dir, dirname, 0);
230-
free(dirname);
231-
} else {
232-
dir = find_containing_dir(dir, refname, 0);
233-
}
234-
if (!dir)
235-
return -1;
236-
entry_index = search_ref_dir(dir, refname, refname_len);
237-
if (entry_index == -1)
238-
return -1;
239-
entry = dir->entries[entry_index];
240-
241-
MOVE_ARRAY(&dir->entries[entry_index],
242-
&dir->entries[entry_index + 1], dir->nr - entry_index - 1);
243-
dir->nr--;
244-
if (dir->sorted > entry_index)
245-
dir->sorted--;
246-
free_ref_entry(entry);
247-
return dir->nr;
248-
}
249-
250-
int add_ref_entry(struct ref_dir *dir, struct ref_entry *ref)
251-
{
252-
dir = find_containing_dir(dir, ref->name, 1);
253-
if (!dir)
254-
return -1;
255-
add_entry_to_dir(dir, ref);
256-
return 0;
257-
}
258-
259202
/*
260203
* Emit a warning and return true iff ref1 and ref2 have the same name
261204
* and the same oid. Die if they have the same name but different
@@ -522,7 +465,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
522465

523466
dir = get_ref_dir(cache->root);
524467
if (prefix && *prefix)
525-
dir = find_containing_dir(dir, prefix, 0);
468+
dir = find_containing_dir(dir, prefix);
526469
if (!dir)
527470
/* There's nothing to iterate over. */
528471
return empty_ref_iterator_begin();

refs/ref-cache.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry);
169169
* "refs/heads/") or "" for the top-level directory.
170170
*/
171171
struct ref_entry *create_dir_entry(struct ref_cache *cache,
172-
const char *dirname, size_t len,
173-
int incomplete);
172+
const char *dirname, size_t len);
174173

175174
struct ref_entry *create_ref_entry(const char *refname,
176175
const struct object_id *oid, int flag);
@@ -199,29 +198,6 @@ void free_ref_cache(struct ref_cache *cache);
199198
*/
200199
void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry);
201200

202-
/*
203-
* Remove the entry with the given name from dir, recursing into
204-
* subdirectories as necessary. If refname is the name of a directory
205-
* (i.e., ends with '/'), then remove the directory and its contents.
206-
* If the removal was successful, return the number of entries
207-
* remaining in the directory entry that contained the deleted entry.
208-
* If the name was not found, return -1. Please note that this
209-
* function only deletes the entry from the cache; it does not delete
210-
* it from the filesystem or ensure that other cache entries (which
211-
* might be symbolic references to the removed entry) are updated.
212-
* Nor does it remove any containing dir entries that might be made
213-
* empty by the removal. dir must represent the top-level directory
214-
* and must already be complete.
215-
*/
216-
int remove_entry_from_dir(struct ref_dir *dir, const char *refname);
217-
218-
/*
219-
* Add a ref_entry to the ref_dir (unsorted), recursing into
220-
* subdirectories as necessary. dir must represent the top-level
221-
* directory. Return 0 on success.
222-
*/
223-
int add_ref_entry(struct ref_dir *dir, struct ref_entry *ref);
224-
225201
/*
226202
* Find the value entry with the given name in dir, sorting ref_dirs
227203
* and recursing into subdirectories as necessary. If the name is not

0 commit comments

Comments
 (0)