Skip to content

Commit fc62e08

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 9365786 commit fc62e08

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
{
@@ -464,7 +464,7 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
464464
/* Get old_dir, skip if its directory isn't relevant. */
465465
dirname_munge(old_dir);
466466
if (info->relevant_source_dirs &&
467-
!strset_contains(info->relevant_source_dirs, old_dir))
467+
!strintmap_contains(info->relevant_source_dirs, old_dir))
468468
break;
469469

470470
/* Get new_dir */
@@ -509,7 +509,7 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
509509
}
510510
}
511511

512-
if (strset_contains(dirs_removed, old_dir))
512+
if (strintmap_contains(dirs_removed, old_dir))
513513
increment_count(info, old_dir, new_dir);
514514
else
515515
break;
@@ -527,8 +527,8 @@ static void update_dir_rename_counts(struct dir_rename_info *info,
527527
}
528528

529529
static void initialize_dir_rename_info(struct dir_rename_info *info,
530-
struct strset *relevant_sources,
531-
struct strset *dirs_removed,
530+
struct strintmap *relevant_sources,
531+
struct strintmap *dirs_removed,
532532
struct strmap *dir_rename_count)
533533
{
534534
struct hashmap_iter iter;
@@ -555,12 +555,13 @@ static void initialize_dir_rename_info(struct dir_rename_info *info,
555555
info->relevant_source_dirs = dirs_removed; /* might be NULL */
556556
} else {
557557
info->relevant_source_dirs = xmalloc(sizeof(struct strintmap));
558-
strset_init(info->relevant_source_dirs);
559-
strset_for_each_entry(relevant_sources, &iter, entry) {
558+
strintmap_init(info->relevant_source_dirs, 0 /* unused */);
559+
strintmap_for_each_entry(relevant_sources, &iter, entry) {
560560
char *dirname = get_dirname(entry->key);
561561
if (!dirs_removed ||
562-
strset_contains(dirs_removed, dirname))
563-
strset_add(info->relevant_source_dirs, dirname);
562+
strintmap_contains(dirs_removed, dirname))
563+
strintmap_set(info->relevant_source_dirs,
564+
dirname, 0 /* value irrelevant */);
564565
free(dirname);
565566
}
566567
}
@@ -624,7 +625,7 @@ void partial_clear_dir_rename_count(struct strmap *dir_rename_count)
624625
}
625626

626627
static void cleanup_dir_rename_info(struct dir_rename_info *info,
627-
struct strset *dirs_removed,
628+
struct strintmap *dirs_removed,
628629
int keep_dir_rename_count)
629630
{
630631
struct hashmap_iter iter;
@@ -644,7 +645,7 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
644645
/* relevant_source_dirs */
645646
if (info->relevant_source_dirs &&
646647
info->relevant_source_dirs != dirs_removed) {
647-
strset_clear(info->relevant_source_dirs);
648+
strintmap_clear(info->relevant_source_dirs);
648649
FREE_AND_NULL(info->relevant_source_dirs);
649650
}
650651

@@ -666,7 +667,7 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
666667
const char *source_dir = entry->key;
667668
struct strintmap *counts = entry->value;
668669

669-
if (!strset_contains(dirs_removed, source_dir)) {
670+
if (!strintmap_contains(dirs_removed, source_dir)) {
670671
string_list_append(&to_remove, source_dir);
671672
strintmap_clear(counts);
672673
continue;
@@ -770,8 +771,8 @@ static int idx_possible_rename(char *filename, struct dir_rename_info *info)
770771
static int find_basename_matches(struct diff_options *options,
771772
int minimum_score,
772773
struct dir_rename_info *info,
773-
struct strset *relevant_sources,
774-
struct strset *dirs_removed)
774+
struct strintmap *relevant_sources,
775+
struct strintmap *dirs_removed)
775776
{
776777
/*
777778
* When I checked in early 2020, over 76% of file renames in linux
@@ -863,7 +864,7 @@ static int find_basename_matches(struct diff_options *options,
863864

864865
/* Skip irrelevant sources */
865866
if (relevant_sources &&
866-
!strset_contains(relevant_sources, filename))
867+
!strintmap_contains(relevant_sources, filename))
867868
continue;
868869

869870
/*
@@ -994,7 +995,7 @@ static int find_renames(struct diff_score *mx,
994995
int minimum_score,
995996
int copies,
996997
struct dir_rename_info *info,
997-
struct strset *dirs_removed)
998+
struct strintmap *dirs_removed)
998999
{
9991000
int count = 0, i;
10001001

@@ -1019,7 +1020,7 @@ static int find_renames(struct diff_score *mx,
10191020
}
10201021

10211022
static void remove_unneeded_paths_from_src(int detecting_copies,
1022-
struct strset *interesting)
1023+
struct strintmap *interesting)
10231024
{
10241025
int i, new_num_src;
10251026

@@ -1061,7 +1062,7 @@ static void remove_unneeded_paths_from_src(int detecting_copies,
10611062
continue;
10621063

10631064
/* If we don't care about the source path, skip it */
1064-
if (interesting && !strset_contains(interesting, one->path))
1065+
if (interesting && !strintmap_contains(interesting, one->path))
10651066
continue;
10661067

10671068
if (new_num_src < i)
@@ -1074,8 +1075,8 @@ static void remove_unneeded_paths_from_src(int detecting_copies,
10741075
}
10751076

10761077
void diffcore_rename_extended(struct diff_options *options,
1077-
struct strset *relevant_sources,
1078-
struct strset *dirs_removed,
1078+
struct strintmap *relevant_sources,
1079+
struct strintmap *dirs_removed,
10791080
struct strmap *dir_rename_count)
10801081
{
10811082
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)