Skip to content

Commit a8aa0c6

Browse files
committed
Merge branch 'gvfs/master' into users/johasc/gvfs-2.10.1
This merge was performed simply to avoid merge conflicts in the Pull Request.
2 parents 311b9c9 + 44b51d5 commit a8aa0c6

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

merge-recursive.c

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
#include "submodule.h"
2525
#include "gvfs.h"
2626

27+
struct path_hashmap_entry {
28+
struct hashmap_entry entry;
29+
char path[FLEX_ARRAY];
30+
};
31+
32+
static unsigned int (*pathhash)(const char *path);
33+
static int (*pathcmp)(const char *a, const char *b);
34+
35+
static int path_hashmap_cmp(const void *a, const void *b, const void *key)
36+
{
37+
const struct path_hashmap_entry *one = a;
38+
const struct path_hashmap_entry *two = b;
39+
40+
return pathcmp(one->path, two->path);
41+
}
42+
2743
static void flush_output(struct merge_options *o)
2844
{
2945
if (o->buffer_output < 2 && o->obuf.len) {
@@ -315,29 +331,26 @@ static int save_files_dirs(const unsigned char *sha1,
315331
struct strbuf *base, const char *path,
316332
unsigned int mode, int stage, void *context)
317333
{
334+
struct path_hashmap_entry *entry;
335+
318336
int baselen = base->len;
319337
struct merge_options *o = context;
320338

321339
strbuf_addstr(base, path);
322340

323-
if (S_ISDIR(mode))
324-
string_list_insert(&o->current_directory_set, base->buf);
325-
else
326-
string_list_insert(&o->current_file_set, base->buf);
341+
FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
342+
hashmap_entry_init(entry, pathhash(entry->path));
343+
hashmap_add(&o->current_file_dir_set, entry);
327344

328345
strbuf_setlen(base, baselen);
329346
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
330347
}
331348

332-
static int get_files_dirs(struct merge_options *o, struct tree *tree)
349+
static void get_files_dirs(struct merge_options *o, struct tree *tree)
333350
{
334-
int n;
335351
struct pathspec match_all;
336352
memset(&match_all, 0, sizeof(match_all));
337-
if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
338-
return 0;
339-
n = o->current_file_set.nr + o->current_directory_set.nr;
340-
return n;
353+
read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o);
341354
}
342355

343356
/*
@@ -649,6 +662,7 @@ static void add_flattened_path(struct strbuf *out, const char *s)
649662

650663
static char *unique_path(struct merge_options *o, const char *path, const char *branch)
651664
{
665+
struct path_hashmap_entry *entry;
652666
struct strbuf newpath = STRBUF_INIT;
653667
int suffix = 0;
654668
size_t base_len;
@@ -657,14 +671,18 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
657671
add_flattened_path(&newpath, branch);
658672

659673
base_len = newpath.len;
660-
while (string_list_has_string(&o->current_file_set, newpath.buf) ||
661-
string_list_has_string(&o->current_directory_set, newpath.buf) ||
674+
FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
675+
hashmap_entry_init(entry, pathhash(entry->path));
676+
while (hashmap_get(&o->current_file_dir_set, entry, NULL) ||
662677
(!o->call_depth && file_exists(newpath.buf))) {
663678
strbuf_setlen(&newpath, base_len);
664679
strbuf_addf(&newpath, "_%d", suffix++);
680+
free(entry);
681+
FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
682+
hashmap_entry_init(entry, pathhash(entry->path));
665683
}
666684

667-
string_list_insert(&o->current_file_set, newpath.buf);
685+
hashmap_add(&o->current_file_dir_set, entry);
668686
return strbuf_detach(&newpath, NULL);
669687
}
670688

@@ -1933,8 +1951,9 @@ int merge_trees(struct merge_options *o,
19331951
if (unmerged_cache()) {
19341952
struct string_list *entries, *re_head, *re_merge;
19351953
int i;
1936-
string_list_clear(&o->current_file_set, 1);
1937-
string_list_clear(&o->current_directory_set, 1);
1954+
1955+
hashmap_init(&o->current_file_dir_set, path_hashmap_cmp, 512);
1956+
19381957
get_files_dirs(o, head);
19391958
get_files_dirs(o, merge);
19401959

@@ -1943,17 +1962,21 @@ int merge_trees(struct merge_options *o,
19431962
re_head = get_renames(o, head, common, head, merge, entries);
19441963
re_merge = get_renames(o, merge, common, head, merge, entries);
19451964
clean = process_renames(o, re_head, re_merge);
1946-
if (clean < 0)
1947-
return clean;
1965+
if (clean < 0) {
1966+
goto cleanup;
1967+
}
1968+
19481969
for (i = entries->nr-1; 0 <= i; i--) {
19491970
const char *path = entries->items[i].string;
19501971
struct stage_data *e = entries->items[i].util;
19511972
if (!e->processed) {
19521973
int ret = process_entry(o, path, e);
19531974
if (!ret)
19541975
clean = 0;
1955-
else if (ret < 0)
1956-
return ret;
1976+
else if (ret < 0) {
1977+
clean = ret;
1978+
goto cleanup;
1979+
}
19571980
}
19581981
}
19591982
for (i = 0; i < entries->nr; i++) {
@@ -1963,13 +1986,19 @@ int merge_trees(struct merge_options *o,
19631986
entries->items[i].string);
19641987
}
19651988

1989+
cleanup:
19661990
string_list_clear(re_merge, 0);
19671991
string_list_clear(re_head, 0);
19681992
string_list_clear(entries, 1);
1993+
1994+
hashmap_free(&o->current_file_dir_set, 1);
19691995

19701996
free(re_merge);
19711997
free(re_head);
19721998
free(entries);
1999+
2000+
if (clean < 0)
2001+
return clean;
19732002
}
19742003
else
19752004
clean = 1;
@@ -2167,8 +2196,10 @@ void init_merge_options(struct merge_options *o)
21672196
if (o->verbosity >= 5)
21682197
o->buffer_output = 0;
21692198
strbuf_init(&o->obuf, 0);
2170-
string_list_init(&o->current_file_set, 1);
2171-
string_list_init(&o->current_directory_set, 1);
2199+
2200+
pathhash = ignore_case ? strihash : strhash;
2201+
pathcmp = ignore_case ? strcasecmp : strcmp;
2202+
21722203
string_list_init(&o->df_conflict_file_set, 1);
21732204
}
21742205

merge-recursive.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ struct merge_options {
2525
int show_rename_progress;
2626
int call_depth;
2727
struct strbuf obuf;
28-
struct string_list current_file_set;
29-
struct string_list current_directory_set;
28+
struct hashmap current_file_dir_set;
3029
struct string_list df_conflict_file_set;
3130
};
3231

0 commit comments

Comments
 (0)