From: "Erik Elfström" <erik.elfstrom@gmail.com>
To: git@vger.kernel.org
Cc: "Erik Elfström" <erik.elfstrom@gmail.com>
Subject: [PATCH v6 1/7] setup: add gentle version of is_git_directory
Date: Sun, 10 May 2015 22:00:35 +0200 [thread overview]
Message-ID: <1431288041-21077-2-git-send-email-erik.elfstrom@gmail.com> (raw)
In-Reply-To: <1431288041-21077-1-git-send-email-erik.elfstrom@gmail.com>
This is a prerequisite for implementing a gentle version of
read_gitfile.
Signed-off-by: Erik Elfström <erik.elfstrom@gmail.com>
---
cache.h | 4 ++++
setup.c | 44 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index b34447f..dd67695 100644
--- a/cache.h
+++ b/cache.h
@@ -431,7 +431,11 @@ extern int is_inside_git_dir(void);
extern char *git_work_tree_cfg;
extern int is_inside_work_tree(void);
extern const char *get_git_dir(void);
+
+#define IS_GIT_DIRECTORY_ERR_PATH_TOO_LONG 1
+extern int is_git_directory_gently(const char *path, int *return_err, struct strbuf *err_msg);
extern int is_git_directory(const char *path);
+
extern char *get_object_directory(void);
extern char *get_index_file(void);
extern char *get_graft_file(void);
diff --git a/setup.c b/setup.c
index 979b13f..62ee88c 100644
--- a/setup.c
+++ b/setup.c
@@ -224,6 +224,18 @@ void verify_non_filename(const char *prefix, const char *arg)
"'git <command> [<revision>...] -- [<file>...]'", arg);
}
+__attribute((format (printf,4,5)))
+static void set_error(int *return_err, struct strbuf *err_msg, int err,
+ const char *msg, ...)
+{
+ va_list params;
+ va_start(params, msg);
+ if (err_msg)
+ strbuf_vaddf(err_msg, msg, params);
+ va_end(params);
+ if (return_err)
+ *return_err = err;
+}
/*
* Test if it looks like we're at a git directory.
@@ -235,14 +247,28 @@ void verify_non_filename(const char *prefix, const char *arg)
* - either a HEAD symlink or a HEAD file that is formatted as
* a proper "ref:", or a regular file HEAD that has a properly
* formatted sha1 object name.
+ *
+ * In the event of an error, return_err will be set to an error code
+ * and err_msg will be set to an error message describing the error
+ * and 0 will be returned. If no error reporting is required, pass
+ * NULL for return_err and/or err_msg.
*/
-int is_git_directory(const char *suspect)
+int is_git_directory_gently(const char *suspect, int *return_err,
+ struct strbuf *err_msg)
{
char path[PATH_MAX];
size_t len = strlen(suspect);
- if (PATH_MAX <= len + strlen("/objects"))
- die("Too long path: %.*s", 60, suspect);
+ if (return_err)
+ *return_err = 0;
+
+ if (PATH_MAX <= len + strlen("/objects")) {
+ set_error(return_err, err_msg,
+ IS_GIT_DIRECTORY_ERR_PATH_TOO_LONG,
+ "Too long path: %.*s", 60, suspect);
+ return 0;
+ }
+
strcpy(path, suspect);
if (getenv(DB_ENVIRONMENT)) {
if (access(getenv(DB_ENVIRONMENT), X_OK))
@@ -265,6 +291,18 @@ int is_git_directory(const char *suspect)
return 1;
}
+int is_git_directory(const char *suspect)
+{
+ int err;
+ int ret;
+ struct strbuf err_msg = STRBUF_INIT;
+ ret = is_git_directory_gently(suspect, &err, &err_msg);
+ if (err)
+ die("%s", err_msg.buf);
+ /* No need to free err_msg, will only be touched in case of error */
+ return ret;
+}
+
int is_inside_git_dir(void)
{
if (inside_git_dir < 0)
--
2.4.0.60.gf7143f7
next prev parent reply other threads:[~2015-05-10 20:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-10 20:00 [PATCH v6 0/7] Improving performance of git clean Erik Elfström
2015-05-10 20:00 ` Erik Elfström [this message]
2015-05-10 20:00 ` [PATCH v6 2/7] setup: add gentle version of read_gitfile Erik Elfström
2015-05-10 20:00 ` [PATCH v6 3/7] setup: sanity check file size in read_gitfile_gently Erik Elfström
2015-05-12 6:46 ` erik elfström
2015-05-10 20:00 ` [PATCH v6 4/7] t7300: add tests to document behavior of clean and nested git Erik Elfström
2015-05-10 20:00 ` [PATCH v6 5/7] p7300: add performance tests for clean Erik Elfström
2015-05-10 20:00 ` [PATCH v6 6/7] clean: improve performance when removing lots of directories Erik Elfström
2015-05-10 20:00 ` [PATCH v6 7/7] RFC: Change error handling scheme in read_gitfile_gently Erik Elfström
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431288041-21077-2-git-send-email-erik.elfstrom@gmail.com \
--to=erik.elfstrom@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.
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 NNTP newsgroup(s).