* [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list()
@ 2014-03-17 21:30 Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp() Hiroyuki Sano
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Hiroyuki Sano @ 2014-03-17 21:30 UTC (permalink / raw)
To: git; +Cc: Hiroyuki Sano
Including "dir.h" in "diff-no-index.c", it causes a compile error, because
the same name function read_directory() is declared globally in "dir.h".
This change is to avoid conflicts as above.
Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
---
diff-no-index.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 8e10bff..1ed5c9d 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -16,7 +16,7 @@
#include "builtin.h"
#include "string-list.h"
-static int read_directory(const char *path, struct string_list *list)
+static int get_directory_list(const char *path, struct string_list *list)
{
DIR *dir;
struct dirent *e;
@@ -107,9 +107,9 @@ static int queue_diff(struct diff_options *o,
int i1, i2, ret = 0;
size_t len1 = 0, len2 = 0;
- if (name1 && read_directory(name1, &p1))
+ if (name1 && get_directory_list(name1, &p1))
return -1;
- if (name2 && read_directory(name2, &p2)) {
+ if (name2 && get_directory_list(name2, &p2)) {
string_list_clear(&p1, 0);
return -1;
}
--
1.9.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp()
2014-03-17 21:30 [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Hiroyuki Sano
@ 2014-03-17 21:30 ` Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 3/3][GSOC] fsck: " Hiroyuki Sano
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Hiroyuki Sano @ 2014-03-17 21:30 UTC (permalink / raw)
To: git; +Cc: Hiroyuki Sano
The is_dot_or_dotdot() is used to check if the string is either "." or "..".
Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
---
diff-no-index.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 1ed5c9d..ccd9270 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -11,6 +11,7 @@
#include "tag.h"
#include "diff.h"
#include "diffcore.h"
+#include "dir.h"
#include "revision.h"
#include "log-tree.h"
#include "builtin.h"
@@ -25,7 +26,7 @@ static int get_directory_list(const char *path, struct string_list *list)
return error("Could not open directory %s", path);
while ((e = readdir(dir)))
- if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
+ if (!is_dot_or_dotdot(e->d_name))
string_list_insert(list, e->d_name);
closedir(dir);
--
1.9.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3][GSOC] fsck: use is_dot_or_dotdot() instead of strcmp()
2014-03-17 21:30 [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp() Hiroyuki Sano
@ 2014-03-17 21:30 ` Hiroyuki Sano
2014-03-17 22:39 ` Junio C Hamano
2014-03-17 22:37 ` [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Junio C Hamano
2014-03-19 10:04 ` Eric Sunshine
3 siblings, 1 reply; 8+ messages in thread
From: Hiroyuki Sano @ 2014-03-17 21:30 UTC (permalink / raw)
To: git; +Cc: Hiroyuki Sano
The is_dot_or_dotdot() is used to check if the string is either "." or "..".
Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
---
fsck.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fsck.c b/fsck.c
index b3022ad..c9d7784 100644
--- a/fsck.c
+++ b/fsck.c
@@ -6,6 +6,7 @@
#include "commit.h"
#include "tag.h"
#include "fsck.h"
+#include "dir.h"
static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
{
@@ -171,10 +172,12 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
has_full_path = 1;
if (!*name)
has_empty_name = 1;
- if (!strcmp(name, "."))
- has_dot = 1;
- if (!strcmp(name, ".."))
- has_dotdot = 1;
+ if (is_dot_or_dotdot(name)) {
+ if (!name[1])
+ has_dot = 1;
+ else
+ has_dotdot = 1;
+ }
if (!strcmp(name, ".git"))
has_dotgit = 1;
has_zero_pad |= *(char *)desc.buffer == '0';
--
1.9.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list()
2014-03-17 21:30 [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp() Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 3/3][GSOC] fsck: " Hiroyuki Sano
@ 2014-03-17 22:37 ` Junio C Hamano
2014-03-19 17:22 ` Junio C Hamano
2014-03-19 10:04 ` Eric Sunshine
3 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2014-03-17 22:37 UTC (permalink / raw)
To: Hiroyuki Sano; +Cc: git
Hiroyuki Sano <sh19910711@gmail.com> writes:
> Including "dir.h" in "diff-no-index.c", it causes a compile error, because
> the same name function read_directory() is declared globally in "dir.h".
>
> This change is to avoid conflicts as above.
>
> Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
> ---
> diff-no-index.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 8e10bff..1ed5c9d 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -16,7 +16,7 @@
> #include "builtin.h"
> #include "string-list.h"
>
> -static int read_directory(const char *path, struct string_list *list)
> +static int get_directory_list(const char *path, struct string_list *list)
Renaming is a good idea but the new name sounds like you are
grabbing the names of directories, ignoring all the files, no?
> {
> DIR *dir;
> struct dirent *e;
> @@ -107,9 +107,9 @@ static int queue_diff(struct diff_options *o,
> int i1, i2, ret = 0;
> size_t len1 = 0, len2 = 0;
>
> - if (name1 && read_directory(name1, &p1))
> + if (name1 && get_directory_list(name1, &p1))
> return -1;
> - if (name2 && read_directory(name2, &p2)) {
> + if (name2 && get_directory_list(name2, &p2)) {
> string_list_clear(&p1, 0);
> return -1;
> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3][GSOC] fsck: use is_dot_or_dotdot() instead of strcmp()
2014-03-17 21:30 ` [PATCH 3/3][GSOC] fsck: " Hiroyuki Sano
@ 2014-03-17 22:39 ` Junio C Hamano
0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2014-03-17 22:39 UTC (permalink / raw)
To: Hiroyuki Sano; +Cc: git
Hiroyuki Sano <sh19910711@gmail.com> writes:
> The is_dot_or_dotdot() is used to check if the string is either "." or "..".
>
> Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
> ---
> fsck.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/fsck.c b/fsck.c
> index b3022ad..c9d7784 100644
> --- a/fsck.c
> +++ b/fsck.c
> @@ -6,6 +6,7 @@
> #include "commit.h"
> #include "tag.h"
> #include "fsck.h"
> +#include "dir.h"
>
> static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
> {
> @@ -171,10 +172,12 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
> has_full_path = 1;
> if (!*name)
> has_empty_name = 1;
> - if (!strcmp(name, "."))
> - has_dot = 1;
> - if (!strcmp(name, ".."))
> - has_dotdot = 1;
> + if (is_dot_or_dotdot(name)) {
> + if (!name[1])
> + has_dot = 1;
> + else
> + has_dotdot = 1;
> + }
In what way is this an improvement?
This looks like "because I was told to", not "because the resulting
code is better" to me.
The other patch on diff-no-index looked sensible, though.
> if (!strcmp(name, ".git"))
> has_dotgit = 1;
> has_zero_pad |= *(char *)desc.buffer == '0';
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list()
2014-03-17 21:30 [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Hiroyuki Sano
` (2 preceding siblings ...)
2014-03-17 22:37 ` [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Junio C Hamano
@ 2014-03-19 10:04 ` Eric Sunshine
3 siblings, 0 replies; 8+ messages in thread
From: Eric Sunshine @ 2014-03-19 10:04 UTC (permalink / raw)
To: Hiroyuki Sano; +Cc: Git List
On Mon, Mar 17, 2014 at 5:30 PM, Hiroyuki Sano <sh19910711@gmail.com> wrote:
> Including "dir.h" in "diff-no-index.c", it causes a compile error, because
> the same name function read_directory() is declared globally in "dir.h".
>
> This change is to avoid conflicts as above.
This explanation is slightly lacking. Since dir.h is not currently
included by this file, a person reading this patch may wonder why you
need to avoid conflict where there is none. Adding a short sentence
saying that a subsequent patch will include dir.h in order to access
is_dot_or_dotdot() can avoid such confusion.
> Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
> ---
> diff-no-index.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 8e10bff..1ed5c9d 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -16,7 +16,7 @@
> #include "builtin.h"
> #include "string-list.h"
>
> -static int read_directory(const char *path, struct string_list *list)
> +static int get_directory_list(const char *path, struct string_list *list)
> {
> DIR *dir;
> struct dirent *e;
> @@ -107,9 +107,9 @@ static int queue_diff(struct diff_options *o,
> int i1, i2, ret = 0;
> size_t len1 = 0, len2 = 0;
>
> - if (name1 && read_directory(name1, &p1))
> + if (name1 && get_directory_list(name1, &p1))
> return -1;
> - if (name2 && read_directory(name2, &p2)) {
> + if (name2 && get_directory_list(name2, &p2)) {
> string_list_clear(&p1, 0);
> return -1;
> }
> --
> 1.9.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list()
2014-03-17 22:37 ` [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Junio C Hamano
@ 2014-03-19 17:22 ` Junio C Hamano
2014-03-19 18:48 ` Junio C Hamano
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2014-03-19 17:22 UTC (permalink / raw)
To: Hiroyuki Sano; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> Hiroyuki Sano <sh19910711@gmail.com> writes:
>
>> Including "dir.h" in "diff-no-index.c", it causes a compile error, because
>> the same name function read_directory() is declared globally in "dir.h".
>>
>> This change is to avoid conflicts as above.
>>
>> Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
>> ---
>> diff-no-index.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/diff-no-index.c b/diff-no-index.c
>> index 8e10bff..1ed5c9d 100644
>> --- a/diff-no-index.c
>> +++ b/diff-no-index.c
>> @@ -16,7 +16,7 @@
>> #include "builtin.h"
>> #include "string-list.h"
>>
>> -static int read_directory(const char *path, struct string_list *list)
>> +static int get_directory_list(const char *path, struct string_list *list)
>
> Renaming is a good idea but the new name sounds like you are
> grabbing the names of directories, ignoring all the files, no?
I am tempted to suggest, because this is an internal implementation
detail only visible to this narrow corner of the system, calling
this just
static int ls(const char *path, struct string_list *result)
;-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list()
2014-03-19 17:22 ` Junio C Hamano
@ 2014-03-19 18:48 ` Junio C Hamano
0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2014-03-19 18:48 UTC (permalink / raw)
To: Hiroyuki Sano; +Cc: git, Brian Bourn, Eric Sunshine
Junio C Hamano <gitster@pobox.com> writes:
>>> -static int read_directory(const char *path, struct string_list *list)
>>> +static int get_directory_list(const char *path, struct string_list *list)
>>
>> Renaming is a good idea but the new name sounds like you are
>> grabbing the names of directories, ignoring all the files, no?
>
> I am tempted to suggest, because this is an internal implementation
> detail only visible to this narrow corner of the system, calling
> this just
>
> static int ls(const char *path, struct string_list *result)
>
> ;-)
Scratch that one.
I'll take read_directory_contents() from Brian Bourn, which
essentially is the same patch.
Thanks.
-- >8 --
From: Brian Bourn <ba.bourn@gmail.com>
Date: Wed, 19 Mar 2014 11:58:21 -0400
Subject: [PATCH] diff-no-index: rename read_directory()
In the next patch, we will replace a manual checking of "." or ".."
with a call to is_dot_or_dotdot() defined in dir.h. The private
function read_directory() defined in this file will conflict with
the global function declared there when we do so.
As a preparatory step, rename the private read_directory() to avoid
the name collision.
Signed-off-by: Brian Bourn <ba.bourn@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff-no-index.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 33e5982..3e4f47e 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -16,7 +16,7 @@
#include "builtin.h"
#include "string-list.h"
-static int read_directory(const char *path, struct string_list *list)
+static int read_directory_contents(const char *path, struct string_list *list)
{
DIR *dir;
struct dirent *e;
@@ -107,9 +107,9 @@ static int queue_diff(struct diff_options *o,
int i1, i2, ret = 0;
size_t len1 = 0, len2 = 0;
- if (name1 && read_directory(name1, &p1))
+ if (name1 && read_directory_contents(name1, &p1))
return -1;
- if (name2 && read_directory(name2, &p2)) {
+ if (name2 && read_directory_contents(name2, &p2)) {
string_list_clear(&p1, 0);
return -1;
}
--
1.9.1-423-g4596e3a
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-03-19 18:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-17 21:30 [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp() Hiroyuki Sano
2014-03-17 21:30 ` [PATCH 3/3][GSOC] fsck: " Hiroyuki Sano
2014-03-17 22:39 ` Junio C Hamano
2014-03-17 22:37 ` [PATCH 1/3][GSOC] diff: rename read_directory() to get_directory_list() Junio C Hamano
2014-03-19 17:22 ` Junio C Hamano
2014-03-19 18:48 ` Junio C Hamano
2014-03-19 10:04 ` Eric Sunshine
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).