@matheusbsbs / matheus-bagliano / commits / 3055d78f97
Fork 0

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>

Clemens Buchacher committed Nov 15, 2010 at 20:52 UTC 3055d78f97da105acfc0e207266e902251d2949f
4 files changed +38 -42
t/t7607-merge-overwrite.sh
+16 -3
@@ -15,7 +15,9 @@ test_expect_success 'setup' '
15 git reset --hard c0 &&
16 mkdir sub &&
17 echo "sub/f" > sub/f &&
18 - git add sub/f &&
18 + mkdir sub2 &&
19 + echo "sub2/f" > sub2/f &&
20 + git add sub/f sub2/f &&
21 git commit -m sub &&
22 git tag sub &&
23 echo "VERY IMPORTANT CHANGES" > important
@@ -100,13 +102,24 @@ test_expect_success 'will not overwrite untracked subtree' '
102 test_cmp important sub/f/important
103 '
104
105 +cat >expect <<\EOF
106 +error: The following untracked working tree files would be overwritten by merge:
107 + sub
108 + sub2
109 +Please move or remove them before you can merge.
110 +EOF
111 +
112 test_expect_success 'will not overwrite untracked file in leading path' '
113 git reset --hard c0 &&
114 rm -rf sub &&
115 cp important sub &&
107 - test_must_fail git merge sub &&
116 + cp important sub2 &&
117 + test_must_fail git merge sub 2>out &&
118 + test_cmp out expect &&
119 test_path_is_missing .git/MERGE_HEAD &&
109 - test_cmp important sub
120 + test_cmp important sub &&
121 + test_cmp important sub2 &&
122 + rm -f sub sub2
123 '
124
125 test_expect_failure SYMLINKS 'will not overwrite untracked symlink in leading path' '
t/t7609-merge-co-error-msgs.sh
+8 -8
@@ -27,10 +27,10 @@ test_expect_success 'setup' '
27
28 cat >expect <<\EOF
29 error: The following untracked working tree files would be overwritten by merge:
30 - two
31 - three
32 - four
30 five
31 + four
32 + three
33 + two
34 Please move or remove them before you can merge.
35 EOF
36
@@ -49,9 +49,9 @@ test_expect_success 'untracked files overwritten by merge (fast and non-fast for
49
50 cat >expect <<\EOF
51 error: Your local changes to the following files would be overwritten by merge:
52 - two
53 - three
52 four
53 + three
54 + two
55 Please, commit your changes or stash them before you can merge.
56 error: The following untracked working tree files would be overwritten by merge:
57 five
@@ -68,8 +68,8 @@ test_expect_success 'untracked files or local changes ovewritten by merge' '
68
69 cat >expect <<\EOF
70 error: Your local changes to the following files would be overwritten by checkout:
71 - rep/two
71 rep/one
72 + rep/two
73 Please, commit your changes or stash them before you can switch branches.
74 EOF
75
@@ -89,8 +89,8 @@ test_expect_success 'cannot switch branches because of local changes' '
89
90 cat >expect <<\EOF
91 error: Your local changes to the following files would be overwritten by checkout:
92 - rep/two
92 rep/one
93 + rep/two
94 Please, commit your changes or stash them before you can switch branches.
95 EOF
96
@@ -102,8 +102,8 @@ test_expect_success 'not uptodate file porcelain checkout error' '
102
103 cat >expect <<\EOF
104 error: Updating the following directories would lose untracked files in it:
105 - rep2
105 rep
106 + rep2
107
108 EOF
109
unpack-trees.c
+11 -25
@@ -53,6 +53,7 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
53 void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
54 const char *cmd)
55 {
56 + int i;
57 const char **msgs = opts->msgs;
58 const char *msg;
59 char *tmp;
@@ -96,6 +97,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
97 "The following Working tree files would be removed by sparse checkout update:\n%s";
98
99 opts->show_all_errors = 1;
100 + /* rejected paths may not have a static buffer */
101 + for (i = 0; i < ARRAY_SIZE(opts->unpack_rejects); i++)
102 + opts->unpack_rejects[i].strdup_strings = 1;
103 }
104
105 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,
128 enum unpack_trees_error_types e,
129 const char *path)
130 {
127 - struct rejected_paths_list *newentry;
131 if (!o->show_all_errors)
132 return error(ERRORMSG(o, e), path);
133
@@ -132,45 +135,28 @@ static int add_rejected_path(struct unpack_trees_options *o,
135 * Otherwise, insert in a list for future display by
136 * display_error_msgs()
137 */
135 - newentry = xmalloc(sizeof(struct rejected_paths_list));
136 - newentry->path = (char *)path;
137 - newentry->next = o->unpack_rejects[e];
138 - o->unpack_rejects[e] = newentry;
138 + string_list_append(&o->unpack_rejects[e], path);
139 return -1;
140 }
141
142 -/*
143 - * free all the structures allocated for the error <e>
144 - */
145 -static void free_rejected_paths(struct unpack_trees_options *o,
146 - enum unpack_trees_error_types e)
147 -{
148 - while (o->unpack_rejects[e]) {
149 - struct rejected_paths_list *del = o->unpack_rejects[e];
150 - o->unpack_rejects[e] = o->unpack_rejects[e]->next;
151 - free(del);
152 - }
153 - free(o->unpack_rejects[e]);
154 -}
155 -
142 /*
143 * display all the error messages stored in a nice way
144 */
145 static void display_error_msgs(struct unpack_trees_options *o)
146 {
161 - int e;
147 + int e, i;
148 int something_displayed = 0;
149 for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
164 - if (o->unpack_rejects[e]) {
165 - struct rejected_paths_list *rp;
150 + struct string_list *rejects = &o->unpack_rejects[e];
151 + if (rejects->nr > 0) {
152 struct strbuf path = STRBUF_INIT;
153 something_displayed = 1;
168 - for (rp = o->unpack_rejects[e]; rp; rp = rp->next)
169 - strbuf_addf(&path, "\t%s\n", rp->path);
154 + for (i = 0; i < rejects->nr; i++)
155 + strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
156 error(ERRORMSG(o, e), path.buf);
157 strbuf_release(&path);
172 - free_rejected_paths(o, e);
158 }
159 + string_list_clear(rejects, 0);
160 }
161 if (something_displayed)
162 printf("Aborting\n");
unpack-trees.h
+3 -6
@@ -1,6 +1,8 @@
1 #ifndef UNPACK_TREES_H
2 #define UNPACK_TREES_H
3
4 +#include "string-list.h"
5 +
6 #define MAX_UNPACK_TREES 8
7
8 struct unpack_trees_options;
@@ -29,11 +31,6 @@ enum unpack_trees_error_types {
31 void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
32 const char *cmd);
33
32 -struct rejected_paths_list {
33 - char *path;
34 - struct rejected_paths_list *next;
35 -};
36 -
34 struct unpack_trees_options {
35 unsigned int reset,
36 merge,
@@ -59,7 +56,7 @@ struct unpack_trees_options {
56 * Store error messages in an array, each case
57 * corresponding to a error message type
58 */
62 - struct rejected_paths_list *unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
59 + struct string_list unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
60
61 int head_idx;
62 int merge_size;