From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org,
"João Carlos Mendes Luís" <jonny@jonny.eng.br>,
"Junio C Hamano" <gitster@pobox.com>,
"Johannes Sixt" <j6t@kdbg.org>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/5] Add is_root_path()
Date: Thu, 11 Feb 2010 21:43:21 +0700 [thread overview]
Message-ID: <1265899403-15904-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1265899403-15904-1-git-send-email-pclouds@gmail.com>
This function returns the length of the root part of a path, or zero if
there is no root.
"The root part" is the leading slash on Linux/Unix, or 'C:/' on Windows.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
... and can be extended to recognize "//machine/share/" as a root part?
git-compat-util.h | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index a3c4537..4d0398d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -210,6 +210,17 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
return strncmp(str, prefix, len) ? NULL : str + len;
}
+/* path must be canonical */
+static inline int is_root_path(const char *path)
+{
+ int len = 0;
+ if (has_dos_drive_prefix(path))
+ len += 2;
+ if (is_dir_sep(path[len]))
+ len++;
+ return len;
+}
+
#if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
#ifndef PROT_READ
--
1.7.0.rc2.182.g3adef
next prev parent reply other threads:[~2010-02-11 14:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-11 14:43 [PATCH 0/5 v2] Worktree/Gitdir at root directory Nguyễn Thái Ngọc Duy
2010-02-11 14:43 ` [PATCH 1/5] make_absolute_path(): Do not append redundant slash Nguyễn Thái Ngọc Duy
2010-02-11 14:43 ` [PATCH 2/5] init-db, rev-parse --git-dir: do " Nguyễn Thái Ngọc Duy
2010-02-11 14:43 ` Nguyễn Thái Ngọc Duy [this message]
2010-02-12 10:11 ` [PATCH 3/5] Add is_root_path() Johannes Sixt
2010-02-11 14:43 ` [PATCH 4/5] Support working directory located at root Nguyễn Thái Ngọc Duy
2010-02-11 14:43 ` [PATCH 5/5] Add test for using Git at root directory Nguyễn Thái Ngọc Duy
2010-02-12 10:21 ` [PATCH 0/5 v2] Worktree/Gitdir " Johannes Sixt
2010-02-12 13:05 ` João Carlos Mendes Luís
2010-02-12 16:00 ` Johannes Sixt
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=1265899403-15904-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=jonny@jonny.eng.br \
/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).