Skip to contentSkip to conversation

help.c: strip suffix only if the STRIP_EXTENSION defined

PATCH In review Alexander Kuleshov 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 help.c: strip suffix only if the STRIP_EXTENSION defined

We stripping extension in the list_commands_in_dir() to get commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION is defined to not spend time for unnecessary strip_suffix() call in this case.

---
 help.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
help.c +3 -2
index 19328ea..c865991 100644
@@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 			continue;
 
 		entlen = strlen(ent);
-		strip_suffix(ent, ".exe", &entlen);
-
+#ifdef STRIP_EXTENSION
+		strip_suffix(ent, STRIP_EXTENSION, &entlen);
+#endif
 		add_cmdname(cmds, ent, entlen);
 	}
 	closedir(dir);
Signature · 1 line
2.8.0.rc2.216.g1477fb2.dirty
#1 lore raw
Quoted 4 lines · Alexander Kuleshov

We stripping extension in the list_commands_in_dir() to get commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION is defined to not spend time for unnecessary strip_suffix() call in this case.

Unless the time saving is significant, I'm against this change. It makes it harder to spot compile bugs in #ifdef'd code that's only active on Windows (imagine somebody renames "ent" or change its type). If you can do something like strip_extension() in git.c, it's better. Or maybe just refactor that function a bit and share it with help.c

Quoted 28 lines
---
 help.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
help.c +3 -3
index 19328ea..c865991 100644
@@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,
                        continue;
 
                entlen = strlen(ent);
-               strip_suffix(ent, ".exe", &entlen);
-
+#ifdef STRIP_EXTENSION
+               strip_suffix(ent, STRIP_EXTENSION, &entlen);
+#endif
                add_cmdname(cmds, ent, entlen);
        }
        closedir(dir);
--

2.8.0.rc2.216.g1477fb2.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Duy
#2 lore raw
Quoted 7 lines · Duy Nguyen
Quoted 4 lines · Alexander Kuleshov

We stripping extension in the list_commands_in_dir() to get commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION is defined to not spend time for unnecessary strip_suffix() call in this case.

Quoted 5 lines

Unless the time saving is significant, I'm against this change. It makes it harder to spot compile bugs in #ifdef'd code that's only active on Windows (imagine somebody renames "ent" or change its type). If you can do something like strip_extension() in git.c, it's better. Or maybe just refactor that function a bit and share it with help.c

Yes, agree. Will think about this.

#3 lore raw
In reply to Alexander Kuleshov
Quoted 15 lines · Alexander Kuleshov

We stripping extension in the list_commands_in_dir() to get commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION is defined to not spend time for unnecessary strip_suffix() call in this case.

---
 help.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
help.c +0 -0
index 19328ea..c865991 100644

help.c static void list_commands_in_dir(struct cmdnames *cmds, · line 158

Quoted 8 lines
help.c +3 -2
@@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 			continue;
 
 		entlen = strlen(ent);
-		strip_suffix(ent, ".exe", &entlen);
-
+#ifdef STRIP_EXTENSION
+		strip_suffix(ent, STRIP_EXTENSION, &entlen);
+#endif

This is billed as an optimization in the commit message, but these two pieces of code are not the same. The original always strips ".exe", whether or not STRIP_EXTENSION is defined, and whether or not it is ".exe".

In practice it works out because people on Unix systems do not have "git-foo.exe", and nobody sets STRIP_EXTENSION to other things. But I tend to think this is an improvement in robustness.

I also wonder if this should be sharing the strip_extension() helper added in your 63ca1c0.

-Peff

#4 lore raw

Hello Jeff,

Quoted 11 lines · Jeff King

This is billed as an optimization in the commit message, but these two pieces of code are not the same. The original always strips ".exe", whether or not STRIP_EXTENSION is defined, and whether or not it is ".exe".

In practice it works out because people on Unix systems do not have "git-foo.exe", and nobody sets STRIP_EXTENSION to other things. But I tend to think this is an improvement in robustness.

I also wonder if this should be sharing the strip_extension() helper added in your 63ca1c0.

Yes, I want to move strip_extension() (from 63ca1c0) to the git-compat-util.h and adapt/reuse it in the help.c. What do you think about this?

Thank you.

#5 lore raw
Quoted 5 lines · Alexander Kuleshov
Quoted 2 lines

I also wonder if this should be sharing the strip_extension() helper added in your 63ca1c0.

Yes, I want to move strip_extension() (from 63ca1c0) to the git-compat-util.h and adapt/reuse it in the help.c. What do you think about this?

Naively, it sounds like a good idea to me, but I haven't looked too hard. There may be complications in the interface (it looks like the helper wants to make a new string, but one in help.c makes its own copy into the flex-array struct).

-Peff