aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-07-04 23:40:38 -0700
committerJunio C Hamano <gitster@pobox.com>2012-07-04 23:40:38 -0700
commit60ad08bfdfe393fd86391e2f9e60e8ffccc78e5b (patch)
treee856039e5ad6149a72dfa5d9160ff1b1888dd23e /setup.c
parent348c44e78eb079fa97a575f8fb8c1fcac747efe5 (diff)
parent304970dd5d9e542e70eca98932c1e9f26770678e (diff)
downloadgit-60ad08bfdfe393fd86391e2f9e60e8ffccc78e5b.tar.gz
git-60ad08bfdfe393fd86391e2f9e60e8ffccc78e5b.tar.xz
Merge branch 'th/diff-no-index-fixes'
"git diff --no-index" did not correctly handle relative paths and did not give correct exit codes when run under "--quiet" option. * th/diff-no-index-fixes: diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes diff: handle relative paths in no-index
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/setup.c b/setup.c
index 994976946..e11497720 100644
--- a/setup.c
+++ b/setup.c
@@ -4,7 +4,7 @@
static int inside_git_dir = -1;
static int inside_work_tree = -1;
-char *prefix_path(const char *prefix, int len, const char *path)
+static char *prefix_path_gently(const char *prefix, int len, const char *path)
{
const char *orig = path;
char *sanitized;
@@ -31,7 +31,8 @@ char *prefix_path(const char *prefix, int len, const char *path)
if (strncmp(sanitized, work_tree, len) ||
(len > root_len && sanitized[len] != '\0' && sanitized[len] != '/')) {
error_out:
- die("'%s' is outside repository", orig);
+ free(sanitized);
+ return NULL;
}
if (sanitized[len] == '/')
len++;
@@ -40,6 +41,25 @@ char *prefix_path(const char *prefix, int len, const char *path)
return sanitized;
}
+char *prefix_path(const char *prefix, int len, const char *path)
+{
+ char *r = prefix_path_gently(prefix, len, path);
+ if (!r)
+ die("'%s' is outside repository", path);
+ return r;
+}
+
+int path_inside_repo(const char *prefix, const char *path)
+{
+ int len = prefix ? strlen(prefix) : 0;
+ char *r = prefix_path_gently(prefix, len, path);
+ if (r) {
+ free(r);
+ return 1;
+ }
+ return 0;
+}
+
int check_filename(const char *prefix, const char *arg)
{
const char *name;