Move set_porcelain_error_msgs to unpack-trees.c and rename it
The function is currently dealing only with error messages, but the intent of calling it is really to notify the unpack-tree mechanics that it is running in porcelain mode. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Sep 2, 2010 at 13:57 UTC
dc1166e685dc54946ea4600e962e56a965962ec2
6 files changed
+54
-54
builtin/checkout.c
+1
-1
@@ -373,7 +373,7 @@ static int merge_working_tree(struct checkout_opts *opts,
373
topts.src_index = &the_index;
374
topts.dst_index = &the_index;
375
376
- set_porcelain_error_msgs(topts.msgs, "checkout");
376
+ setup_unpack_trees_porcelain(topts.msgs, "checkout");
377
378
refresh_cache(REFRESH_QUIET);
379
builtin/merge.c
+1
-1
@@ -705,7 +705,7 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
705
opts.merge = 1;
706
opts.fn = twoway_merge;
707
opts.show_all_errors = 1;
708
- set_porcelain_error_msgs(opts.msgs, "merge");
708
+ setup_unpack_trees_porcelain(opts.msgs, "merge");
709
710
trees[nr_trees] = parse_tree_indirect(head);
711
if (!trees[nr_trees++])
merge-recursive.c
+1
-45
@@ -185,7 +185,7 @@ static int git_merge_trees(int index_only,
185
opts.fn = threeway_merge;
186
opts.src_index = &the_index;
187
opts.dst_index = &the_index;
188
- set_porcelain_error_msgs(opts.msgs, "merge");
188
+ setup_unpack_trees_porcelain(opts.msgs, "merge");
189
190
init_tree_desc_from_tree(t+0, common);
191
init_tree_desc_from_tree(t+1, head);
@@ -1178,50 +1178,6 @@ static int process_entry(struct merge_options *o,
1178
return clean_merge;
1179
}
1180
1181
-void set_porcelain_error_msgs(const char **msgs, const char *cmd)
1182
-{
1183
- const char *msg;
1184
- char *tmp;
1185
- const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
1186
- if (advice_commit_before_merge)
1187
- msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
1188
- "Please, commit your changes or stash them before you can %s.";
1189
- else
1190
- msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
1191
- tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
1192
- sprintf(tmp, msg, cmd, cmd2);
1193
- msgs[ERROR_WOULD_OVERWRITE] = tmp;
1194
- msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
1195
-
1196
- msgs[ERROR_NOT_UPTODATE_DIR] =
1197
- "Updating the following directories would lose untracked files in it:\n%s";
1198
-
1199
- if (advice_commit_before_merge)
1200
- msg = "The following untracked working tree files would be %s by %s:\n%%s"
1201
- "Please move or remove them before you can %s.";
1202
- else
1203
- msg = "The following untracked working tree files would be %s by %s:\n%%s";
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
- * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
1213
- * cannot easily display it as a list.
1214
- */
1215
- msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind.";
1216
-
1217
- msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
1218
- "Cannot update sparse checkout: the following entries are not up-to-date:\n%s";
1219
- msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
1220
- "The following Working tree files would be overwritten by sparse checkout update:\n%s";
1221
- msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
1222
- "The following Working tree files would be removed by sparse checkout update:\n%s";
1223
-}
1224
-
1181
int merge_trees(struct merge_options *o,
1182
struct tree *head,
1183
struct tree *merge,
merge-recursive.h
-6
@@ -23,12 +23,6 @@ struct merge_options {
23
struct string_list current_directory_set;
24
};
25
26
-/*
27
- * Sets the list of user-friendly error messages to be used by the
28
- * command "cmd" (either merge or checkout)
29
- */
30
-void set_porcelain_error_msgs(const char **msgs, const char *cmd);
31
-
26
/* merge_trees() but with recursive ancestor consolidation */
27
int merge_recursive(struct merge_options *o,
28
struct commit *h1,
unpack-trees.c
+45
-1
@@ -14,7 +14,7 @@
14
* read-tree. Non-scripted Porcelain is not required to use these messages
15
* and in fact are encouraged to reword them to better suit their particular
16
* situation better. See how "git checkout" and "git merge" replaces
17
- * them using set_porcelain_error_msgs(), for example.
17
+ * them using setup_unpack_trees_porcelain(), for example.
18
*/
19
const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
20
/* ERROR_WOULD_OVERWRITE */
@@ -50,6 +50,50 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
50
? ((o)->msgs[(type)]) \
51
: (unpack_plumbing_errors[(type)]) )
52
53
+void setup_unpack_trees_porcelain(const char **msgs, const char *cmd)
54
+{
55
+ const char *msg;
56
+ char *tmp;
57
+ const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
58
+ if (advice_commit_before_merge)
59
+ msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
60
+ "Please, commit your changes or stash them before you can %s.";
61
+ else
62
+ msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
63
+ tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
64
+ sprintf(tmp, msg, cmd, cmd2);
65
+ msgs[ERROR_WOULD_OVERWRITE] = tmp;
66
+ msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
67
+
68
+ msgs[ERROR_NOT_UPTODATE_DIR] =
69
+ "Updating the following directories would lose untracked files in it:\n%s";
70
+
71
+ if (advice_commit_before_merge)
72
+ msg = "The following untracked working tree files would be %s by %s:\n%%s"
73
+ "Please move or remove them before you can %s.";
74
+ else
75
+ msg = "The following untracked working tree files would be %s by %s:\n%%s";
76
+ tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
77
+ sprintf(tmp, msg, "removed", cmd, cmd2);
78
+ msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
79
+ tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
80
+ sprintf(tmp, msg, "overwritten", cmd, cmd2);
81
+ msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
82
+
83
+ /*
84
+ * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
85
+ * cannot easily display it as a list.
86
+ */
87
+ msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind.";
88
+
89
+ msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
90
+ "Cannot update sparse checkout: the following entries are not up-to-date:\n%s";
91
+ msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
92
+ "The following Working tree files would be overwritten by sparse checkout update:\n%s";
93
+ msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
94
+ "The following Working tree files would be removed by sparse checkout update:\n%s";
95
+}
96
+
97
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
98
unsigned int set, unsigned int clear)
99
{
unpack-trees.h
+6
@@ -22,6 +22,12 @@ enum unpack_trees_error_types {
22
NB_UNPACK_TREES_ERROR_TYPES
23
};
24
25
+/*
26
+ * Sets the list of user-friendly error messages to be used by the
27
+ * command "cmd" (either merge or checkout)
28
+ */
29
+void setup_unpack_trees_porcelain(const char **msgs, const char *cmd);
30
+
31
struct rejected_paths_list {
32
char *path;
33
struct rejected_paths_list *next;