Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
abspath: use strbuf_getcwd() to remember original working directory
author
René Scharfe
<l.s.r@web.de>
Mon, 28 Jul 2014 18:27:34 +0000
(20:27 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 26 Aug 2014 18:06:04 +0000
(11:06 -0700)
Store the original working directory in a strbuf instead of in a
fixed-sized buffer, in order to be able to handle longer paths.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
abspath.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
7333ed1
)
diff --git
a/abspath.c
b/abspath.c
index ca33558a91c5259a793fc56b571fa683e16b134f..911e931cc07118b9a696bd6ae041485a8eae3c0a 100644
(file)
--- a/
abspath.c
+++ b/
abspath.c
@@
-41,7
+41,7
@@
static const char *real_path_internal(const char *path, int die_on_error)
* here so that we can chdir() back to it at the end of the
* function:
*/
* here so that we can chdir() back to it at the end of the
* function:
*/
-
char cwd[1024] = ""
;
+
struct strbuf cwd = STRBUF_INIT
;
int buf_index = 1;
int buf_index = 1;
@@
-80,7
+80,7
@@
static const char *real_path_internal(const char *path, int die_on_error)
}
if (*buf) {
}
if (*buf) {
- if (!
*cwd && !getcwd(cwd, sizeof(cwd)
)) {
+ if (!
cwd.len && strbuf_getcwd(&cwd
)) {
if (die_on_error)
die_errno("Could not get current working directory");
else
if (die_on_error)
die_errno("Could not get current working directory");
else
@@
-142,8
+142,9
@@
static const char *real_path_internal(const char *path, int die_on_error)
retval = buf;
error_out:
free(last_elem);
retval = buf;
error_out:
free(last_elem);
- if (*cwd && chdir(cwd))
- die_errno("Could not change back to '%s'", cwd);
+ if (cwd.len && chdir(cwd.buf))
+ die_errno("Could not change back to '%s'", cwd.buf);
+ strbuf_release(&cwd);
return retval;
}
return retval;
}