diff options
| author | Junio C Hamano <gitster@pobox.com> | 2008-06-22 14:33:53 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2008-06-22 14:33:53 -0700 |
| commit | 8bcff62baf7a17864620964c60d3a02d7c5b8d77 (patch) | |
| tree | 16af8e6acf176389ea22102a316e376192b44adc /path.c | |
| parent | 6419cd556696a77e55ec21c260b36571e9e53c12 (diff) | |
| parent | 044bbbcb63281dfdb78344ada2c44c96122dc822 (diff) | |
Merge branch 'lt/maint-gitdir-relative'
* lt/maint-gitdir-relative:
Make git_dir a path relative to work_tree in setup_work_tree()
Diffstat (limited to 'path.c')
| -rw-r--r-- | path.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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]; |
