config_set_store: rename some fields for consistency
The `seen` field is the actual length of the `offset` array, and the `offset_alloc` field records what was allocated (to avoid resizing wherever `seen` has to be incremented). Elsewhere, we use the convention `name` for the array, where `name` is descriptive enough to guess its purpose, `name_nr` for the actual length and `name_alloc` to record the maximum length without needing to resize. Let's make the names of the fields in question consistent with that convention. This will also help with the next steps where we will let the git_config_set() machinery use the config event stream that we just introduced. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Apr 9, 2018 at 10:32 UTC
668b9ade6bcafbed1577468902d27c05c17cf026
1 file changed
+31
-32
config.c
+31
-32
@@ -2294,10 +2294,9 @@ struct config_store_data {
2294
int do_not_match;
2295
regex_t *value_regex;
2296
int multi_replace;
2297
- size_t *offset;
2298
- unsigned int offset_alloc;
2297
+ size_t *seen;
2298
+ unsigned int seen_nr, seen_alloc;
2299
enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state;
2300
- unsigned int seen;
2300
};
2301
2302
static int matches(const char *key, const char *value,
@@ -2323,15 +2322,15 @@ static int store_aux(const char *key, const char *value, void *cb)
2322
switch (store->state) {
2323
case KEY_SEEN:
2324
if (matches(key, value, store)) {
2326
- if (store->seen == 1 && store->multi_replace == 0) {
2325
+ if (store->seen_nr == 1 && store->multi_replace == 0) {
2326
warning(_("%s has multiple values"), key);
2327
}
2328
2330
- ALLOC_GROW(store->offset, store->seen + 1,
2331
- store->offset_alloc);
2329
+ ALLOC_GROW(store->seen, store->seen_nr + 1,
2330
+ store->seen_alloc);
2331
2333
- store->offset[store->seen] = cf->do_ftell(cf);
2334
- store->seen++;
2332
+ store->seen[store->seen_nr] = cf->do_ftell(cf);
2333
+ store->seen_nr++;
2334
}
2335
break;
2336
case SECTION_SEEN:
@@ -2357,26 +2356,26 @@ static int store_aux(const char *key, const char *value, void *cb)
2356
* Do not increment matches: this is no match, but we
2357
* just made sure we are in the desired section.
2358
*/
2360
- ALLOC_GROW(store->offset, store->seen + 1,
2361
- store->offset_alloc);
2362
- store->offset[store->seen] = cf->do_ftell(cf);
2359
+ ALLOC_GROW(store->seen, store->seen_nr + 1,
2360
+ store->seen_alloc);
2361
+ store->seen[store->seen_nr] = cf->do_ftell(cf);
2362
/* fallthru */
2363
case SECTION_END_SEEN:
2364
case START:
2365
if (matches(key, value, store)) {
2367
- ALLOC_GROW(store->offset, store->seen + 1,
2368
- store->offset_alloc);
2369
- store->offset[store->seen] = cf->do_ftell(cf);
2366
+ ALLOC_GROW(store->seen, store->seen_nr + 1,
2367
+ store->seen_alloc);
2368
+ store->seen[store->seen_nr] = cf->do_ftell(cf);
2369
store->state = KEY_SEEN;
2371
- store->seen++;
2370
+ store->seen_nr++;
2371
} else {
2372
if (strrchr(key, '.') - key == store->baselen &&
2373
!strncmp(key, store->key, store->baselen)) {
2374
store->state = SECTION_SEEN;
2376
- ALLOC_GROW(store->offset,
2377
- store->seen + 1,
2378
- store->offset_alloc);
2379
- store->offset[store->seen] =
2375
+ ALLOC_GROW(store->seen,
2376
+ store->seen_nr + 1,
2377
+ store->seen_alloc);
2378
+ store->seen[store->seen_nr] =
2379
cf->do_ftell(cf);
2380
}
2381
}
@@ -2636,10 +2635,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2635
}
2636
}
2637
2639
- ALLOC_GROW(store.offset, 1, store.offset_alloc);
2640
- store.offset[0] = 0;
2638
+ ALLOC_GROW(store.seen, 1, store.seen_alloc);
2639
+ store.seen[0] = 0;
2640
store.state = START;
2642
- store.seen = 0;
2641
+ store.seen_nr = 0;
2642
2643
/*
2644
* After this, store.offset will contain the *end* offset
@@ -2667,8 +2666,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2666
}
2667
2668
/* if nothing to unset, or too many matches, error out */
2670
- if ((store.seen == 0 && value == NULL) ||
2671
- (store.seen > 1 && multi_replace == 0)) {
2669
+ if ((store.seen_nr == 0 && value == NULL) ||
2670
+ (store.seen_nr > 1 && multi_replace == 0)) {
2671
ret = CONFIG_NOTHING_SET;
2672
goto out_free;
2673
}
@@ -2699,19 +2698,19 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2698
goto out_free;
2699
}
2700
2702
- if (store.seen == 0)
2703
- store.seen = 1;
2701
+ if (store.seen_nr == 0)
2702
+ store.seen_nr = 1;
2703
2705
- for (i = 0, copy_begin = 0; i < store.seen; i++) {
2704
+ for (i = 0, copy_begin = 0; i < store.seen_nr; i++) {
2705
new_line = 0;
2707
- if (store.offset[i] == 0) {
2708
- store.offset[i] = copy_end = contents_sz;
2706
+ if (store.seen[i] == 0) {
2707
+ store.seen[i] = copy_end = contents_sz;
2708
} else if (store.state != KEY_SEEN) {
2710
- copy_end = store.offset[i];
2709
+ copy_end = store.seen[i];
2710
} else
2711
copy_end = find_beginning_of_line(
2712
contents, contents_sz,
2714
- store.offset[i], &new_line);
2713
+ store.seen[i], &new_line);
2714
2715
if (copy_end > 0 && contents[copy_end-1] != '\n')
2716
new_line = 1;
@@ -2725,7 +2724,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2724
write_str_in_full(fd, "\n") < 0)
2725
goto write_err_out;
2726
}
2728
- copy_begin = store.offset[i];
2727
+ copy_begin = store.seen[i];
2728
}
2729
2730
/* write the pair (value == NULL means unset) */