Skip to content

Commit 811f151

Browse files
committed
merge-ort, diffcore-rename: tweak dirs_removed and relevant_source type
A future change will want to take advantage of being able to store a bit more information about removed directories and relevant sources. Since strset does not allow storing any data, and since we only need to store an enum value for each, switch these over to using strintmap. No functional changes yet. Signed-off-by: Elijah Newren <[email protected]>
1 parent 69d8e51 commit 811f151

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

diffcore-rename.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct dir_rename_info {
371371
struct strintmap idx_map;
372372
struct strmap dir_rename_guess;
373373
struct strmap *dir_rename_count;
374-
struct strset *relevant_source_dirs;
374+
struct strintmap *relevant_source_dirs;
375375
unsigned setup;
376376
};
377377

@@ -429,7 +429,7 @@ static void increment_count(struct dir_rename_info *info,
429429
}
430430

431431
static void update_dir_rename_counts(struct dir_rename_info *info,
432-
struct strset *dirs_removed,
432+
struct strintmap *dirs_removed,
433433
const char *oldname,
434434
const char *newname)
435435
{
@@ -458,7 +458,7 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
458458
/* Get old_dir, skip if its directory isn't relevant. */
459459
dirname_munge(old_dir);
460460
if (info->relevant_source_dirs &&
461-
!strset_contains(info->relevant_source_dirs, old_dir))
461+
!strintmap_contains(info->relevant_source_dirs, old_dir))
462462
break;
463463

464464
/* Get new_dir */
@@ -503,7 +503,7 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
503503
}
504504
}
505505

506-
if (strset_contains(dirs_removed, old_dir))
506+
if (strintmap_contains(dirs_removed, old_dir))
507507
increment_count(info, old_dir, new_dir);
508508
else
509509
break;
@@ -521,8 +521,8 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
521521
}
522522

523523
static void initialize_dir_rename_info(struct dir_rename_info *info,
524-
struct strset *relevant_sources,
525-
struct strset *dirs_removed,
524+
struct strintmap *relevant_sources,
525+
struct strintmap *dirs_removed,
526526
struct strmap *dir_rename_count)
527527
{
528528
struct hashmap_iter iter;
@@ -548,12 +548,13 @@ static void initialize_dir_rename_info(struct dir_rename_info *info,
548548
info->relevant_source_dirs = dirs_removed; /* might be NULL */
549549
} else {
550550
info->relevant_source_dirs = xmalloc(sizeof(struct strintmap));
551-
strset_init(info->relevant_source_dirs);
552-
strset_for_each_entry(relevant_sources, &iter, entry) {
551+
strintmap_init(info->relevant_source_dirs, 0 /* unused */);
552+
strintmap_for_each_entry(relevant_sources, &iter, entry) {
553553
char *dirname = get_dirname(entry->key);
554554
if (!dirs_removed ||
555-
strset_contains(dirs_removed, dirname))
556-
strset_add(info->relevant_source_dirs, dirname);
555+
strintmap_contains(dirs_removed, dirname))
556+
strintmap_set(info->relevant_source_dirs,
557+
dirname, 0 /* value irrelevant */);
557558
free(dirname);
558559
}
559560
}
@@ -617,7 +618,7 @@ void partial_clear_dir_rename_count(struct strmap *dir_rename_count)
617618
}
618619

