summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e90fdc3)
raw | patch | inline | side by side (parent: e90fdc3)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Wed, 1 Aug 2007 18:26:59 +0000 (19:26 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 1 Aug 2007 18:34:13 +0000 (11:34 -0700) |
The comment did not make a good case why it makes sense.
Clarify, and remove stale comment about the caller being lazy.
The behaviour on NULL input is pretty much intentional.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Clarify, and remove stale comment about the caller being lazy.
The behaviour on NULL input is pretty much intentional.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c | patch | blob | history |
index b3329f41b2b8830d311f88be59037f7325e2b1e4..eb6c3abd30baefb9501c69b0e956ae1231f4b085 100644 (file)
--- a/dir.c
+++ b/dir.c
/*
* get_relative_cwd() gets the prefix of the current working directory
* relative to 'dir'. If we are not inside 'dir', it returns NULL.
- * As a convenience, it also returns NULL if 'dir' is already NULL.
+ *
+ * As a convenience, it also returns NULL if 'dir' is already NULL. The
+ * reason for this behaviour is that it is natural for functions returning
+ * directory names to return NULL to say "this directory does not exist"
+ * or "this directory is invalid". These cases are usually handled the
+ * same as if the cwd is not inside 'dir' at all, so get_relative_cwd()
+ * returns NULL for both of them.
+ *
+ * Most notably, get_relative_cwd(buffer, size, get_git_work_tree())
+ * unifies the handling of "outside work tree" with "no work tree at all".
*/
char *get_relative_cwd(char *buffer, int size, const char *dir)
{
char *cwd = buffer;
- /*
- * a lazy caller can pass a NULL returned from get_git_work_tree()
- * and rely on this function to return NULL.
- */
if (!dir)
return NULL;
if (!getcwd(buffer, size))