Git fork

Merge branch 'jc/strbuf-split'

Arrays of strbuf is often a wrong data structure to use, and
strbuf_split*() family of functions that create them often have
better alternatives.

Update several code paths and replace strbuf_split*().

* jc/strbuf-split:
trace2: do not use strbuf_split*()
trace2: trim_trailing_newline followed by trim is a no-op
sub-process: do not use strbuf_split*()
environment: do not use strbuf_split*()
config: do not use strbuf_split()
notes: do not use strbuf_split*()
merge-tree: do not use strbuf_split*()
clean: do not use strbuf_split*() [part 2]
clean: do not pass the whole structure when it is not necessary
clean: do not use strbuf_split*() [part 1]
clean: do not pass strbuf by value
wt-status: avoid strbuf_split*()

+129 -166
+36 -38
builtin/clean.c
··· 478 */ 479 static int parse_choice(struct menu_stuff *menu_stuff, 480 int is_single, 481 - struct strbuf input, 482 int **chosen) 483 { 484 - struct strbuf **choice_list, **ptr; 485 int nr = 0; 486 int i; 487 488 - if (is_single) { 489 - choice_list = strbuf_split_max(&input, '\n', 0); 490 - } else { 491 - char *p = input.buf; 492 - do { 493 - if (*p == ',') 494 - *p = ' '; 495 - } while (*p++); 496 - choice_list = strbuf_split_max(&input, ' ', 0); 497 - } 498 499 - for (ptr = choice_list; *ptr; ptr++) { 500 - char *p; 501 - int choose = 1; 502 int bottom = 0, top = 0; 503 int is_range, is_number; 504 505 - strbuf_trim(*ptr); 506 - if (!(*ptr)->len) 507 continue; 508 509 /* Input that begins with '-'; unchoose */ 510 - if (*(*ptr)->buf == '-') { 511 choose = 0; 512 - strbuf_remove((*ptr), 0, 1); 513 } 514 515 is_range = 0; 516 is_number = 1; 517 - for (p = (*ptr)->buf; *p; p++) { 518 if ('-' == *p) { 519 if (!is_range) { 520 is_range = 1; ··· 532 } 533 534 if (is_number) { 535 - bottom = atoi((*ptr)->buf); 536 top = bottom; 537 } else if (is_range) { 538 - bottom = atoi((*ptr)->buf); 539 /* a range can be specified like 5-7 or 5- */ 540 - if (!*(strchr((*ptr)->buf, '-') + 1)) 541 top = menu_stuff->nr; 542 else 543 - top = atoi(strchr((*ptr)->buf, '-') + 1); 544 - } else if (!strcmp((*ptr)->buf, "*")) { 545 bottom = 1; 546 top = menu_stuff->nr; 547 } else { 548 - bottom = find_unique((*ptr)->buf, menu_stuff); 549 top = bottom; 550 } 551 552 if (top <= 0 || bottom <= 0 || top > menu_stuff->nr || bottom > top || 553 (is_single && bottom != top)) { 554 clean_print_color(CLEAN_COLOR_ERROR); 555 - printf(_("Huh (%s)?\n"), (*ptr)->buf); 556 clean_print_color(CLEAN_COLOR_RESET); 557 continue; 558 } ··· 561 (*chosen)[i-1] = choose; 562 } 563 564 - strbuf_list_free(choice_list); 565 566 for (i = 0; i < menu_stuff->nr; i++) 567 nr += (*chosen)[i]; ··· 631 632 nr = parse_choice(stuff, 633 opts->flags & MENU_OPTS_SINGLETON, 634 - choice, 635 &chosen); 636 637 if (opts->flags & MENU_OPTS_SINGLETON) { ··· 679 { 680 struct dir_struct dir = DIR_INIT; 681 struct strbuf confirm = STRBUF_INIT; 682 - struct strbuf **ignore_list; 683 - struct string_list_item *item; 684 struct pattern_list *pl; 685 int changed = -1, i; 686 687 for (;;) { 688 if (!del_list.nr) 689 break; 690 ··· 702 break; 703 704 pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude"); 705 - ignore_list = strbuf_split_max(&confirm, ' ', 0); 706 707 - for (i = 0; ignore_list[i]; i++) { 708 - strbuf_trim(ignore_list[i]); 709 - if (!ignore_list[i]->len) 710 - continue; 711 712 - add_pattern(ignore_list[i]->buf, "", 0, pl, -(i+1)); 713 } 714 715 changed = 0; ··· 730 clean_print_color(CLEAN_COLOR_RESET); 731 } 732 733 - strbuf_list_free(ignore_list); 734 dir_clear(&dir); 735 } 736
··· 478 */ 479 static int parse_choice(struct menu_stuff *menu_stuff, 480 int is_single, 481 + char *input, 482 int **chosen) 483 { 484 + struct string_list choice = STRING_LIST_INIT_NODUP; 485 + struct string_list_item *item; 486 int nr = 0; 487 int i; 488 489 + string_list_split_in_place_f(&choice, input, 490 + is_single ? "\n" : ", ", -1, 491 + STRING_LIST_SPLIT_TRIM); 492 493 + for_each_string_list_item(item, &choice) { 494 + const char *string; 495 + int choose; 496 int bottom = 0, top = 0; 497 int is_range, is_number; 498 499 + string = item->string; 500 + if (!*string) 501 continue; 502 503 /* Input that begins with '-'; unchoose */ 504 + if (string[0] == '-') { 505 choose = 0; 506 + string++; 507 + } else { 508 + choose = 1; 509 } 510 511 is_range = 0; 512 is_number = 1; 513 + for (const char *p = string; *p; p++) { 514 if ('-' == *p) { 515 if (!is_range) { 516 is_range = 1; ··· 528 } 529 530 if (is_number) { 531 + bottom = atoi(string); 532 top = bottom; 533 } else if (is_range) { 534 + bottom = atoi(string); 535 /* a range can be specified like 5-7 or 5- */ 536 + if (!*(strchr(string, '-') + 1)) 537 top = menu_stuff->nr; 538 else 539 + top = atoi(strchr(string, '-') + 1); 540 + } else if (!strcmp(string, "*")) { 541 bottom = 1; 542 top = menu_stuff->nr; 543 } else { 544 + bottom = find_unique(string, menu_stuff); 545 top = bottom; 546 } 547 548 if (top <= 0 || bottom <= 0 || top > menu_stuff->nr || bottom > top || 549 (is_single && bottom != top)) { 550 clean_print_color(CLEAN_COLOR_ERROR); 551 + printf(_("Huh (%s)?\n"), string); 552 clean_print_color(CLEAN_COLOR_RESET); 553 continue; 554 } ··· 557 (*chosen)[i-1] = choose; 558 } 559 560 + string_list_clear(&choice, 0); 561 562 for (i = 0; i < menu_stuff->nr; i++) 563 nr += (*chosen)[i]; ··· 627 628 nr = parse_choice(stuff, 629 opts->flags & MENU_OPTS_SINGLETON, 630 + choice.buf, 631 &chosen); 632 633 if (opts->flags & MENU_OPTS_SINGLETON) { ··· 675 { 676 struct dir_struct dir = DIR_INIT; 677 struct strbuf confirm = STRBUF_INIT; 678 struct pattern_list *pl; 679 int changed = -1, i; 680 681 for (;;) { 682 + struct string_list ignore_list = STRING_LIST_INIT_NODUP; 683 + struct string_list_item *item; 684 + 685 if (!del_list.nr) 686 break; 687 ··· 699 break; 700 701 pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude"); 702 703 + string_list_split_in_place_f(&ignore_list, confirm.buf, " ", -1, 704 + STRING_LIST_SPLIT_TRIM); 705 706 + for (i = 0; i < ignore_list.nr; i++) { 707 + item = &ignore_list.items[i]; 708 + if (!*item->string) 709 + continue; 710 + add_pattern(item->string, "", 0, pl, -(i+1)); 711 } 712 713 changed = 0; ··· 728 clean_print_color(CLEAN_COLOR_RESET); 729 } 730 731 + string_list_clear(&ignore_list, 0); 732 dir_clear(&dir); 733 } 734
+16 -14
builtin/merge-tree.c
··· 619 "--merge-base", "--stdin"); 620 line_termination = '\0'; 621 while (strbuf_getline_lf(&buf, stdin) != EOF) { 622 - struct strbuf **split; 623 const char *input_merge_base = NULL; 624 625 - split = strbuf_split(&buf, ' '); 626 - if (!split[0] || !split[1]) 627 die(_("malformed input line: '%s'."), buf.buf); 628 - strbuf_rtrim(split[0]); 629 - strbuf_rtrim(split[1]); 630 631 /* parse the merge-base */ 632 - if (!strcmp(split[1]->buf, "--")) { 633 - input_merge_base = split[0]->buf; 634 } 635 636 - if (input_merge_base && split[2] && split[3] && !split[4]) { 637 - strbuf_rtrim(split[2]); 638 - strbuf_rtrim(split[3]); 639 - real_merge(&o, input_merge_base, split[2]->buf, split[3]->buf, prefix); 640 - } else if (!input_merge_base && !split[2]) { 641 - real_merge(&o, NULL, split[0]->buf, split[1]->buf, prefix); 642 } else { 643 die(_("malformed input line: '%s'."), buf.buf); 644 } 645 maybe_flush_or_die(stdout, "stdout"); 646 647 - strbuf_list_free(split); 648 } 649 strbuf_release(&buf); 650
··· 619 "--merge-base", "--stdin"); 620 line_termination = '\0'; 621 while (strbuf_getline_lf(&buf, stdin) != EOF) { 622 + struct string_list split = STRING_LIST_INIT_NODUP; 623 const char *input_merge_base = NULL; 624 625 + string_list_split_in_place_f(&split, buf.buf, " ", -1, 626 + STRING_LIST_SPLIT_TRIM); 627 + 628 + if (split.nr < 2) 629 die(_("malformed input line: '%s'."), buf.buf); 630 631 /* parse the merge-base */ 632 + if (!strcmp(split.items[1].string, "--")) { 633 + input_merge_base = split.items[0].string; 634 } 635 636 + if (input_merge_base && split.nr == 4) { 637 + real_merge(&o, input_merge_base, 638 + split.items[2].string, split.items[3].string, 639 + prefix); 640 + } else if (!input_merge_base && split.nr == 2) { 641 + real_merge(&o, NULL, 642 + split.items[0].string, split.items[1].string, 643 + prefix); 644 } else { 645 die(_("malformed input line: '%s'."), buf.buf); 646 } 647 maybe_flush_or_die(stdout, "stdout"); 648 649 + string_list_clear(&split, 0); 650 } 651 strbuf_release(&buf); 652
+12 -11
builtin/notes.c
··· 376 377 while (strbuf_getline_lf(&buf, stdin) != EOF) { 378 struct object_id from_obj, to_obj; 379 - struct strbuf **split; 380 int err; 381 382 - split = strbuf_split(&buf, ' '); 383 - if (!split[0] || !split[1]) 384 die(_("malformed input line: '%s'."), buf.buf); 385 - strbuf_rtrim(split[0]); 386 - strbuf_rtrim(split[1]); 387 - if (repo_get_oid(the_repository, split[0]->buf, &from_obj)) 388 - die(_("failed to resolve '%s' as a valid ref."), split[0]->buf); 389 - if (repo_get_oid(the_repository, split[1]->buf, &to_obj)) 390 - die(_("failed to resolve '%s' as a valid ref."), split[1]->buf); 391 392 if (rewrite_cmd) 393 err = copy_note_for_rewrite(c, &from_obj, &to_obj); ··· 397 398 if (err) { 399 error(_("failed to copy notes from '%s' to '%s'"), 400 - split[0]->buf, split[1]->buf); 401 ret = 1; 402 } 403 404 - strbuf_list_free(split); 405 } 406 407 if (!rewrite_cmd) {
··· 376 377 while (strbuf_getline_lf(&buf, stdin) != EOF) { 378 struct object_id from_obj, to_obj; 379 + struct string_list split = STRING_LIST_INIT_NODUP; 380 int err; 381 382 + string_list_split_in_place_f(&split, buf.buf, " ", -1, 383 + STRING_LIST_SPLIT_TRIM); 384 + if (split.nr < 2) 385 die(_("malformed input line: '%s'."), buf.buf); 386 + if (repo_get_oid(the_repository, split.items[0].string, &from_obj)) 387 + die(_("failed to resolve '%s' as a valid ref."), 388 + split.items[0].string); 389 + if (repo_get_oid(the_repository, split.items[1].string, &to_obj)) 390 + die(_("failed to resolve '%s' as a valid ref."), 391 + split.items[1].string); 392 393 if (rewrite_cmd) 394 err = copy_note_for_rewrite(c, &from_obj, &to_obj); ··· 398 399 if (err) { 400 error(_("failed to copy notes from '%s' to '%s'"), 401 + split.items[0].string, split.items[1].string); 402 ret = 1; 403 } 404 405 + string_list_clear(&split, 0); 406 } 407 408 if (!rewrite_cmd) {
+10 -13
config.c
··· 629 config_fn_t fn, void *data) 630 { 631 const char *value; 632 - struct strbuf **pair; 633 int ret; 634 struct key_value_info kvi = KVI_INIT; 635 636 kvi_from_param(&kvi); 637 638 - pair = strbuf_split_str(text, '=', 2); 639 - if (!pair[0]) 640 return error(_("bogus config parameter: %s"), text); 641 642 - if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') { 643 - strbuf_setlen(pair[0], pair[0]->len - 1); 644 - value = pair[1] ? pair[1]->buf : ""; 645 - } else { 646 value = NULL; 647 - } 648 649 - strbuf_trim(pair[0]); 650 - if (!pair[0]->len) { 651 - strbuf_list_free(pair); 652 return error(_("bogus config parameter: %s"), text); 653 } 654 655 - ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data); 656 - strbuf_list_free(pair); 657 return ret; 658 } 659
··· 629 config_fn_t fn, void *data) 630 { 631 const char *value; 632 + struct string_list pair = STRING_LIST_INIT_DUP; 633 int ret; 634 struct key_value_info kvi = KVI_INIT; 635 636 kvi_from_param(&kvi); 637 638 + string_list_split(&pair, text, "=", 1); 639 + if (!pair.nr) 640 return error(_("bogus config parameter: %s"), text); 641 642 + if (pair.nr == 1) 643 value = NULL; 644 + else 645 + value = pair.items[1].string; 646 647 + if (!*pair.items[0].string) { 648 + string_list_clear(&pair, 0); 649 return error(_("bogus config parameter: %s"), text); 650 } 651 652 + ret = config_parse_pair(pair.items[0].string, value, &kvi, fn, data); 653 + string_list_clear(&pair, 0); 654 return ret; 655 } 656
+12 -7
environment.c
··· 175 const char *get_git_namespace(void) 176 { 177 static const char *namespace; 178 - 179 struct strbuf buf = STRBUF_INIT; 180 - struct strbuf **components, **c; 181 const char *raw_namespace; 182 183 if (namespace) 184 return namespace; ··· 190 } 191 192 strbuf_addstr(&buf, raw_namespace); 193 - components = strbuf_split(&buf, '/'); 194 strbuf_reset(&buf); 195 - for (c = components; *c; c++) 196 - if (strcmp((*c)->buf, "/") != 0) 197 - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); 198 - strbuf_list_free(components); 199 if (check_refname_format(buf.buf, 0)) 200 die(_("bad git namespace path \"%s\""), raw_namespace); 201 strbuf_addch(&buf, '/');
··· 175 const char *get_git_namespace(void) 176 { 177 static const char *namespace; 178 struct strbuf buf = STRBUF_INIT; 179 const char *raw_namespace; 180 + struct string_list components = STRING_LIST_INIT_DUP; 181 + struct string_list_item *item; 182 183 if (namespace) 184 return namespace; ··· 190 } 191 192 strbuf_addstr(&buf, raw_namespace); 193 + 194 + string_list_split(&components, buf.buf, "/", -1); 195 strbuf_reset(&buf); 196 + 197 + for_each_string_list_item(item, &components) { 198 + if (item->string[0]) 199 + strbuf_addf(&buf, "refs/namespaces/%s/", item->string); 200 + } 201 + string_list_clear(&components, 0); 202 + 203 + strbuf_trim_trailing_dir_sep(&buf); 204 if (check_refname_format(buf.buf, 0)) 205 die(_("bad git namespace path \"%s\""), raw_namespace); 206 strbuf_addch(&buf, '/');
+6 -9
sub-process.c
··· 30 31 int subprocess_read_status(int fd, struct strbuf *status) 32 { 33 - struct strbuf **pair; 34 - char *line; 35 int len; 36 37 for (;;) { 38 len = packet_read_line_gently(fd, NULL, &line); 39 if ((len < 0) || !line) 40 break; 41 - pair = strbuf_split_str(line, '=', 2); 42 - if (pair[0] && pair[0]->len && pair[1]) { 43 /* the last "status=<foo>" line wins */ 44 - if (!strcmp(pair[0]->buf, "status=")) { 45 - strbuf_reset(status); 46 - strbuf_addbuf(status, pair[1]); 47 - } 48 } 49 - strbuf_list_free(pair); 50 } 51 52 return (len < 0) ? len : 0;
··· 30 31 int subprocess_read_status(int fd, struct strbuf *status) 32 { 33 int len; 34 35 for (;;) { 36 + char *line; 37 + const char *value; 38 + 39 len = packet_read_line_gently(fd, NULL, &line); 40 if ((len < 0) || !line) 41 break; 42 + if (skip_prefix(line, "status=", &value)) { 43 /* the last "status=<foo>" line wins */ 44 + strbuf_reset(status); 45 + strbuf_addstr(status, value); 46 } 47 } 48 49 return (len < 0) ? len : 0;
+27 -53
trace2/tr2_cfg.c
··· 8 #include "trace2/tr2_sysenv.h" 9 #include "wildmatch.h" 10 11 - static struct strbuf **tr2_cfg_patterns; 12 - static int tr2_cfg_count_patterns; 13 static int tr2_cfg_loaded; 14 15 - static struct strbuf **tr2_cfg_env_vars; 16 - static int tr2_cfg_env_vars_count; 17 static int tr2_cfg_env_vars_loaded; 18 19 /* 20 * Parse a string containing a comma-delimited list of config keys 21 - * or wildcard patterns into a list of strbufs. 22 */ 23 - static int tr2_cfg_load_patterns(void) 24 { 25 - struct strbuf **s; 26 const char *envvar; 27 28 if (tr2_cfg_loaded) 29 - return tr2_cfg_count_patterns; 30 tr2_cfg_loaded = 1; 31 32 envvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM); 33 if (!envvar || !*envvar) 34 - return tr2_cfg_count_patterns; 35 - 36 - tr2_cfg_patterns = strbuf_split_buf(envvar, strlen(envvar), ',', -1); 37 - for (s = tr2_cfg_patterns; *s; s++) { 38 - struct strbuf *buf = *s; 39 - 40 - if (buf->len && buf->buf[buf->len - 1] == ',') 41 - strbuf_setlen(buf, buf->len - 1); 42 - strbuf_trim_trailing_newline(*s); 43 - strbuf_trim(*s); 44 - } 45 46 - tr2_cfg_count_patterns = s - tr2_cfg_patterns; 47 - return tr2_cfg_count_patterns; 48 } 49 50 void tr2_cfg_free_patterns(void) 51 { 52 - if (tr2_cfg_patterns) 53 - strbuf_list_free(tr2_cfg_patterns); 54 - tr2_cfg_count_patterns = 0; 55 tr2_cfg_loaded = 0; 56 } 57 58 /* 59 * Parse a string containing a comma-delimited list of environment variable 60 - * names into a list of strbufs. 61 */ 62 - static int tr2_load_env_vars(void) 63 { 64 - struct strbuf **s; 65 const char *varlist; 66 67 if (tr2_cfg_env_vars_loaded) 68 - return tr2_cfg_env_vars_count; 69 tr2_cfg_env_vars_loaded = 1; 70 71 varlist = tr2_sysenv_get(TR2_SYSENV_ENV_VARS); 72 if (!varlist || !*varlist) 73 - return tr2_cfg_env_vars_count; 74 - 75 - tr2_cfg_env_vars = strbuf_split_buf(varlist, strlen(varlist), ',', -1); 76 - for (s = tr2_cfg_env_vars; *s; s++) { 77 - struct strbuf *buf = *s; 78 - 79 - if (buf->len && buf->buf[buf->len - 1] == ',') 80 - strbuf_setlen(buf, buf->len - 1); 81 - strbuf_trim_trailing_newline(*s); 82 - strbuf_trim(*s); 83 - } 84 85 - tr2_cfg_env_vars_count = s - tr2_cfg_env_vars; 86 - return tr2_cfg_env_vars_count; 87 } 88 89 void tr2_cfg_free_env_vars(void) 90 { 91 - if (tr2_cfg_env_vars) 92 - strbuf_list_free(tr2_cfg_env_vars); 93 - tr2_cfg_env_vars_count = 0; 94 tr2_cfg_env_vars_loaded = 0; 95 } 96 ··· 105 static int tr2_cfg_cb(const char *key, const char *value, 106 const struct config_context *ctx, void *d) 107 { 108 - struct strbuf **s; 109 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d; 110 111 - for (s = tr2_cfg_patterns; *s; s++) { 112 - struct strbuf *buf = *s; 113 - int wm = wildmatch(buf->buf, key, WM_CASEFOLD); 114 if (wm == WM_MATCH) { 115 trace2_def_param_fl(data->file, data->line, key, value, 116 ctx->kvi); ··· 132 void tr2_list_env_vars_fl(const char *file, int line) 133 { 134 struct key_value_info kvi = KVI_INIT; 135 - struct strbuf **s; 136 137 kvi_from_param(&kvi); 138 if (tr2_load_env_vars() <= 0) 139 return; 140 141 - for (s = tr2_cfg_env_vars; *s; s++) { 142 - struct strbuf *buf = *s; 143 - const char *val = getenv(buf->buf); 144 if (val && *val) 145 - trace2_def_param_fl(file, line, buf->buf, val, &kvi); 146 } 147 } 148
··· 8 #include "trace2/tr2_sysenv.h" 9 #include "wildmatch.h" 10 11 + static struct string_list tr2_cfg_patterns = STRING_LIST_INIT_DUP; 12 static int tr2_cfg_loaded; 13 14 + static struct string_list tr2_cfg_env_vars = STRING_LIST_INIT_DUP; 15 static int tr2_cfg_env_vars_loaded; 16 17 /* 18 * Parse a string containing a comma-delimited list of config keys 19 + * or wildcard patterns into a string list. 20 */ 21 + static size_t tr2_cfg_load_patterns(void) 22 { 23 const char *envvar; 24 25 if (tr2_cfg_loaded) 26 + return tr2_cfg_patterns.nr; 27 tr2_cfg_loaded = 1; 28 29 envvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM); 30 if (!envvar || !*envvar) 31 + return tr2_cfg_patterns.nr; 32 33 + string_list_split_f(&tr2_cfg_patterns, envvar, ",", -1, 34 + STRING_LIST_SPLIT_TRIM); 35 + return tr2_cfg_patterns.nr; 36 } 37 38 void tr2_cfg_free_patterns(void) 39 { 40 + if (tr2_cfg_patterns.nr) 41 + string_list_clear(&tr2_cfg_patterns, 0); 42 tr2_cfg_loaded = 0; 43 } 44 45 /* 46 * Parse a string containing a comma-delimited list of environment variable 47 + * names into a string list. 48 */ 49 + static size_t tr2_load_env_vars(void) 50 { 51 const char *varlist; 52 53 if (tr2_cfg_env_vars_loaded) 54 + return tr2_cfg_env_vars.nr; 55 tr2_cfg_env_vars_loaded = 1; 56 57 varlist = tr2_sysenv_get(TR2_SYSENV_ENV_VARS); 58 if (!varlist || !*varlist) 59 + return tr2_cfg_env_vars.nr; 60 61 + string_list_split_f(&tr2_cfg_env_vars, varlist, ",", -1, 62 + STRING_LIST_SPLIT_TRIM); 63 + return tr2_cfg_env_vars.nr; 64 } 65 66 void tr2_cfg_free_env_vars(void) 67 { 68 + if (tr2_cfg_env_vars.nr) 69 + string_list_clear(&tr2_cfg_env_vars, 0); 70 tr2_cfg_env_vars_loaded = 0; 71 } 72 ··· 81 static int tr2_cfg_cb(const char *key, const char *value, 82 const struct config_context *ctx, void *d) 83 { 84 + struct string_list_item *item; 85 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d; 86 87 + for_each_string_list_item(item, &tr2_cfg_patterns) { 88 + int wm = wildmatch(item->string, key, WM_CASEFOLD); 89 if (wm == WM_MATCH) { 90 trace2_def_param_fl(data->file, data->line, key, value, 91 ctx->kvi); ··· 107 void tr2_list_env_vars_fl(const char *file, int line) 108 { 109 struct key_value_info kvi = KVI_INIT; 110 + struct string_list_item *item; 111 112 kvi_from_param(&kvi); 113 if (tr2_load_env_vars() <= 0) 114 return; 115 116 + for_each_string_list_item(item, &tr2_cfg_env_vars) { 117 + const char *val = getenv(item->string); 118 if (val && *val) 119 + trace2_def_param_fl(file, line, item->string, val, &kvi); 120 } 121 } 122
+10 -21
wt-status.c
··· 1352 */ 1353 static void abbrev_oid_in_line(struct strbuf *line) 1354 { 1355 - struct strbuf **split; 1356 - int i; 1357 1358 if (starts_with(line->buf, "exec ") || 1359 starts_with(line->buf, "x ") || ··· 1361 starts_with(line->buf, "l ")) 1362 return; 1363 1364 - split = strbuf_split_max(line, ' ', 3); 1365 - if (split[0] && split[1]) { 1366 - struct object_id oid; 1367 - 1368 - /* 1369 - * strbuf_split_max left a space. Trim it and re-add 1370 - * it after abbreviation. 1371 - */ 1372 - strbuf_trim(split[1]); 1373 - if (!repo_get_oid(the_repository, split[1]->buf, &oid)) { 1374 - strbuf_reset(split[1]); 1375 - strbuf_add_unique_abbrev(split[1], &oid, 1376 - DEFAULT_ABBREV); 1377 - strbuf_addch(split[1], ' '); 1378 - strbuf_reset(line); 1379 - for (i = 0; split[i]; i++) 1380 - strbuf_addbuf(line, split[i]); 1381 - } 1382 } 1383 - strbuf_list_free(split); 1384 } 1385 1386 static int read_rebase_todolist(const char *fname, struct string_list *lines)
··· 1352 */ 1353 static void abbrev_oid_in_line(struct strbuf *line) 1354 { 1355 + struct string_list split = STRING_LIST_INIT_DUP; 1356 + struct object_id oid; 1357 1358 if (starts_with(line->buf, "exec ") || 1359 starts_with(line->buf, "x ") || ··· 1361 starts_with(line->buf, "l ")) 1362 return; 1363 1364 + if ((2 <= string_list_split(&split, line->buf, " ", 2)) && 1365 + !repo_get_oid(the_repository, split.items[1].string, &oid)) { 1366 + strbuf_reset(line); 1367 + strbuf_addf(line, "%s ", split.items[0].string); 1368 + strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV); 1369 + for (size_t i = 2; i < split.nr; i++) 1370 + strbuf_addf(line, " %s", split.items[i].string); 1371 } 1372 + string_list_clear(&split, 0); 1373 } 1374 1375 static int read_rebase_todolist(const char *fname, struct string_list *lines)