merge-recursive: distinguish "removed" and "overwritten" messages
To limit the number of possible error messages, the error messages for the case would_lose_untracked_file and would_lose_orphaned in unpack_trees_options.msgs were handled with a single string, parameterized by an action string ("overwritten" or "removed"). Instead, we consider them as two different cases, with unparameterized string. This will make it easier to make separate lists sorted by error types later. Only the bind_overlap case still takes two %s parameters, but that's unavoidable. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Aug 11, 2010 at 10:38 UTC
08402b0409bc501deb97cf4388a78ee9f87092c6
3 files changed
+51
-32
merge-recursive.c
+8
-5
@@ -1197,13 +1197,16 @@ void set_porcelain_error_msgs(const char **msgs, const char *cmd)
1197
"Updating '%s' would lose untracked files in it. Aborting.";
1198
1199
if (advice_commit_before_merge)
1200
- msg = "Untracked working tree file '%%s' would be %%s by %s. Aborting"
1200
+ msg = "Untracked working tree file '%%s' would be %s by %s. Aborting"
1201
"Please move or remove them before you can %s.";
1202
else
1203
- msg = "Untracked working tree file '%%s' would be %%s by %s. Aborting";
1204
- tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 3);
1205
- sprintf(tmp, msg, cmd, cmd2);
1206
- msgs[ERROR_WOULD_LOSE_UNTRACKED] = tmp;
1203
+ msg = "Untracked working tree file '%%s' would be %s by %s. Aborting";
1204
+ tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
1205
+ sprintf(tmp, msg, "removed", cmd, cmd2);
1206
+ msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
1207
+ tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
1208
+ sprintf(tmp, msg, "overwritten", cmd, cmd2);
1209
+ msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
1210
}
1211
1212
int merge_trees(struct merge_options *o,
unpack-trees.c
+39
-25
@@ -26,8 +26,11 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
26
/* ERROR_NOT_UPTODATE_DIR */
27
"Updating '%s' would lose untracked files in it",
28
29
- /* ERROR_WOULD_LOSE_UNTRACKED */
30
- "Untracked working tree file '%s' would be %s by merge.",
29
+ /* ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN */
30
+ "Untracked working tree file '%s' would be overwritten by merge.",
31
+
32
+ /* ERROR_WOULD_LOSE_UNTRACKED_REMOVED */
33
+ "Untracked working tree file '%s' would be removed by merge.",
34
35
/* ERROR_BIND_OVERLAP */
36
"Entry '%s' overlaps with '%s'. Cannot bind.",
@@ -35,8 +38,11 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
38
/* ERROR_SPARSE_NOT_UPTODATE_FILE */
39
"Entry '%s' not uptodate. Cannot update sparse checkout.",
40
38
- /* ERROR_WOULD_LOSE_ORPHANED */
39
- "Working tree file '%s' would be %s by sparse checkout update.",
41
+ /* ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN */
42
+ "Working tree file '%s' would be overwritten by sparse checkout update.",
43
+
44
+ /* ERROR_WOULD_LOSE_ORPHANED_REMOVED */
45
+ "Working tree file '%s' would be removed by sparse checkout update.",
46
};
47
48
#define ERRORMSG(o,type) \
@@ -131,7 +137,7 @@ static int check_updates(struct unpack_trees_options *o)
137
}
138
139
static int verify_uptodate_sparse(struct cache_entry *ce, struct unpack_trees_options *o);
134
-static int verify_absent_sparse(struct cache_entry *ce, const char *action, struct unpack_trees_options *o);
140
+static int verify_absent_sparse(struct cache_entry *ce, enum unpack_trees_error_types, struct unpack_trees_options *o);
141
142
static int will_have_skip_worktree(const struct cache_entry *ce, struct unpack_trees_options *o)
143
{
@@ -174,7 +180,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
180
ce->ce_flags |= CE_WT_REMOVE;
181
}
182
if (was_skip_worktree && !ce_skip_worktree(ce)) {
177
- if (verify_absent_sparse(ce, "overwritten", o))
183
+ if (verify_absent_sparse(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
184
return -1;
185
ce->ce_flags |= CE_UPDATE;
186
}
@@ -859,7 +865,7 @@ static int same(struct cache_entry *a, struct cache_entry *b)
865
*/
866
static int verify_uptodate_1(struct cache_entry *ce,
867
struct unpack_trees_options *o,
862
- const char *error_msg)
868
+ enum unpack_trees_error_types error_type)
869
{
870
struct stat st;
871
@@ -884,7 +890,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
890
if (errno == ENOENT)
891
return 0;
892
return o->gently ? -1 :
887
- error(error_msg, ce->name);
893
+ error(ERRORMSG(o, error_type), ce->name);
894
}
895
896
static int verify_uptodate(struct cache_entry *ce,
@@ -892,13 +898,13 @@ static int verify_uptodate(struct cache_entry *ce,
898
{
899
if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
900
return 0;
895
- return verify_uptodate_1(ce, o, ERRORMSG(o, ERROR_NOT_UPTODATE_FILE));
901
+ return verify_uptodate_1(ce, o, ERROR_NOT_UPTODATE_FILE);
902
}
903
904
static int verify_uptodate_sparse(struct cache_entry *ce,
905
struct unpack_trees_options *o)
906
{
901
- return verify_uptodate_1(ce, o, ERRORMSG(o, ERROR_SPARSE_NOT_UPTODATE_FILE));
907
+ return verify_uptodate_1(ce, o, ERROR_SPARSE_NOT_UPTODATE_FILE);
908
}
909
910
static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_options *o)
@@ -914,13 +920,15 @@ static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_optio
920
* Currently, git does not checkout subprojects during a superproject
921
* checkout, so it is not going to overwrite anything.
922
*/
917
-static int verify_clean_submodule(struct cache_entry *ce, const char *action,
923
+static int verify_clean_submodule(struct cache_entry *ce,
924
+ enum unpack_trees_error_types error_type,
925
struct unpack_trees_options *o)
926
{
927
return 0;
928
}
929
923
-static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
930
+static int verify_clean_subdirectory(struct cache_entry *ce,
931
+ enum unpack_trees_error_types error_type,
932
struct unpack_trees_options *o)
933
{
934
/*
@@ -941,7 +949,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
949
*/
950
if (!hashcmp(sha1, ce->sha1))
951
return 0;
944
- return verify_clean_submodule(ce, action, o);
952
+ return verify_clean_submodule(ce, error_type, o);
953
}
954
955
/*
@@ -1010,9 +1018,9 @@ static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst,
1018
* We do not want to remove or overwrite a working tree file that
1019
* is not tracked, unless it is ignored.
1020
*/
1013
-static int verify_absent_1(struct cache_entry *ce, const char *action,
1014
- struct unpack_trees_options *o,
1015
- const char *error_msg)
1021
+static int verify_absent_1(struct cache_entry *ce,
1022
+ enum unpack_trees_error_types error_type,
1023
+ struct unpack_trees_options *o)
1024
{
1025
struct stat st;
1026
@@ -1050,7 +1058,7 @@ static int verify_absent_1(struct cache_entry *ce, const char *action,
1058
* files that are in "foo/" we would lose
1059
* them.
1060
*/
1053
- if (verify_clean_subdirectory(ce, action, o) < 0)
1061
+ if (verify_clean_subdirectory(ce, error_type, o) < 0)
1062
return -1;
1063
return 0;
1064
}
@@ -1067,22 +1075,28 @@ static int verify_absent_1(struct cache_entry *ce, const char *action,
1075
}
1076
1077
return o->gently ? -1 :
1070
- error(ERRORMSG(o, ERROR_WOULD_LOSE_UNTRACKED), ce->name, action);
1078
+ error(ERRORMSG(o, error_type), ce->name);
1079
}
1080
return 0;
1081
}
1074
-static int verify_absent(struct cache_entry *ce, const char *action,
1082
+static int verify_absent(struct cache_entry *ce,
1083
+ enum unpack_trees_error_types error_type,
1084
struct unpack_trees_options *o)
1085
{
1086
if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
1087
return 0;
1079
- return verify_absent_1(ce, action, o, ERRORMSG(o, ERROR_WOULD_LOSE_UNTRACKED));
1088
+ return verify_absent_1(ce, error_type, o);
1089
}
1090
1082
-static int verify_absent_sparse(struct cache_entry *ce, const char *action,
1091
+static int verify_absent_sparse(struct cache_entry *ce,
1092
+ enum unpack_trees_error_types error_type,
1093
struct unpack_trees_options *o)
1094
{
1085
- return verify_absent_1(ce, action, o, ERRORMSG(o, ERROR_WOULD_LOSE_ORPHANED));
1095
+ enum unpack_trees_error_types orphaned_error = error_type;
1096
+ if (orphaned_error == ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN)
1097
+ orphaned_error = ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN;
1098
+
1099
+ return verify_absent_1(ce, orphaned_error, o);
1100
}
1101
1102
static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
@@ -1091,7 +1105,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
1105
int update = CE_UPDATE;
1106
1107
if (!old) {
1094
- if (verify_absent(merge, "overwritten", o))
1108
+ if (verify_absent(merge, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
1109
return -1;
1110
invalidate_ce_path(merge, o);
1111
} else if (!(old->ce_flags & CE_CONFLICTED)) {
@@ -1129,7 +1143,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
1143
{
1144
/* Did it exist in the index? */
1145
if (!old) {
1132
- if (verify_absent(ce, "removed", o))
1146
+ if (verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_REMOVED, o))
1147
return -1;
1148
return 0;
1149
}
@@ -1278,7 +1292,7 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1292
if (index)
1293
return deleted_entry(index, index, o);
1294
if (ce && !head_deleted) {
1281
- if (verify_absent(ce, "removed", o))
1295
+ if (verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_REMOVED, o))
1296
return -1;
1297
}
1298
return 0;
unpack-trees.h
+4
-2
@@ -13,10 +13,12 @@ enum unpack_trees_error_types {
13
ERROR_WOULD_OVERWRITE = 0,
14
ERROR_NOT_UPTODATE_FILE,
15
ERROR_NOT_UPTODATE_DIR,
16
- ERROR_WOULD_LOSE_UNTRACKED,
16
+ ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN,
17
+ ERROR_WOULD_LOSE_UNTRACKED_REMOVED,
18
ERROR_BIND_OVERLAP,
19
ERROR_SPARSE_NOT_UPTODATE_FILE,
19
- ERROR_WOULD_LOSE_ORPHANED,
20
+ ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN,
21
+ ERROR_WOULD_LOSE_ORPHANED_REMOVED,
22
NB_UNPACK_TREES_ERROR_TYPES
23
};
24