add function check_ok_to_remove()
This wraps some inline code into the function check_ok_to_remove(), which will later be used for leading path components as well. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Clemens Buchacher committed
Oct 9, 2010 at 15:52 UTC
6838d1ad6b52c95c02de4c476aae2192050ac2c9
1 file changed
+58
-49
unpack-trees.c
+58
-49
@@ -1127,14 +1127,65 @@ static int verify_clean_subdirectory(struct cache_entry *ce,
1127
* See if we can find a case-insensitive match in the index that also
1128
* matches the stat information, and assume it's that other file!
1129
*/
1130
-static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst, struct stat *st)
1130
+static int icase_exists(struct unpack_trees_options *o, const char *name, int len, struct stat *st)
1131
{
1132
struct cache_entry *src;
1133
1134
- src = index_name_exists(o->src_index, dst->name, ce_namelen(dst), 1);
1134
+ src = index_name_exists(o->src_index, name, len, 1);
1135
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
1136
}
1137
1138
+static int check_ok_to_remove(const char *name, int len, int dtype,
1139
+ struct cache_entry *ce, struct stat *st,
1140
+ enum unpack_trees_error_types error_type,
1141
+ struct unpack_trees_options *o)
1142
+{
1143
+ struct cache_entry *result;
1144
+
1145
+ /*
1146
+ * It may be that the 'lstat()' succeeded even though
1147
+ * target 'ce' was absent, because there is an old
1148
+ * entry that is different only in case..
1149
+ *
1150
+ * Ignore that lstat() if it matches.
1151
+ */
1152
+ if (ignore_case && icase_exists(o, name, len, st))
1153
+ return 0;
1154
+
1155
+ if (o->dir && excluded(o->dir, name, &dtype))
1156
+ /*
1157
+ * ce->name is explicitly excluded, so it is Ok to
1158
+ * overwrite it.
1159
+ */
1160
+ return 0;
1161
+ if (S_ISDIR(st->st_mode)) {
1162
+ /*
1163
+ * We are checking out path "foo" and
1164
+ * found "foo/." in the working tree.
1165
+ * This is tricky -- if we have modified
1166
+ * files that are in "foo/" we would lose
1167
+ * them.
1168
+ */
1169
+ if (verify_clean_subdirectory(ce, error_type, o) < 0)
1170
+ return -1;
1171
+ return 0;
1172
+ }
1173
+
1174
+ /*
1175
+ * The previous round may already have decided to
1176
+ * delete this path, which is in a subdirectory that
1177
+ * is being replaced with a blob.
1178
+ */
1179
+ result = index_name_exists(&o->result, name, len, 0);
1180
+ if (result) {
1181
+ if (result->ce_flags & CE_REMOVE)
1182
+ return 0;
1183
+ }
1184
+
1185
+ return o->gently ? -1 :
1186
+ add_rejected_path(o, error_type, name);
1187
+}
1188
+
1189
/*
1190
* We do not want to remove or overwrite a working tree file that
1191
* is not tracked, unless it is ignored.
@@ -1151,55 +1202,13 @@ static int verify_absent_1(struct cache_entry *ce,
1202
if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
1203
return 0;
1204
1154
- if (!lstat(ce->name, &st)) {
1155
- int dtype = ce_to_dtype(ce);
1156
- struct cache_entry *result;
1157
-
1158
- /*
1159
- * It may be that the 'lstat()' succeeded even though
1160
- * target 'ce' was absent, because there is an old
1161
- * entry that is different only in case..
1162
- *
1163
- * Ignore that lstat() if it matches.
1164
- */
1165
- if (ignore_case && icase_exists(o, ce, &st))
1166
- return 0;
1167
-
1168
- if (o->dir && excluded(o->dir, ce->name, &dtype))
1169
- /*
1170
- * ce->name is explicitly excluded, so it is Ok to
1171
- * overwrite it.
1172
- */
1173
- return 0;
1174
- if (S_ISDIR(st.st_mode)) {
1175
- /*
1176
- * We are checking out path "foo" and
1177
- * found "foo/." in the working tree.
1178
- * This is tricky -- if we have modified
1179
- * files that are in "foo/" we would lose
1180
- * them.
1181
- */
1182
- if (verify_clean_subdirectory(ce, error_type, o) < 0)
1183
- return -1;
1184
- return 0;
1185
- }
1186
-
1187
- /*
1188
- * The previous round may already have decided to
1189
- * delete this path, which is in a subdirectory that
1190
- * is being replaced with a blob.
1191
- */
1192
- result = index_name_exists(&o->result, ce->name, ce_namelen(ce), 0);
1193
- if (result) {
1194
- if (result->ce_flags & CE_REMOVE)
1195
- return 0;
1196
- }
1197
-
1198
- return o->gently ? -1 :
1199
- add_rejected_path(o, error_type, ce->name);
1200
- }
1205
+ if (!lstat(ce->name, &st))
1206
+ return check_ok_to_remove(ce->name, ce_namelen(ce),
1207
+ ce_to_dtype(ce), ce, &st,
1208
+ error_type, o);
1209
return 0;
1210
}
1211
+
1212
static int verify_absent(struct cache_entry *ce,
1213
enum unpack_trees_error_types error_type,
1214
struct unpack_trees_options *o)