summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2010-11-15 20:52:19 +0100
committerJunio C Hamano <gitster@pobox.com>2010-11-15 15:05:34 -0800
commit7980872d4ef3ce24329cbdb6d61dc2ed48cbf1c5 (patch)
tree15224e4692f6adf3be1f1ef945583aa9de0adb42 /unpack-trees.c
parentf66caaf9c8e0feb840a439a58e165b963aec79cf (diff)
downloadgit-7980872d4ef3ce24329cbdb6d61dc2ed48cbf1c5.tar.gz
use persistent memory for rejected paths
An aborted merge prints the list of rejected paths as part of the error message. Since commit f66caaf9 (do not overwrite files in leading path), some of those paths do not have static buffers, so we have to keep a copy. Use string_list's to accomplish this. This changes the order of the list to the order in which the paths are processed. Previously, it was reversed. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 6816113420..d5a453079a 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -53,6 +53,7 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
const char *cmd)
{
+ int i;
const char **msgs = opts->msgs;
const char *msg;
char *tmp;
@@ -96,6 +97,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
"The following Working tree files would be removed by sparse checkout update:\n%s";
opts->show_all_errors = 1;
+ /* rejected paths may not have a static buffer */
+ for (i = 0; i < ARRAY_SIZE(opts->unpack_rejects); i++)
+ opts->unpack_rejects[i].strdup_strings = 1;
}
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
@@ -124,7 +128,6 @@ static int add_rejected_path(struct unpack_trees_options *o,
enum unpack_trees_error_types e,
const char *path)
{
- struct rejected_paths_list *newentry;
if (!o->show_all_errors)
return error(ERRORMSG(o, e), path);
@@ -132,45 +135,28 @@ static int add_rejected_path(struct unpack_trees_options *o,
* Otherwise, insert in a list for future display by
* display_error_msgs()
*/
- newentry = xmalloc(sizeof(struct rejected_paths_list));
- newentry->path = (char *)path;
- newentry->next = o->unpack_rejects[e];
- o->unpack_rejects[e] = newentry;
+ string_list_append(&o->unpack_rejects[e], path);
return -1;
}
/*
- * free all the structures allocated for the error <e>
- */
-static void free_rejected_paths(struct unpack_trees_options *o,
- enum unpack_trees_error_types e)
-{
- while (o->unpack_rejects[e]) {
- struct rejected_paths_list *del = o->unpack_rejects[e];
- o->unpack_rejects[e] = o->unpack_rejects[e]->next;
- free(del);
- }
- free(o->unpack_rejects[e]);
-}
-
-/*
* display all the error messages stored in a nice way
*/
static void display_error_msgs(struct unpack_trees_options *o)
{
- int e;
+ int e, i;
int something_displayed = 0;
for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
- if (o->unpack_rejects[e]) {
- struct rejected_paths_list *rp;
+ struct string_list *rejects = &o->unpack_rejects[e];
+ if (rejects->nr > 0) {
struct strbuf path = STRBUF_INIT;
something_displayed = 1;
- for (rp = o->unpack_rejects[e]; rp; rp = rp->next)
- strbuf_addf(&path, "\t%s\n", rp->path);
+ for (i = 0; i < rejects->nr; i++)
+ strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
error(ERRORMSG(o, e), path.buf);
strbuf_release(&path);
- free_rejected_paths(o, e);
}
+ string_list_clear(rejects, 0);
}
if (something_displayed)
printf("Aborting\n");