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>
This commit is contained in:
parent
b1735b1ab7
commit
3055d78f97
@ -15,7 +15,9 @@ test_expect_success 'setup' '
|
|||||||
git reset --hard c0 &&
|
git reset --hard c0 &&
|
||||||
mkdir sub &&
|
mkdir sub &&
|
||||||
echo "sub/f" > sub/f &&
|
echo "sub/f" > sub/f &&
|
||||||
git add sub/f &&
|
mkdir sub2 &&
|
||||||
|
echo "sub2/f" > sub2/f &&
|
||||||
|
git add sub/f sub2/f &&
|
||||||
git commit -m sub &&
|
git commit -m sub &&
|
||||||
git tag sub &&
|
git tag sub &&
|
||||||
echo "VERY IMPORTANT CHANGES" > important
|
echo "VERY IMPORTANT CHANGES" > important
|
||||||
@ -100,13 +102,24 @@ test_expect_success 'will not overwrite untracked subtree' '
|
|||||||
test_cmp important sub/f/important
|
test_cmp important sub/f/important
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat >expect <<\EOF
|
||||||
|
error: The following untracked working tree files would be overwritten by merge:
|
||||||
|
sub
|
||||||
|
sub2
|
||||||
|
Please move or remove them before you can merge.
|
||||||
|
EOF
|
||||||
|
|
||||||
test_expect_success 'will not overwrite untracked file in leading path' '
|
test_expect_success 'will not overwrite untracked file in leading path' '
|
||||||
git reset --hard c0 &&
|
git reset --hard c0 &&
|
||||||
rm -rf sub &&
|
rm -rf sub &&
|
||||||
cp important sub &&
|
cp important sub &&
|
||||||
test_must_fail git merge sub &&
|
cp important sub2 &&
|
||||||
|
test_must_fail git merge sub 2>out &&
|
||||||
|
test_cmp out expect &&
|
||||||
test_path_is_missing .git/MERGE_HEAD &&
|
test_path_is_missing .git/MERGE_HEAD &&
|
||||||
test_cmp important sub
|
test_cmp important sub &&
|
||||||
|
test_cmp important sub2 &&
|
||||||
|
rm -f sub sub2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure SYMLINKS 'will not overwrite untracked symlink in leading path' '
|
test_expect_failure SYMLINKS 'will not overwrite untracked symlink in leading path' '
|
||||||
|
@ -27,10 +27,10 @@ test_expect_success 'setup' '
|
|||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
error: The following untracked working tree files would be overwritten by merge:
|
error: The following untracked working tree files would be overwritten by merge:
|
||||||
two
|
|
||||||
three
|
|
||||||
four
|
|
||||||
five
|
five
|
||||||
|
four
|
||||||
|
three
|
||||||
|
two
|
||||||
Please move or remove them before you can merge.
|
Please move or remove them before you can merge.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -49,9 +49,9 @@ test_expect_success 'untracked files overwritten by merge (fast and non-fast for
|
|||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
error: Your local changes to the following files would be overwritten by merge:
|
error: Your local changes to the following files would be overwritten by merge:
|
||||||
two
|
|
||||||
three
|
|
||||||
four
|
four
|
||||||
|
three
|
||||||
|
two
|
||||||
Please, commit your changes or stash them before you can merge.
|
Please, commit your changes or stash them before you can merge.
|
||||||
error: The following untracked working tree files would be overwritten by merge:
|
error: The following untracked working tree files would be overwritten by merge:
|
||||||
five
|
five
|
||||||
@ -68,8 +68,8 @@ test_expect_success 'untracked files or local changes ovewritten by merge' '
|
|||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
error: Your local changes to the following files would be overwritten by checkout:
|
error: Your local changes to the following files would be overwritten by checkout:
|
||||||
rep/two
|
|
||||||
rep/one
|
rep/one
|
||||||
|
rep/two
|
||||||
Please, commit your changes or stash them before you can switch branches.
|
Please, commit your changes or stash them before you can switch branches.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -89,8 +89,8 @@ test_expect_success 'cannot switch branches because of local changes' '
|
|||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
error: Your local changes to the following files would be overwritten by checkout:
|
error: Your local changes to the following files would be overwritten by checkout:
|
||||||
rep/two
|
|
||||||
rep/one
|
rep/one
|
||||||
|
rep/two
|
||||||
Please, commit your changes or stash them before you can switch branches.
|
Please, commit your changes or stash them before you can switch branches.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ test_expect_success 'not uptodate file porcelain checkout error' '
|
|||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
error: Updating the following directories would lose untracked files in it:
|
error: Updating the following directories would lose untracked files in it:
|
||||||
rep2
|
|
||||||
rep
|
rep
|
||||||
|
rep2
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
|
|||||||
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
|
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
|
||||||
const char *cmd)
|
const char *cmd)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
const char **msgs = opts->msgs;
|
const char **msgs = opts->msgs;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
char *tmp;
|
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";
|
"The following Working tree files would be removed by sparse checkout update:\n%s";
|
||||||
|
|
||||||
opts->show_all_errors = 1;
|
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,
|
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,
|
enum unpack_trees_error_types e,
|
||||||
const char *path)
|
const char *path)
|
||||||
{
|
{
|
||||||
struct rejected_paths_list *newentry;
|
|
||||||
if (!o->show_all_errors)
|
if (!o->show_all_errors)
|
||||||
return error(ERRORMSG(o, e), path);
|
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
|
* Otherwise, insert in a list for future display by
|
||||||
* display_error_msgs()
|
* display_error_msgs()
|
||||||
*/
|
*/
|
||||||
newentry = xmalloc(sizeof(struct rejected_paths_list));
|
string_list_append(&o->unpack_rejects[e], path);
|
||||||
newentry->path = (char *)path;
|
|
||||||
newentry->next = o->unpack_rejects[e];
|
|
||||||
o->unpack_rejects[e] = newentry;
|
|
||||||
return -1;
|
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
|
* display all the error messages stored in a nice way
|
||||||
*/
|
*/
|
||||||
static void display_error_msgs(struct unpack_trees_options *o)
|
static void display_error_msgs(struct unpack_trees_options *o)
|
||||||
{
|
{
|
||||||
int e;
|
int e, i;
|
||||||
int something_displayed = 0;
|
int something_displayed = 0;
|
||||||
for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
|
for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
|
||||||
if (o->unpack_rejects[e]) {
|
struct string_list *rejects = &o->unpack_rejects[e];
|
||||||
struct rejected_paths_list *rp;
|
if (rejects->nr > 0) {
|
||||||
struct strbuf path = STRBUF_INIT;
|
struct strbuf path = STRBUF_INIT;
|
||||||
something_displayed = 1;
|
something_displayed = 1;
|
||||||
for (rp = o->unpack_rejects[e]; rp; rp = rp->next)
|
for (i = 0; i < rejects->nr; i++)
|
||||||
strbuf_addf(&path, "\t%s\n", rp->path);
|
strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
|
||||||
error(ERRORMSG(o, e), path.buf);
|
error(ERRORMSG(o, e), path.buf);
|
||||||
strbuf_release(&path);
|
strbuf_release(&path);
|
||||||
free_rejected_paths(o, e);
|
|
||||||
}
|
}
|
||||||
|
string_list_clear(rejects, 0);
|
||||||
}
|
}
|
||||||
if (something_displayed)
|
if (something_displayed)
|
||||||
printf("Aborting\n");
|
printf("Aborting\n");
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef UNPACK_TREES_H
|
#ifndef UNPACK_TREES_H
|
||||||
#define UNPACK_TREES_H
|
#define UNPACK_TREES_H
|
||||||
|
|
||||||
|
#include "string-list.h"
|
||||||
|
|
||||||
#define MAX_UNPACK_TREES 8
|
#define MAX_UNPACK_TREES 8
|
||||||
|
|
||||||
struct unpack_trees_options;
|
struct unpack_trees_options;
|
||||||
@ -29,11 +31,6 @@ enum unpack_trees_error_types {
|
|||||||
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
|
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
|
||||||
const char *cmd);
|
const char *cmd);
|
||||||
|
|
||||||
struct rejected_paths_list {
|
|
||||||
char *path;
|
|
||||||
struct rejected_paths_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct unpack_trees_options {
|
struct unpack_trees_options {
|
||||||
unsigned int reset,
|
unsigned int reset,
|
||||||
merge,
|
merge,
|
||||||
@ -59,7 +56,7 @@ struct unpack_trees_options {
|
|||||||
* Store error messages in an array, each case
|
* Store error messages in an array, each case
|
||||||
* corresponding to a error message type
|
* corresponding to a error message type
|
||||||
*/
|
*/
|
||||||
struct rejected_paths_list *unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
|
struct string_list unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
|
||||||
|
|
||||||
int head_idx;
|
int head_idx;
|
||||||
int merge_size;
|
int merge_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user