sha1-name.c: remove the_repo from diagnose_invalid_index_path()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 16, 2019 at 16:33 UTC 0488481e795e3cb683944e54bb0670a1c6e8b477
3 files changed +15 -4
dir.c
+8
@@ -2315,6 +2315,14 @@ int file_exists(const char *f)
2315 return lstat(f, &sb) == 0;
2316 }
2317
2318 +int repo_file_exists(struct repository *repo, const char *path)
2319 +{
2320 + if (repo != the_repository)
2321 + BUG("do not know how to check file existence in arbitrary repo");
2322 +
2323 + return file_exists(path);
2324 +}
2325 +
2326 static int cmp_icase(char a, char b)
2327 {
2328 if (a == b)
dir.h
+3 -1
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
269 int baselen, struct exclude_list *el, int srcpos);
270 extern void clear_exclude_list(struct exclude_list *el);
271 extern void clear_directory(struct dir_struct *dir);
272 -extern int file_exists(const char *);
272 +
273 +int repo_file_exists(struct repository *repo, const char *path);
274 +int file_exists(const char *);
275
276 extern int is_inside_dir(const char *dir);
277 extern int dir_inside_of(const char *subdir, const char *dir);
sha1-name.c
+4 -3
@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,
1664 }
1665
1666 /* Must be called only when :stage:filename doesn't exist. */
1667 -static void diagnose_invalid_index_path(struct index_state *istate,
1667 +static void diagnose_invalid_index_path(struct repository *r,
1668 int stage,
1669 const char *prefix,
1670 const char *filename)
1671 {
1672 + struct index_state *istate = r->index;
1673 const struct cache_entry *ce;
1674 int pos;
1675 unsigned namelen = strlen(filename);
@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,
1709 ce_stage(ce), filename);
1710 }
1711
1711 - if (file_exists(filename))
1712 + if (repo_file_exists(r, filename))
1713 die("Path '%s' exists on disk, but not in the index.", filename);
1714 if (is_missing_file_error(errno))
1715 die("Path '%s' does not exist (neither on disk nor in the index).",
@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1815 pos++;
1816 }
1817 if (only_to_die && name[1] && name[1] != '/')
1817 - diagnose_invalid_index_path(repo->index, stage, prefix, cp);
1818 + diagnose_invalid_index_path(repo, stage, prefix, cp);
1819 free(new_path);
1820 return -1;
1821 }