git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC 8/8] UTF-8 in non-SHA1-objects

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
May 12, 2009, 22:50 UTC
Message-ID
<1242168631-30753-9-git-send-email-robin.rosenberg@dewire.com>
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
Previous: Robin Rosenberg
Message 20 of 20 in “[RFC 0/8] Antique UTF-8 filename support”
  1. Robin RosenbergMay 12, 2009
  2. 1/8 UTF helpersRobin Rosenberg, May 12, 2009
  3. 2/8 Messages in locale.Robin Rosenberg, May 12, 2009
  4. 3/8 Extend tests to cover locale wrt to commit messages.Robin Rosenberg, May 12, 2009
  5. 4/8 UTF file names.Robin Rosenberg, May 12, 2009
  6. Johannes SchindelinMay 13, 2009
  7. Robin RosenbergMay 13, 2009
  8. Esko LuontolaMay 13, 2009
  9. Andreas EricssonMay 13, 2009
  10. Esko LuontolaMay 13, 2009
  11. Alex RiesenMay 13, 2009
  12. Junio C HamanoMay 13, 2009
  13. Esko LuontolaMay 13, 2009
  14. Junio C HamanoMay 13, 2009
  15. Johannes SchindelinMay 13, 2009
  16. Junio C HamanoMay 14, 2009
  17. Jay SoffianMay 14, 2009
  18. 6/8 test of utf_locallinksRobin Rosenberg, May 12, 2009
  19. 7/8 Convert symlink dest in diffRobin Rosenberg, May 12, 2009
  20. 8/8 UTF-8 in non-SHA1-objectsRobin Rosenberg, May 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.