diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-06-25 11:19:33 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-06-25 11:19:33 -0700 |
commit | 41cb0fc100c2e00e2978c91d7d0b8b51167c1243 (patch) | |
tree | d7b0b1dc5f7e527fc6c9ad8a01d381b2a83c0b41 | |
parent | 340a6b58da21442492650f0e1d7e25be5253c677 (diff) | |
parent | 044bbbcb63281dfdb78344ada2c44c96122dc822 (diff) | |
download | git-41cb0fc100c2e00e2978c91d7d0b8b51167c1243.tar.gz git-41cb0fc100c2e00e2978c91d7d0b8b51167c1243.tar.xz |
Merge branch 'lt/maint-gitdir-relative' into maint
* lt/maint-gitdir-relative:
Make git_dir a path relative to work_tree in setup_work_tree()
-rw-r--r-- | cache.h | 1 | ||||
-rw-r--r-- | path.c | 17 | ||||
-rw-r--r-- | setup.c | 3 |
3 files changed, 20 insertions, 1 deletions
@@ -525,6 +525,7 @@ static inline int is_absolute_path(const char *path) } const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); +const char *make_relative_path(const char *abs, const char *base); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); @@ -330,6 +330,23 @@ const char *make_nonrelative_path(const char *path) /* We allow "recursive" symbolic links. Only within reason, though. */ #define MAXDEPTH 5 +const char *make_relative_path(const char *abs, const char *base) +{ + static char buf[PATH_MAX + 1]; + int baselen; + if (!base) + return abs; + baselen = strlen(base); + if (prefixcmp(abs, base)) + return abs; + if (abs[baselen] == '/') + baselen++; + else if (base[baselen - 1] != '/') + return abs; + strcpy(buf, abs + baselen); + return buf; +} + const char *make_absolute_path(const char *path) { static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1]; @@ -292,9 +292,10 @@ void setup_work_tree(void) work_tree = get_git_work_tree(); git_dir = get_git_dir(); if (!is_absolute_path(git_dir)) - set_git_dir(make_absolute_path(git_dir)); + git_dir = make_absolute_path(git_dir); if (!work_tree || chdir(work_tree)) die("This operation must be run in a work tree"); + set_git_dir(make_relative_path(git_dir, work_tree)); initialized = 1; } |