All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Yubao <yubao.liu@gmail.com>
To: git@vger.kernel.org
Subject: Re: [PATCH] remove unnecessary loop
Date: Tue, 08 May 2007 12:49:35 +0800	[thread overview]
Message-ID: <4640015F.1080407@gmail.com> (raw)
In-Reply-To: <463FEC07.8080605@gmail.com>

Liu Yubao wrote:
> Hi,
>    Here is a minor optimization, the involved second "for" loop doesn't
> need to start from beginning.
> 

I found it when I debugged a strange problem on Cygwin, at last, I think
it's a bug of Cygwin.

$ touch hello.exe
$ git add hello
The following paths are ignored by one of your .gitignore files:
hello
Use -f if you really want to add them.

Here is a ugly fix, I don't hope it will be merged into git tree as it's not
git's fault, I will file a bug report for Cygwin.

---
 builtin-add.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 9d10fdc..ff1e74f 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -42,6 +42,9 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 	for (i = 0; i < specs; i++) {
 		struct stat st;
 		const char *match;
+#ifdef __CYGWIN__
+		int fd;
+#endif
 		if (seen[i])
 			continue;
 
@@ -50,9 +53,18 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 			continue;
 
 		/* Existing file? We must have ignored it */
+#ifdef __CYGWIN__
+		/*
+		 * On cygwin, lstat("hello", &st) returns 0 when
+		 * "hello.exe" exists, so test with open() again.
+		 */
+		if (lstat(match, &st) && -1 != (fd = open(match, O_RDONLY))) {
+			struct dir_entry *ent;
+			close(fd);
+#else
 		if (!lstat(match, &st)) {
 			struct dir_entry *ent;
-
+#endif
 			ent = dir_add_name(dir, match, strlen(match));
 			ent->ignored = 1;
 			if (S_ISDIR(st.st_mode))
-- 
1.5.2.rc0.95.ga0715-dirty

  reply	other threads:[~2007-05-08  4:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-08  3:18 [PATCH] remove unnecessary loop Liu Yubao
2007-05-08  4:49 ` Liu Yubao [this message]
2007-05-08  5:05   ` Junio C Hamano
2007-05-08  9:08   ` Alex Riesen
2007-05-08 10:13     ` Jan Hudec
2007-05-08 12:38       ` Alex Riesen
2007-05-08 12:17     ` Eric Blake
2007-05-08  9:39   ` Jan Hudec
2007-05-09  1:03     ` Liu Yubao

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=4640015F.1080407@gmail.com \
    --to=yubao.liu@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.