Skip to content

Commit dc1166e

Browse files
moygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e935e62 commit dc1166e

File tree

6 files changed

+54
-54
lines changed

6 files changed

+54
-54
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static int merge_working_tree(struct checkout_opts *opts,
373373
topts.src_index = &the_index;
374374
topts.dst_index = &the_index;
375375

376-
set_porcelain_error_msgs(topts.msgs, "checkout");
376+
setup_unpack_trees_porcelain(topts.msgs, "checkout");
377377

378378
refresh_cache(REFRESH_QUIET);
379379

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
705705
opts.merge = 1;
706706
opts.fn = twoway_merge;
707707
opts.show_all_errors = 1;
708-
set_porcelain_error_msgs(opts.msgs, "merge");
708+
setup_unpack_trees_porcelain(opts.msgs, "merge");
709709

710710
trees[nr_trees] = parse_tree_indirect(head);
711711
if (!trees[nr_trees++])

merge-recursive.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static int git_merge_trees(int index_only,
185185
opts.fn = threeway_merge;
186186
opts.src_index = &the_index;
187187
opts.dst_index = &the_index;
188-
set_porcelain_error_msgs(opts.msgs, "merge");
188+
setup_unpack_trees_porcelain(opts.msgs, "merge");
189189

190190
init_tree_desc_from_tree(t+0, common);
191191
init_tree_desc_from_tree(t+1, head);
@@ -1178,50 +1178,6 @@ static int process_entry(struct merge_options *o,
11781178
return clean_merge;
11791179
}
11801180

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-
12251181
int merge_trees(struct merge_options *o,
12261182
struct tree *head,
12271183
struct tree *merge,

merge-recursive.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ struct merge_options {
2323
struct string_list current_directory_set;
2424
};
2525

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-
3226
/* merge_trees() but with recursive ancestor consolidation */
3327
int merge_recursive(struct merge_options *o,
3428
struct commit *h1,

unpack-trees.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* read-tree. Non-scripted Porcelain is not required to use these messages
1515
* and in fact are encouraged to reword them to better suit their particular
1616
* 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.
1818
*/
1919
const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
2020
/* ERROR_WOULD_OVERWRITE */
@@ -50,6 +50,50 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
5050
? ((o)->msgs[(type)]) \
5151
: (unpack_plumbing_errors[(type)]) )
5252

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+
5397
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
5498
unsigned int set, unsigned int clear)
5599
{

unpack-trees.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ enum unpack_trees_error_types {
2222
NB_UNPACK_TREES_ERROR_TYPES
2323
};
2424

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+
2531
struct rejected_paths_list {
2632
char *path;
2733
struct rejected_paths_list *next;

0 commit comments

Comments
 (0)