unpack-trees: keep gently check inside add_rejected_path

This basically follows the footsteps of 6a143aa2b2 (checkout -m: attempt merge when deletion of path was staged - 2014-08-12) where there gently check is moved inside reject_merge() so that callers do not accidentally forget it. add_rejected_path() has the same usage pattern. All call sites check gently first, then decide to call add_rejected_path() if needed. Move the check inside. 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 Mar 22, 2019 at 16:31 UTC 191e9d2c2dac2aaf8cb7db854cec48028addfece
1 file changed +9 -12
unpack-trees.c
+9 -12
@@ -219,6 +219,9 @@ static int add_rejected_path(struct unpack_trees_options *o,
219 enum unpack_trees_error_types e,
220 const char *path)
221 {
222 + if (o->gently)
223 + return -1;
224 +
225 if (!o->show_all_errors)
226 return error(ERRORMSG(o, e), super_prefixed(path));
227
@@ -268,8 +271,7 @@ static int check_submodule_move_head(const struct cache_entry *ce,
271 flags |= SUBMODULE_MOVE_HEAD_FORCE;
272
273 if (submodule_move_head(ce->name, old_id, new_id, flags))
271 - return o->gently ? -1 :
272 - add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
274 + return add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
275 return 0;
276 }
277
@@ -1645,8 +1647,7 @@ return_failed:
1647 static int reject_merge(const struct cache_entry *ce,
1648 struct unpack_trees_options *o)
1649 {
1648 - return o->gently ? -1 :
1649 - add_rejected_path(o, ERROR_WOULD_OVERWRITE, ce->name);
1650 + return add_rejected_path(o, ERROR_WOULD_OVERWRITE, ce->name);
1651 }
1652
1653 static int same(const struct cache_entry *a, const struct cache_entry *b)
@@ -1693,8 +1694,7 @@ static int verify_uptodate_1(const struct cache_entry *ce,
1694 int r = check_submodule_move_head(ce,
1695 "HEAD", oid_to_hex(&ce->oid), o);
1696 if (r)
1696 - return o->gently ? -1 :
1697 - add_rejected_path(o, error_type, ce->name);
1697 + return add_rejected_path(o, error_type, ce->name);
1698 return 0;
1699 }
1700
@@ -1712,8 +1712,7 @@ static int verify_uptodate_1(const struct cache_entry *ce,
1712 }
1713 if (errno == ENOENT)
1714 return 0;
1715 - return o->gently ? -1 :
1716 - add_rejected_path(o, error_type, ce->name);
1715 + return add_rejected_path(o, error_type, ce->name);
1716 }
1717
1718 int verify_uptodate(const struct cache_entry *ce,
@@ -1835,8 +1834,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
1834 d.exclude_per_dir = o->dir->exclude_per_dir;
1835 i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
1836 if (i)
1838 - return o->gently ? -1 :
1839 - add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
1837 + return add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
1838 free(pathbuf);
1839 return cnt;
1840 }
@@ -1905,8 +1903,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1903 return 0;
1904 }
1905
1908 - return o->gently ? -1 :
1909 - add_rejected_path(o, error_type, name);
1906 + return add_rejected_path(o, error_type, name);
1907 }
1908
1909 /*