From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [RFC 8/8] UTF-8 in non-SHA1-objects
Date: Wed, 13 May 2009 00:50:31 +0200 [thread overview]
Message-ID: <1242168631-30753-9-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1242168631-30753-8-git-send-email-robin.rosenberg@dewire.com>
---
dir.c | 22 ++++++++++++++------
utf.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 80 insertions(+), 8 deletions(-)
diff --git a/dir.c b/dir.c
index 96389b3..043df50 100644
--- a/dir.c
+++ b/dir.c
@@ -114,22 +114,26 @@ static int add_excludes_from_file_1(const char *fname,
{
struct stat st;
int fd, i;
- long size;
- char *buf, *entry;
+ long insize, size;
+ char *inbuf, *entry, *buf;
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0)
goto err;
- size = st.st_size;
- if (size == 0) {
+ insize = st.st_size;
+ if (insize == 0) {
close(fd);
return 0;
}
- buf = xmalloc(size+1);
- if (read(fd, buf, size) != size)
+ inbuf = xmalloc(insize+1);
+ if (read(fd, inbuf, insize) != insize)
goto err;
close(fd);
+ size = utflen(inbuf, insize+1);
+ buf = xmalloc(size);
+ utfcpy(buf, inbuf, insize+1);
+
buf[size++] = '\n';
entry = buf;
for (i = 0; i < size; i++) {
@@ -141,9 +145,11 @@ static int add_excludes_from_file_1(const char *fname,
entry = buf + i + 1;
}
}
+ free(inbuf);
return 0;
err:
+ // bug: not freeing inbuf...
if (0 <= fd)
close(fd);
return -1;
@@ -185,6 +191,7 @@ static int excluded_1(const char *pathname,
int pathlen,
struct exclude_list *el)
{
+ P(("excluded_1(\"%0.*s\") = ", pathlen, pathname));
int i;
if (el->nr) {
@@ -202,6 +209,7 @@ static int excluded_1(const char *pathname,
/* match basename */
const char *basename = strrchr(pathname, '/');
basename = (basename) ? basename+1 : pathname;
+ P(("fnmatch(\"%s\",\"%s\")", exclude, basename));
if (fnmatch(exclude, basename, 0) == 0)
return to_exclude;
}
@@ -218,7 +226,7 @@ static int excluded_1(const char *pathname,
(baselen && pathname[baselen-1] != '/') ||
strncmp(pathname, x->base, baselen))
continue;
-
+ P(("fnmatch(\"%s\",\"%s\")", exclude, pathname+baselen));
if (fnmatch(exclude, pathname+baselen,
FNM_PATHNAME) == 0)
return to_exclude;
diff --git a/utf.c b/utf.c
index 7c44cac..cca64dc 100644
--- a/utf.c
+++ b/utf.c
@@ -228,9 +228,28 @@ static void zfree(void *ret)
free(ret);
}
+int isgitpath(char *path)
+{
+ char *gitdir=getenv("GIT_DIR");
+ if (!gitdir)
+ gitdir=".git";
+
+ P(("gitdir=%s\n",gitdir));
+ if (strncmp(path, gitdir, strlen(gitdir)) == 0) {
+ P(("gitdir:YES\n"));
+ return 1;
+ } else {
+ P(("gitdir:NO\n"));
+ }
+
+ return 0;
+}
+
int utf_lstat(char *path, struct stat *buf)
{
P(("utf_lstat(\"%s\",buf)[",path));
+ if (isgitpath(path))
+ return lstat(path, buf);
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -248,6 +267,8 @@ int utf_lstat(char *path, struct stat *buf)
int utf_stat(char *path, struct stat *buf)
{
P(("utf_stat(\"%s\",buf)[",path));
+ if (isgitpath(path))
+ return stat(path, buf);
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -257,19 +278,27 @@ int utf_stat(char *path, struct stat *buf)
DIR *utf_opendir(char *path)
{
P(("utf_opendir(\"%s\")\n",path));
+ if (isgitpath(path)) {
+ P(("not transforming dir"));
+ return opendir(path);
+ }
char localpath[MAXPATHLEN];
DIR *ret = NULL;
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
ret = opendir(localpath);
if (ret)
- put(ret, NULL);
+ put(ret, xmalloc(1));
return ret;
}
struct dirent* utf_readdir(DIR *dir)
{
P(("utf_readdir(\"%p\")",dir));
+ if (!get(dir)) {
+ P(("Skipping\n"));
+ return readdir(dir);
+ }
struct dirent *ret;
int len;
char utfpath[256];
@@ -294,6 +323,9 @@ struct dirent* utf_readdir(DIR *dir)
int utf_closedir(DIR *dir)
{
P(("utf_closedir(%p)\n",dir));
+ if (!get(dir))
+ return closedir(dir);
+
zfree(getandremove(dir));
return closedir(dir);
}
@@ -301,6 +333,9 @@ int utf_closedir(DIR *dir)
FILE *utf_fopen(char *path, char *mode)
{
P(("utf_fopen(\"%s\",\"%s\")[",path,mode));
+ if (isgitpath(path))
+ return fopen(path,mode);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -310,6 +345,9 @@ FILE *utf_fopen(char *path, char *mode)
FILE *utf_freopen(char *path, char *mode, FILE *stream)
{
P(("utf_freopen(\"%s\",\"%s\",%p)[",path,mode,stream));
+ if (isgitpath(path))
+ return utf_freopen(path, mode, stream);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -319,6 +357,9 @@ FILE *utf_freopen(char *path, char *mode, FILE *stream)
int utf_unlink(char *path)
{
P(("utf_unlink(\"%s\")[",path));
+ if (isgitpath(path))
+ return unlink(path);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -328,6 +369,9 @@ int utf_unlink(char *path)
int utf_rmdir(char *path)
{
P(("utf_rmdir(\"%s\")[",path));
+ if (isgitpath(path))
+ return rmdir(path);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -342,6 +386,9 @@ int utf_open(char *path, int flags,...)
mode = va_arg(va,int);
va_end(va);
P(("utf_open(\"%s\",%d,%d)[",path,flags,mode));
+ if (isgitpath(path))
+ return open(path, flags, mode);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -351,6 +398,9 @@ int utf_open(char *path, int flags,...)
int utf_access(char *path, int mode)
{
P(("utf_access(\"%s\",%d)[",path,mode));
+ if (isgitpath(path))
+ return access(path, mode);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -369,6 +419,11 @@ char *utf_getcwd(char *buf,int bufsize)
buf = malloc(utflen(localbuf,strlen(localbuf)) + 1);
}
}
+ if (isgitpath(localbuf)) {
+ strcpy(buf, localbuf);
+ return buf;
+ }
+
utfcpy(buf, localbuf, strlen(localbuf) + 1);
return buf;
} else {
@@ -379,6 +434,9 @@ char *utf_getcwd(char *buf,int bufsize)
int utf_creat(const char *path,int mode)
{
P(("utf_creat(\"%s\",%d)[",path,mode));
+ if (isgitpath(path))
+ return creat(path, mode);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -388,6 +446,9 @@ int utf_creat(const char *path,int mode)
int utf_mkdir(const char *path,int mode)
{
P(("utf_mkdir(\"%s\",%d)[",path,mode));
+ if (isgitpath(path))
+ return mkdir(path,mode);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("\"%s\"]\n",localpath));
@@ -397,6 +458,9 @@ int utf_mkdir(const char *path,int mode)
ssize_t utf_readlink(const char *path,char *buf,size_t bufsiz)
{
P(("utf_readlink(\"%s\",BUF,%d)[",path,bufsiz));
+ if (isgitpath(path))
+ return readlink(path, buf, bufsiz);
+
char localpath[MAXPATHLEN];
localcpy(localpath, path, strlen(path)+1);
P(("readlink(%s)\n", localpath));
--
1.6.3.dirty
next prev parent reply other threads:[~2009-05-12 22:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-12 22:50 [RFC 0/8] Antique UTF-8 filename support Robin Rosenberg
2009-05-12 22:50 ` [RFC 1/8] UTF helpers Robin Rosenberg
2009-05-12 22:50 ` [RFC 2/8] Messages in locale Robin Rosenberg
2009-05-12 22:50 ` [RFC 3/8] Extend tests to cover locale wrt to commit messages Robin Rosenberg
2009-05-12 22:50 ` [RFC 4/8] UTF file names Robin Rosenberg
[not found] ` <1242168631-30753-6-git-send-email-robin.rosenberg@dewire.com>
2009-05-12 22:50 ` [RFC 6/8] test of utf_locallinks Robin Rosenberg
2009-05-12 22:50 ` [RFC 7/8] Convert symlink dest in diff Robin Rosenberg
2009-05-12 22:50 ` Robin Rosenberg [this message]
2009-05-13 0:20 ` [RFC 1/8] UTF helpers Johannes Schindelin
2009-05-13 5:24 ` Robin Rosenberg
2009-05-13 9:24 ` Esko Luontola
2009-05-13 10:02 ` Andreas Ericsson
2009-05-13 10:21 ` Esko Luontola
2009-05-13 11:44 ` Alex Riesen
2009-05-13 18:48 ` Junio C Hamano
2009-05-13 19:31 ` Esko Luontola
2009-05-13 20:10 ` Junio C Hamano
2009-05-13 10:14 ` Johannes Schindelin
2009-05-14 4:38 ` Junio C Hamano
2009-05-14 13:57 ` Jay Soffian
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=1242168631-30753-9-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.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).