From: Reuben Hawkins <reubenhwk@gmail.com>
To: git@vger.kernel.org
Cc: dpotapov@gmail.com, Reuben Hawkins <reubenhwk@gmail.com>
Subject: [PATCH 2/2] init-db.c: factor out probe_case_sensitivity func
Date: Sat, 1 Feb 2014 03:14:27 -0600 [thread overview]
Message-ID: <1391246067-30499-2-git-send-email-reubenhwk@gmail.com> (raw)
In-Reply-To: <1391246067-30499-1-git-send-email-reubenhwk@gmail.com>
create_default_files was getting a bit long and indented. This
particular bit of code got long enough to be its own function.
Signed-off-by: Reuben Hawkins <reubenhwk@gmail.com>
---
builtin/init-db.c | 97 +++++++++++++++++++++++++++++------------------------
1 file changed, 53 insertions(+), 44 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 34f09d8..bcf7f4c 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -177,6 +177,58 @@ static int git_init_db_config(const char *k, const char *v, void *cb)
return 0;
}
+static void probe_case_sensitivity(char *path, size_t len)
+{
+ int completely_insensitive_fs = 1;
+ char const * const case_check_filename = ".CaseCheck";
+ struct dirent *dirent;
+ FILE *case_file;
+ DIR *dir;
+
+ /*
+ * If we can't access "config" by the name "CoNfIg", this fs is
+ * case sensitive...so do nothing and return.
+ */
+ path[len] = 0;
+ strcpy(path + len, "CoNfIg");
+ if (access(path, F_OK))
+ return;
+
+ /*
+ * This filesystem is at least partially case-insensitive. Let's
+ * find out if this filesystem is completely case-insensitive.
+ *
+ * Create a CamelCase file here, make sure readdir reads a
+ * CamelCase file below.
+ */
+ path[len] = 0;
+ strcpy(path + len, case_check_filename);
+ case_file = fopen(path, "w");
+ if (!case_file)
+ die_errno(_("cannot open '%s'"), path);
+ fclose(case_file);
+
+ path[len] = 0;
+ dir = opendir(path);
+ if (!dir)
+ die_errno(_("cannot opendir '%s'"), path);
+
+ while ( (dirent = readdir(dir)) ) {
+ if (0 == strcmp(case_check_filename, dirent->d_name)) {
+ completely_insensitive_fs = 0;
+ break;
+ }
+ }
+
+ closedir(dir);
+ path[len] = 0;
+ strcpy(path + len, case_check_filename);
+ unlink(path);
+
+ if (completely_insensitive_fs)
+ git_config_set("core.ignorecase", "true");
+}
+
static int create_default_files(const char *template_path)
{
const char *git_dir = get_git_dir();
@@ -285,50 +337,7 @@ static int create_default_files(const char *template_path)
else
git_config_set("core.symlinks", "false");
- /* Check if the filesystem is case-insensitive */
- path[len] = 0;
- strcpy(path + len, "CoNfIg");
- if (!access(path, F_OK)) {
- /*
- * This filesystem is at least partially case-insensitive. Let's
- * find out if this filesystem is completely case-insensitive.
- *
- * Create a CamelCase file here, make sure readdir reads a
- * CamelCase file below.
- */
- int completely_insensitive_fs = 1;
- char const * const case_check_filename = ".CaseCheck";
- struct dirent *dirent;
- FILE *case_file;
- DIR *dir;
-
- path[len] = 0;
- strcpy(path + len, case_check_filename);
- case_file = fopen(path, "w");
- if (!case_file)
- die_errno(_("cannot open '%s'"), path);
- fclose(case_file);
-
- path[len] = 0;
- dir = opendir(path);
- if (!dir)
- die_errno(_("cannot opendir '%s'"), path);
-
- while ( (dirent = readdir(dir)) ) {
- if (0 == strcmp(case_check_filename, dirent->d_name)) {
- completely_insensitive_fs = 0;
- break;
- }
- }
-
- closedir(dir);
- path[len] = 0;
- strcpy(path + len, case_check_filename);
- unlink(path);
-
- if (completely_insensitive_fs)
- git_config_set("core.ignorecase", "true");
- }
+ probe_case_sensitivity(path, len);
probe_utf8_pathname_composition(path, len);
}
--
1.7.9.5
next prev parent reply other threads:[~2014-02-01 9:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-01 9:14 [PATCH 1/2] init-db.c: honor case on case preserving fs Reuben Hawkins
2014-02-01 9:14 ` Reuben Hawkins [this message]
2014-02-01 12:17 ` Torsten Bögershausen
[not found] ` <CAD_8n+RWNZkGO31XveDuSy2aXv5uAMy087AUUu2+wXtO=MngAg@mail.gmail.com>
2014-02-01 23:47 ` Dmitry Potapov
2014-02-02 18:08 ` Junio C Hamano
[not found] ` <CAHkcotg3McjrnQ_rLi4YpLAauMQT6U0kjEp1eu+6jxbuRY5zrA@mail.gmail.com>
[not found] ` <CAD_8n+TQ4i2Z5zePXCTqpdF8mpRrzzKjDUB-NxZ1PJAwek-y1w@mail.gmail.com>
2014-02-02 5:46 ` Dmitry Potapov
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=1391246067-30499-2-git-send-email-reubenhwk@gmail.com \
--to=reubenhwk@gmail.com \
--cc=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
/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).