Skip to contentSkip to conversation

Use is_absolute_path() in diff-lib.c, lockfile.c, setup.c, trace.c

PATCH In review Steffen Prohaska 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use is_absolute_path() in diff-lib.c, lockfile.c, setup.c, trace.c

Using the helper function to test for absolute paths makes porting easier.

---
 diff-lib.c |    2 +-
 lockfile.c |    2 +-
 setup.c    |    2 +-
 trace.c    |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

BTW, what happend to the msysgit related patches:

[PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings [PATCH 2/3] builtin-init-db: use get_git_dir() instead of getenv()

I never received comments about them, nor do I find them on pu.

Steffen

diff-lib.c +1 -1
index f8e936a..d85d8f3 100644
@@ -231,7 +231,7 @@ static int handle_diff_files_args(struct rev_info *revs,
 static int is_outside_repo(const char *path, int nongit, const char *prefix)
 {
 	int i;
-	if (nongit || !strcmp(path, "-") || path[0] == '/')
+	if (nongit || !strcmp(path, "-") || is_absolute_path(path))
 		return 1;
 	if (prefixcmp(path, "../"))
 		return 0;
lockfile.c +1 -1
index 258fb3f..f45d3ed 100644
@@ -94,7 +94,7 @@ static char *resolve_symlink(char *p, size_t s)
 			return p;
 		}
 
-		if (link[0] == '/') {
+		if (is_absolute_path(link)) {
 			/* absolute path simply replaces p */
 			if (link_len < s)
 				strcpy(p, link);
setup.c +1 -1
index 43cd3f9..2c7b5cb 100644
@@ -59,7 +59,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
 {
 	static char path[PATH_MAX];
-	if (!pfx || !*pfx || arg[0] == '/')
+	if (!pfx || !*pfx || is_absolute_path(arg))
 		return arg;
 	memcpy(path, pfx, pfx_len);
 	strcpy(path + pfx_len, arg);
trace.c +1 -1
index 0d89dbe..d3d1b6d 100644
@@ -37,7 +37,7 @@ static int get_trace_fd(int *need_close)
 		return STDERR_FILENO;
 	if (strlen(trace) == 1 && isdigit(*trace))
 		return atoi(trace);
-	if (*trace == '/') {
+	if (is_absolute_path(trace)) {
 		int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
 		if (fd == -1) {
 			fprintf(stderr,
Signature · 1 line
1.5.3.6.878.g8c9e2
#1 lore raw
Quoted 1 line · Steffen Prohaska

Using the helper function to test for absolute paths makes porting easier.

The patch looks good.

setup.c const char *prefix_path(const char *prefix, int len, const char *path) · line 65

Quoted 11 lines
setup.c +1 -1
@@ -59,7 +59,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
 {
 	static char path[PATH_MAX];
-	if (!pfx || !*pfx || arg[0] == '/')
+	if (!pfx || !*pfx || is_absolute_path(arg))
 		return arg;
 	memcpy(path, pfx, pfx_len);
 	strcpy(path + pfx_len, arg);

This instance, however, will be reworked for Windows anyway because we must do '\\' to '/' conversion even if the path is absolute (and, hence, we cannot just return the input).

But disregarding this note, the change makes the code more readable, IMO, so I'm all for it.

-- Hannes

#2 lore raw
In reply to Steffen Prohaska
Quoted 1 line · Steffen Prohaska

Using the helper function to test for absolute paths makes porting easier.

These probably make sense. I obviously do not see any downside from the POSIX side, and can imagine that treating "C:\" prefix as "absolute paths" at these four places will not have any ill effect on the Windows side (IOW, the codepaths that follow these four places seem to do a sensible thing even if the "absolute path" prefix is not a single '/', but would work fine as-is).

I am a bit surprised that there are only four places you needed to touch, though.

Quoted 6 lines

BTW, what happend to the msysgit related patches:

[PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings [PATCH 2/3] builtin-init-db: use get_git_dir() instead of getenv()

I never received comments about them, nor do I find them on pu.

Lack of comments was probably due to mixture of bad timing and general lack of interests. Many people are busy working on their turkeys than hacking this time of the year ;-)

I am reluctant to queue msysgit/gitwin related patches without seeing positive comments from other people involved on the Windows side, unless they are trivial and obvious improvements.

* [1/3] seems without harm but on the other hand does not seem so urgent either.

* [2/3] may introduce chicken-and-egg problem (use of get_git_dir() inside git-init feels quite iffy, as it calls setup_git_env(), which does repository discovery), without an obvious and clear advantage.

For these reasons, both of them disqualify from being trivial and obvious improvements, so I did not pick them up unilaterally before seeing positive comments from other people.

#3 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 1 line · Steffen Prohaska

Using the helper function to test for absolute paths makes porting easier.

These probably make sense. I obviously do not see any downside from the POSIX side, and can imagine that treating "C:\" prefix as "absolute paths" at these four places will not have any ill effect on the Windows side (IOW, the codepaths that follow these four places seem to do a sensible thing even if the "absolute path" prefix is not a single '/', but would work fine as-is).

Quoted 2 lines

I am a bit surprised that there are only four places you needed to touch, though.

Yes, I was a bit surprised, too. I used grep to find these places. Maybe my regular expression was not good enough. On the other side, is_absolute_path() is already used at 11 places before this patch. I also cross checked with the msysgit code base. It does not use is_absolute_path() at more places.

Quoted 10 lines
Quoted 6 lines

BTW, what happend to the msysgit related patches:

[PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings [PATCH 2/3] builtin-init-db: use get_git_dir() instead of getenv()

I never received comments about them, nor do I find them on pu.

Lack of comments was probably due to mixture of bad timing and general lack of interests. Many people are busy working on their turkeys than hacking this time of the year ;-)

Yeah, list traffic was quiet low.

Quoted 6 lines

I am reluctant to queue msysgit/gitwin related patches without seeing positive comments from other people involved on the Windows side, unless they are trivial and obvious improvements.

* [1/3] seems without harm but on the other hand does not seem so urgent either.

I did not find a simpler way to achieve a compile free warning on mingw, without introducing more complex ifdefs. I'm currently trying to reduce the differences between git.git, mingw, and msysgit.

Quoted 4 lines

* [2/3] may introduce chicken-and-egg problem (use of get_git_dir() inside git-init feels quite iffy, as it calls setup_git_env(),
which
does repository discovery), without an obvious and clear advantage.

I see. I'll rethink 2/3 and 3/3. Either I come up with more convincing arguments or I'll try if the changes can be reverted in the msysgit code base.

Quoted 3 lines

For these reasons, both of them disqualify from being trivial and obvious improvements, so I did not pick them up unilaterally before seeing positive comments from other people.

Steffen