619620
static void cleanup_dir_rename_info(struct dir_rename_info *info,
620-
struct strset *dirs_removed,
621+
struct strintmap *dirs_removed,
621622
int keep_dir_rename_count)
622623
{
623624
struct hashmap_iter iter;
@@ -635,7 +636,7 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
635636
/* relevant_source_dirs */
636637
if (info->relevant_source_dirs &&
637638
info->relevant_source_dirs != dirs_removed) {
638-
strset_clear(info->relevant_source_dirs);
639+
strintmap_clear(info->relevant_source_dirs);
639640
FREE_AND_NULL(info->relevant_source_dirs);
640641
}
641642

@@ -657,7 +658,7 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
657658
const char *source_dir = entry->key;
658659
struct strintmap *counts = entry->value;
659660

660-
if (!strset_contains(dirs_removed, source_dir)) {
661+
if (!strintmap_contains(dirs_removed, source_dir)) {
661662
string_list_append(&to_remove, source_dir);
662663
strintmap_clear(counts);
663664
continue;
@@ -735,8 +736,8 @@ static int find_basename_matches(struct diff_options *options,
735736
int minimum_score,
736737
int num_src,
737738
struct dir_rename_info *info,
738-
struct strset *relevant_sources,
739-
struct strset *dirs_removed)
739+
struct strintmap *relevant_sources,
740+
struct strintmap *dirs_removed)
740741
{
741742
/*
742743
* When I checked, over 76% of file renames in linux just moved
@@ -825,7 +826,7 @@ static int find_basename_matches(struct diff_options *options,
825826

826827
/* Skip irrelevant sources */
827828
if (relevant_sources &&
828-
!strset_contains(relevant_sources, filename))
829+
!strintmap_contains(relevant_sources, filename))
829830
continue;
830831

831832
/* Get the basename */
@@ -954,7 +955,7 @@ static int find_renames(struct diff_score *mx,
954955
int minimum_score,
955956
int copies,
956957
struct dir_rename_info *info,
957-
struct strset *dirs_removed)
958+
struct strintmap *dirs_removed)
958959
{
959960
int count = 0, i;
960961

@@ -979,7 +980,7 @@ static int find_renames(struct diff_score *mx,
979980
}
980981

981982
static void remove_unneeded_paths_from_src(int detecting_copies,
982-
struct strset *interesting)
983+
struct strintmap *interesting)
983984
{
984985
int i, new_num_src;
985986

@@ -1021,7 +1022,7 @@ static void remove_unneeded_paths_from_src(int detecting_copies,
10211022
continue;
10221023

10231024
/* If we don't care about the source path, skip it */
1024-
if (interesting && !strset_contains(interesting, one->path))
1025+
if (interesting && !strintmap_contains(interesting, one->path))
10251026
continue;
10261027

10271028
if (new_num_src < i)
@@ -1034,8 +1035,8 @@ static void remove_unneeded_paths_from_src(int detecting_copies,
10341035
}
10351036

10361037
void diffcore_rename_extended(struct diff_options *options,
1037-
struct strset *relevant_sources,
1038-
struct strset *dirs_removed,
1038+
struct strintmap *relevant_sources,
1039+
struct strintmap *dirs_removed,
10391040
struct strmap *dir_rename_count)
10401041
{
10411042
int detect_rename = options->detect_rename;

diffcore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
struct diff_options;
1010
struct repository;
11+
struct strintmap;
1112
struct strmap;
12-
struct strset;
1313
struct userdiff_driver;
1414

1515
/* This header file is internal between diff.c and its diff transformers
@@ -166,8 +166,8 @@ void partial_clear_dir_rename_count(struct strmap *dir_rename_count);
166166
void diffcore_break(struct repository *, int);
167167
void diffcore_rename(struct diff_options *);
168168
void diffcore_rename_extended(struct diff_options *options,
169-
struct strset *relevant_sources,
170-
struct strset *dirs_removed,
169+
struct strintmap *relevant_sources,
170+
struct strintmap *dirs_removed,
171171
struct strmap *dir_rename_count);
172172
void diffcore_merge_broken(void);
173173
void diffcore_pickaxe(struct diff_options *);

merge-ort.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct rename_info {
7474
/*
7575
* dirs_removed: directories removed on a given side of history.
7676
*/
77-
struct strset dirs_removed[3];
77+
struct strintmap dirs_removed[3];
7878

7979
/*
8080
* dir_rename_count: tracking where parts of a directory were renamed to
@@ -106,7 +106,7 @@ struct rename_info {
106106
* If neither of those are true, we can skip rename detection for
107107
* that path.
108108
*/
109-
struct strset relevant_sources[3];
109+
struct strintmap relevant_sources[3];
110110

111111
/*
112112
* dir_rename_mask:
@@ -362,8 +362,8 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
362362
int i;
363363
void (*strmap_func)(struct strmap *, int) =
364364
reinitialize ? strmap_partial_clear : strmap_clear;
365-
void (*strset_func)(struct strset *) =
366-
reinitialize ? strset_partial_clear : strset_clear;
365+
void (*strintmap_func)(struct strintmap *) =
366+
reinitialize ? strintmap_partial_clear : strintmap_clear;
367367

368368
/*
369369
* We marked opti->paths with strdup_strings = 0, so that we
@@ -395,15 +395,15 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
395395

396396
/* Free memory used by various renames maps */
397397
for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) {
398-
strset_func(&renames->dirs_removed[i]);
398+
strintmap_func(&renames->dirs_removed[i]);
399399

400400
partial_clear_dir_rename_count(&renames->dir_rename_count[i]);
401401
if (!reinitialize)
402402
strmap_clear(&renames->dir_rename_count[i], 1);
403403

404404
strmap_func(&renames->dir_renames[i], 0);
405405

406-
strset_func(&renames->relevant_sources[i]);
406+
strintmap_func(&renames->relevant_sources[i]);
407407
}
408408

409409
if (!reinitialize) {
@@ -675,7 +675,7 @@ static void add_pair(struct merge_options *opt,
675675
unsigned location_relevant = (dir_rename_mask == 0x07);
676676

677677
if (content_relevant || location_relevant)
678-
strset_add(&renames->relevant_sources[side], pathname);
678+
strintmap_set(&renames->relevant_sources[side], pathname, 1);
679679
}
680680

681681
one = alloc_filespec(pathname);
@@ -731,9 +731,9 @@ static void collect_rename_info(struct merge_options *opt,
731731
/* absent_mask = 0x07 - dirmask; sides = absent_mask/2 */
732732
unsigned sides = (0x07 - dirmask)/2;
733733
if (sides & 1)
734-
strset_add(&renames->dirs_removed[1], fullname);
734+
strintmap_set(&renames->dirs_removed[1], fullname, 1);
735735
if (sides & 2)
736-
strset_add(&renames->dirs_removed[2], fullname);
736+
strintmap_set(&renames->dirs_removed[2], fullname, 1);
737737
}
738738

739739
if (filemask == 0 || filemask == 7)
@@ -2162,7 +2162,7 @@ static inline int possible_side_renames(struct rename_info *renames,
21622162
unsigned side_index)
21632163
{
21642164
return renames->pairs[side_index].nr > 0 &&
2165-
!strset_empty(&renames->relevant_sources[side_index]);
2165+
!strintmap_empty(&renames->relevant_sources[side_index]);
21662166
}
21672167

21682168
static inline int possible_renames(struct rename_info *renames)
@@ -3447,14 +3447,14 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
34473447
/* Initialization of various renames fields */
34483448
renames = &opt->priv->renames;
34493449
for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
3450-
strset_init_with_options(&renames->dirs_removed[i],
3451-
NULL, 0);
3450+
strintmap_init_with_options(&renames->dirs_removed[i],
3451+
0, NULL, 0);
34523452
strmap_init_with_options(&renames->dir_rename_count[i],
34533453
NULL, 1);
34543454
strmap_init_with_options(&renames->dir_renames[i],
34553455
NULL, 0);
3456-
strset_init_with_options(&renames->relevant_sources[i],
3457-
NULL, 0);
3456+
strintmap_init_with_options(&renames->relevant_sources[i],
3457+
0, NULL, 0);
34583458
}
34593459

34603460
/*

0 commit comments

Comments
 (0)