From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Han-Wen Nienhuys" <hanwen@google.com>,
"Michael Haggerty" <mhagger@alum.mit.edu>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 4/5] refs/ref-cache.c: remove "mkdir" parameter from find_containing_dir()
Date: Tue, 28 Sep 2021 15:02:23 +0200 [thread overview]
Message-ID: <patch-4.5-a6f9c19f658-20210928T130032Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.5-00000000000-20210928T130032Z-avarab@gmail.com>
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>
---
refs/ref-cache.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index a28883768c9..73b338f5ff2 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -144,30 +144,19 @@ int search_ref_dir(struct ref_dir *dir, const char *refname, size_t len)
/*
* Search for a directory entry directly within dir (without
* recursing). Sort dir if necessary. subdirname must be a directory
- * name (i.e., end in '/'). If mkdir is set, then create the
- * directory if it is missing; otherwise, return NULL if the desired
+ * name (i.e., end in '/'). Returns NULL if the desired
* directory cannot be found. dir must already be complete.
*/
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
- const char *subdirname, size_t len,
- int mkdir)
+ const char *subdirname, size_t len)
{
int entry_index = search_ref_dir(dir, subdirname, len);
struct ref_entry *entry;
- if (entry_index == -1) {
- if (!mkdir)
- return NULL;
- /*
- * Since dir is complete, the absence of a subdir
- * means that the subdir really doesn't exist;
- * therefore, create an empty record for it but mark
- * the record complete.
- */
- entry = create_dir_entry(dir->cache, subdirname, len, 0);
- add_entry_to_dir(dir, entry);
- } else {
- entry = dir->entries[entry_index];
- }
+
+ if (entry_index == -1)
+ return NULL;
+
+ entry = dir->entries[entry_index];
return get_ref_dir(entry);
}
@@ -176,18 +165,17 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
* tree that should hold refname. If refname is a directory name
* (i.e., it ends in '/'), then return that ref_dir itself. dir must
* represent the top-level directory and must already be complete.
- * Sort ref_dirs and recurse into subdirectories as necessary. If
- * mkdir is set, then create any missing directories; otherwise,
+ * Sort ref_dirs and recurse into subdirectories as necessary. Will
* return NULL if the desired directory cannot be found.
*/
static struct ref_dir *find_containing_dir(struct ref_dir *dir,
- const char *refname, int mkdir)
+ const char *refname)
{
const char *slash;
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
size_t dirnamelen = slash - refname + 1;
struct ref_dir *subdir;
- subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
+ subdir = search_for_subdir(dir, refname, dirnamelen);
if (!subdir) {
dir = NULL;
break;
@@ -202,7 +190,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
{
int entry_index;
struct ref_entry *entry;
- dir = find_containing_dir(dir, refname, 0);
+ dir = find_containing_dir(dir, refname);
if (!dir)
return NULL;
entry_index = search_ref_dir(dir, refname, strlen(refname));
@@ -478,7 +466,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
dir = get_ref_dir(cache->root);
if (prefix && *prefix)
- dir = find_containing_dir(dir, prefix, 0);
+ dir = find_containing_dir(dir, prefix);
if (!dir)
/* There's nothing to iterate over. */
return empty_ref_iterator_begin();
--
2.33.0.1340.ge9f77250f2b
next prev parent reply other threads:[~2021-09-28 13:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-28 13:02 [PATCH 0/5] refs: remove long-dead code Ævar Arnfjörð Bjarmason
2021-09-28 13:02 ` [PATCH 1/5] refs.[ch]: remove unused ref_storage_backend_exists() Ævar Arnfjörð Bjarmason
2021-09-28 13:02 ` [PATCH 2/5] refs/ref-cache.[ch]: remove unused remove_entry_from_dir() Ævar Arnfjörð Bjarmason
2021-09-28 13:02 ` [PATCH 3/5] refs/ref-cache.[ch]: remove unused add_ref_entry() Ævar Arnfjörð Bjarmason
2021-09-28 13:02 ` Ævar Arnfjörð Bjarmason [this message]
2021-09-28 13:02 ` [PATCH 5/5] refs/ref-cache.[ch]: remove "incomplete" from create_dir_entry() Ævar Arnfjörð Bjarmason
2021-09-28 17:58 ` [PATCH 0/5] refs: remove long-dead code Jeff King
2021-09-28 22:12 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-4.5-a6f9c19f658-20210928T130032Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hanwen@google.com \
--cc=mhagger@alum.mit.edu \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).