git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Hord <hordp@cisco.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>, Phil Hord <hordp@cisco.com>
Subject: [PATCH] Make is_gitfile a non-static generic function
Date: Tue, 11 Oct 2011 18:52:27 -0400	[thread overview]
Message-ID: <4E94C8AB.3040807@cisco.com> (raw)
In-Reply-To: <4E94C70E.3080003@cisco.com>

The new is_gitfile is an amalgam of similar functional checks
from different places in the code.  All these places do
slightly different checks on the suspect gitfile (for their
own good reasons).  But the lack of common code leads to bugs
and maintenance problems. Help move the code forward by making
is_gitfile() a common function that everyone can use for this
purpose.

Signed-off-by: Phil Hord <hordp@cisco.com>
---

I'm not sure this function belongs in transport.c anymore, but
I left it here to minimize conflicts.  I think a better home would
be path.c, but maybe not.  If someone has a preference,
please let me know.

 builtin/clone.c |    8 +-------
 cache.h         |    1 +
 transport.c     |    6 +++++-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 488f48e..5110399 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -120,13 +120,7 @@ static char *get_repo_path(const char *repo, int
*is_bundle)
 			return xstrdup(absolute_path(path));
 		} else if (S_ISREG(st.st_mode) && st.st_size > 8) {
 			/* Is it a "gitfile"? */
-			char signature[8];
-			int len, fd = open(path, O_RDONLY);
-			if (fd < 0)
-				continue;
-			len = read_in_full(fd, signature, 8);
-			close(fd);
-			if (len != 8 || strncmp(signature, "gitdir: ", 8))
+			if (!is_gitfile(path))
 				continue;
 			path = read_gitfile(path);
 			if (path) {
diff --git a/cache.h b/cache.h
index 601f6f6..7a8d9f9 100644
--- a/cache.h
+++ b/cache.h
@@ -441,6 +441,7 @@ extern const char *get_git_work_tree(void);
 extern const char *read_gitfile(const char *path);
 extern const char *resolve_gitdir(const char *suspect);
 extern void set_git_work_tree(const char *tree);
+extern int is_gitfile(const char *path);
  #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 diff --git a/transport.c b/transport.c
index f3195c0..d08a826 100644
--- a/transport.c
+++ b/transport.c
@@ -859,7 +859,11 @@ static int is_local(const char *url)
 		has_dos_drive_prefix(url);
 }
 -static int is_gitfile(const char *url)
+/*
+ * See if the referenced file looks like a 'gitfile'.
+ * Does not try to determine if the referenced gitdir is actually valid.
+ */
+int is_gitfile(const char *url)
 {
 	struct stat st;
 	char buf[9];
-- 
1.7.7.334.gfc143d

       reply	other threads:[~2011-10-11 22:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4E94C70E.3080003@cisco.com>
2011-10-11 22:52 ` Phil Hord [this message]
2011-10-11 23:26   ` [PATCH] Make is_gitfile a non-static generic function Junio C Hamano
2011-10-11 23:45   ` Junio C Hamano
2011-10-12 13:29     ` Phil Hord
2011-10-12 18:01     ` Phil Hord
2011-10-12 18:08       ` Junio C Hamano
2011-10-12 19:47         ` Phil Hord

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=4E94C8AB.3040807@cisco.com \
    --to=hordp@cisco.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).