* [PATCH 1/2] dir: respect string length argument of read_directory_recursive()
@ 2012-05-11 14:53 René Scharfe
2012-05-11 14:59 ` [PATCH 2/2] dir: simplify fill_directory() René Scharfe
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2012-05-11 14:53 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
A directory name is passed to read_directory_recursive() as a
length-limited string, through the parameters base and baselen.
Suprisingly, base must be a NUL-terminated string as well, as it is
passed to opendir(), ignoring baselen.
Fix this by postponing the call to opendir() until the length-limted
string is added to a strbuf, which provides a NUL in the right place.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
dir.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/dir.c b/dir.c
index c6a98cc..d5444fb 100644
--- a/dir.c
+++ b/dir.c
@@ -960,16 +960,17 @@ static int read_directory_recursive(struct dir_struct *dir,
int check_only,
const struct path_simplify *simplify)
{
- DIR *fdir = opendir(*base ? base : ".");
+ DIR *fdir;
int contents = 0;
struct dirent *de;
struct strbuf path = STRBUF_INIT;
- if (!fdir)
- return 0;
-
strbuf_add(&path, base, baselen);
+ fdir = opendir(path.len ? path.buf : ".");
+ if (!fdir)
+ goto out;
+
while ((de = readdir(fdir)) != NULL) {
switch (treat_path(dir, de, &path, baselen, simplify)) {
case path_recurse:
@@ -984,12 +985,11 @@ static int read_directory_recursive(struct dir_struct *dir,
}
contents++;
if (check_only)
- goto exit_early;
- else
- dir_add_name(dir, path.buf, path.len);
+ break;
+ dir_add_name(dir, path.buf, path.len);
}
-exit_early:
closedir(fdir);
+ out:
strbuf_release(&path);
return contents;
--
1.7.10.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] dir: simplify fill_directory()
2012-05-11 14:53 [PATCH 1/2] dir: respect string length argument of read_directory_recursive() René Scharfe
@ 2012-05-11 14:59 ` René Scharfe
0 siblings, 0 replies; 2+ messages in thread
From: René Scharfe @ 2012-05-11 14:59 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
Now that read_directory_recursive() (reached through read_directory())
respects the string length limit we provide, we don't need to create a
NUL-limited copy of the common prefix anymore.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
dir.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/dir.c b/dir.c
index d5444fb..ed1510f 100644
--- a/dir.c
+++ b/dir.c
@@ -74,7 +74,6 @@ char *common_prefix(const char **pathspec)
int fill_directory(struct dir_struct *dir, const char **pathspec)
{
- const char *path;
size_t len;
/*
@@ -82,15 +81,9 @@ int fill_directory(struct dir_struct *dir, const char **pathspec)
* use that to optimize the directory walk
*/
len = common_prefix_len(pathspec);
- path = "";
-
- if (len)
- path = xmemdupz(*pathspec, len);
/* Read the directory and prune it */
- read_directory(dir, path, len, pathspec);
- if (*path)
- free((char *)path);
+ read_directory(dir, pathspec ? *pathspec : "", len, pathspec);
return len;
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-11 14:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-11 14:53 [PATCH 1/2] dir: respect string length argument of read_directory_recursive() René Scharfe
2012-05-11 14:59 ` [PATCH 2/2] dir: simplify fill_directory() René Scharfe
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).