summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-08-01 19:26:59 +0100
committerJunio C Hamano <gitster@pobox.com>2007-08-01 11:34:13 -0700
commit420acb31acbfbd78e0c35ac0c614de8717daed0a (patch)
treeab2a1bb98e4afeb392d2d0cbd9075f9ba0fb3962
parente90fdc39b6903502192b2dd11e5503cea721a1ad (diff)
downloadgit-420acb31acbfbd78e0c35ac0c614de8717daed0a.tar.gz
get_relative_cwd(): clarify why it handles dir == NULL
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>
-rw-r--r--dir.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index b3329f41b2..eb6c3abd30 100644
--- a/dir.c
+++ b/dir.c
@@ -646,16 +646,21 @@ file_exists(const char *f)
/*
* 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))