merge-recursive: move current_{file,directory}_set to struct merge_options
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Miklos Vajna committed
Sep 3, 2008 at 19:08 UTC
696ee23cc1817a5064780600374589d3a773a081
2 files changed
+34
-27
merge-recursive.c
+30
-27
@@ -77,9 +77,6 @@ struct stage_data
77
unsigned processed:1;
78
};
79
80
-static struct string_list current_file_set = {NULL, 0, 0, 1};
81
-static struct string_list current_directory_set = {NULL, 0, 0, 1};
82
-
80
static int show(struct merge_options *o, int v)
81
{
82
return (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;
@@ -232,25 +229,27 @@ static int save_files_dirs(const unsigned char *sha1,
229
{
230
int len = strlen(path);
231
char *newpath = xmalloc(baselen + len + 1);
232
+ struct merge_options *o = context;
233
+
234
memcpy(newpath, base, baselen);
235
memcpy(newpath + baselen, path, len);
236
newpath[baselen + len] = '\0';
237
238
if (S_ISDIR(mode))
240
- string_list_insert(newpath, ¤t_directory_set);
239
+ string_list_insert(newpath, &o->current_directory_set);
240
else
242
- string_list_insert(newpath, ¤t_file_set);
241
+ string_list_insert(newpath, &o->current_file_set);
242
free(newpath);
243
244
return READ_TREE_RECURSIVE;
245
}
246
248
-static int get_files_dirs(struct tree *tree)
247
+static int get_files_dirs(struct merge_options *o, struct tree *tree)
248
{
249
int n;
251
- if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs, NULL))
250
+ if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs, o))
251
return 0;
253
- n = current_file_set.nr + current_directory_set.nr;
252
+ n = o->current_file_set.nr + o->current_directory_set.nr;
253
return n;
254
}
255
@@ -434,7 +433,7 @@ static int remove_file(struct merge_options *o, int clean,
433
return 0;
434
}
435
437
-static char *unique_path(const char *path, const char *branch)
436
+static char *unique_path(struct merge_options *o, const char *path, const char *branch)
437
{
438
char *newpath = xmalloc(strlen(path) + 1 + strlen(branch) + 8 + 1);
439
int suffix = 0;
@@ -446,12 +445,12 @@ static char *unique_path(const char *path, const char *branch)
445
for (; *p; ++p)
446
if ('/' == *p)
447
*p = '_';
449
- while (string_list_has_string(¤t_file_set, newpath) ||
450
- string_list_has_string(¤t_directory_set, newpath) ||
448
+ while (string_list_has_string(&o->current_file_set, newpath) ||
449
+ string_list_has_string(&o->current_directory_set, newpath) ||
450
lstat(newpath, &st) == 0)
451
sprintf(p, "_%d", suffix++);
452
454
- string_list_insert(newpath, ¤t_file_set);
453
+ string_list_insert(newpath, &o->current_file_set);
454
return newpath;
455
}
456
@@ -716,14 +715,14 @@ static void conflict_rename_rename(struct merge_options *o,
715
const char *ren2_dst = ren2->pair->two->path;
716
const char *dst_name1 = ren1_dst;
717
const char *dst_name2 = ren2_dst;
719
- if (string_list_has_string(¤t_directory_set, ren1_dst)) {
720
- dst_name1 = del[delp++] = unique_path(ren1_dst, branch1);
718
+ if (string_list_has_string(&o->current_directory_set, ren1_dst)) {
719
+ dst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);
720
output(o, 1, "%s is a directory in %s adding as %s instead",
721
ren1_dst, branch2, dst_name1);
722
remove_file(o, 0, ren1_dst, 0);
723
}
725
- if (string_list_has_string(¤t_directory_set, ren2_dst)) {
726
- dst_name2 = del[delp++] = unique_path(ren2_dst, branch2);
724
+ if (string_list_has_string(&o->current_directory_set, ren2_dst)) {
725
+ dst_name2 = del[delp++] = unique_path(o, ren2_dst, branch2);
726
output(o, 1, "%s is a directory in %s adding as %s instead",
727
ren2_dst, branch1, dst_name2);
728
remove_file(o, 0, ren2_dst, 0);
@@ -749,7 +748,7 @@ static void conflict_rename_dir(struct merge_options *o,
748
struct rename *ren1,
749
const char *branch1)
750
{
752
- char *new_path = unique_path(ren1->pair->two->path, branch1);
751
+ char *new_path = unique_path(o, ren1->pair->two->path, branch1);
752
output(o, 1, "Renaming %s to %s instead", ren1->pair->one->path, new_path);
753
remove_file(o, 0, ren1->pair->two->path, 0);
754
update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);
@@ -762,8 +761,8 @@ static void conflict_rename_rename_2(struct merge_options *o,
761
struct rename *ren2,
762
const char *branch2)
763
{
765
- char *new_path1 = unique_path(ren1->pair->two->path, branch1);
766
- char *new_path2 = unique_path(ren2->pair->two->path, branch2);
764
+ char *new_path1 = unique_path(o, ren1->pair->two->path, branch1);
765
+ char *new_path2 = unique_path(o, ren2->pair->two->path, branch2);
766
output(o, 1, "Renaming %s to %s and %s to %s instead",
767
ren1->pair->one->path, new_path1,
768
ren2->pair->one->path, new_path2);
@@ -913,7 +912,7 @@ static int process_renames(struct merge_options *o,
912
913
try_merge = 0;
914
916
- if (string_list_has_string(¤t_directory_set, ren1_dst)) {
915
+ if (string_list_has_string(&o->current_directory_set, ren1_dst)) {
916
clean_merge = 0;
917
output(o, 1, "CONFLICT (rename/directory): Rename %s->%s in %s "
918
" directory %s added in %s",
@@ -935,7 +934,7 @@ static int process_renames(struct merge_options *o,
934
"%s added in %s",
935
ren1_src, ren1_dst, branch1,
936
ren1_dst, branch2);
938
- new_path = unique_path(ren1_dst, branch2);
937
+ new_path = unique_path(o, ren1_dst, branch2);
938
output(o, 1, "Adding as %s instead", new_path);
939
update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
940
} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {
@@ -1073,8 +1072,8 @@ static int process_entry(struct merge_options *o,
1072
sha = b_sha;
1073
conf = "directory/file";
1074
}
1076
- if (string_list_has_string(¤t_directory_set, path)) {
1077
- const char *new_path = unique_path(path, add_branch);
1075
+ if (string_list_has_string(&o->current_directory_set, path)) {
1076
+ const char *new_path = unique_path(o, path, add_branch);
1077
clean_merge = 0;
1078
output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
1079
"Adding %s as %s",
@@ -1165,10 +1164,10 @@ int merge_trees(struct merge_options *o,
1164
if (unmerged_cache()) {
1165
struct string_list *entries, *re_head, *re_merge;
1166
int i;
1168
- string_list_clear(¤t_file_set, 1);
1169
- string_list_clear(¤t_directory_set, 1);
1170
- get_files_dirs(head);
1171
- get_files_dirs(merge);
1167
+ string_list_clear(&o->current_file_set, 1);
1168
+ string_list_clear(&o->current_directory_set, 1);
1169
+ get_files_dirs(o, head);
1170
+ get_files_dirs(o, merge);
1171
1172
entries = get_unmerged();
1173
re_head = get_renames(o, head, common, head, merge, entries);
@@ -1374,4 +1373,8 @@ void init_merge_options(struct merge_options *o)
1373
if (o->verbosity >= 5)
1374
o->buffer_output = 0;
1375
strbuf_init(&o->obuf, 0);
1376
+ memset(&o->current_file_set, 0, sizeof(struct string_list));
1377
+ o->current_file_set.strdup_strings = 1;
1378
+ memset(&o->current_directory_set, 0, sizeof(struct string_list));
1379
+ o->current_directory_set.strdup_strings = 1;
1380
}
merge-recursive.h
+4
@@ -1,6 +1,8 @@
1
#ifndef MERGE_RECURSIVE_H
2
#define MERGE_RECURSIVE_H
3
4
+#include "string-list.h"
5
+
6
struct merge_options {
7
const char *branch1;
8
const char *branch2;
@@ -11,6 +13,8 @@ struct merge_options {
13
int merge_rename_limit;
14
int call_depth;
15
struct strbuf obuf;
16
+ struct string_list current_file_set;
17
+ struct string_list current_directory_set;
18
};
19
20
/* merge_trees() but with recursive ancestor consolidation */