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

Re: [PATCH] remove unnecessary loop

From
LYLiu Yubao <yubao.liu@gmail.com>
Date
May 8, 2007, 04:49 UTC
Message-ID
<4640015F.1080407@gmail.com>
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
Previous: Liu YubaoNext: Junio C Hamano
Message 2 of 9 in “remove unnecessary loop”
  1. remove unnecessary loopLiu Yubao, May 8, 2007
  2. Liu YubaoMay 8, 2007
  3. Junio C HamanoMay 8, 2007
  4. Alex RiesenMay 8, 2007
  5. Jan HudecMay 8, 2007
  6. Alex RiesenMay 8, 2007
  7. Eric BlakeMay 8, 2007
  8. Jan HudecMay 8, 2007
  9. Liu YubaoMay 9, 2007

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.