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

[PATCH 1/3] dir.c: clean up handling of 'path' parameter in read_directory_recursive()

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
May 14, 2009, 20:42 UTC
Message-ID
<alpine.LFD.2.01.0905141341470.3343@localhost.localdomain>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Thu, 14 May 2009 13:05:03 -0700

Right now we pass two different pathnames ('path' and 'base') down to read_directory_recursive(), and the only real reason for that is that we want to allow an empty 'base' parameter, but when we do so, we need the pathname to "opendir()" to be "." rather than the empty string.

And rather than handle that confusion in the caller, we can just fix read_directory_recursive() to handle the case of an empty path itself, by just passing opendir() a "." ourselves if the path is empty.

This would allow us to then drop one of the pathnames entirely from the calling convention, but rather than do that, we'll start separating them out as a "filesystem pathname" (the one we use for filesystem accesses) and a "git internal base name" (which is the name that we use for git internally).

That will eventually allow us to do things like handle different encodings (eg the filesystem pathnames might be Latin1, while git itself would use UTF-8 for filename information).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

This is a truly trivial diff, but it's independent from the other changes I have, and simplifies the next ones, so I've made it a patch of its own.

 dir.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c
index 6aae09a..0e6b752 100644
--- a/dir.c
+++ b/dir.c
@@ -576,7 +576,7 @@ static int get_dtype(struct dirent *de, const char *path)
  */
 static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify)
 {
-	DIR *fdir = opendir(path);
+	DIR *fdir = opendir(*path ? path : ".");
 	int contents = 0;
 
 	if (fdir) {
-- 
1.6.3.1.11.g97114
Next: Linus Torvalds
Message 1 of 13 in “dir.c: clean up handling of 'path' parameter in read_directory_recursive()”
  1. 1/3 dir.c: clean up handling of 'path' parameter in read_directory_recursive()Linus Torvalds, May 14, 2009
  2. 2/3 Add 'fill_directory()' helper function for directory traversalLinus Torvalds, May 14, 2009
  3. 3/3 read_directory(): infrastructure for pathname character set conversionLinus Torvalds, May 14, 2009
  4. Linus TorvaldsMay 14, 2009
  5. Johannes SchindelinMay 14, 2009
  6. Aaron CohenMay 14, 2009
  7. Linus TorvaldsMay 14, 2009
  8. Linus TorvaldsMay 14, 2009
  9. 4/3 Introduce 'convert_path_to_git()'Linus Torvalds, May 15, 2009
  10. Junio C HamanoMay 16, 2009
  11. Linus TorvaldsMay 16, 2009
  12. Jens KilianMay 19, 2009
  13. John KoleszarMay 19, 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.