Skip to content

Commit 7ff1213

Browse files
committed
Merge branch 'va/i18n' into pu
More i18n marking. * va/i18n: i18n: config: unfold error messages marked for translation i18n: notes: mark comment for translation
2 parents 14fa1c4 + 1b8132d commit 7ff1213

File tree

4 files changed

+112
-24
lines changed

4 files changed

+112
-24
lines changed

builtin/notes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static const char * const git_notes_get_ref_usage[] = {
9191
};
9292

9393
static const char note_template[] =
94-
"\nWrite/edit the notes for the following object:\n";
94+
N_("Write/edit the notes for the following object:");
9595

9696
struct note_data {
9797
int given;
@@ -179,7 +179,8 @@ static void prepare_note_data(const unsigned char *object, struct note_data *d,
179179
copy_obj_to_fd(fd, old_note);
180180

181181
strbuf_addch(&buf, '\n');
182-
strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
182+
strbuf_add_commented_lines(&buf, "\n", strlen("\n"));
183+
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)));
183184
strbuf_addch(&buf, '\n');
184185
write_or_die(fd, buf.buf, buf.len);
185186

cache.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,10 +1593,18 @@ struct git_config_source {
15931593
const char *blob;
15941594
};
15951595

1596+
enum config_origin_type {
1597+
CONFIG_ORIGIN_BLOB,
1598+
CONFIG_ORIGIN_FILE,
1599+
CONFIG_ORIGIN_STDIN,
1600+
CONFIG_ORIGIN_SUBMODULE_BLOB,
1601+
CONFIG_ORIGIN_CMDLINE
1602+
};
1603+
15961604
typedef int (*config_fn_t)(const char *, const char *, void *);
15971605
extern int git_default_config(const char *, const char *, void *);
15981606
extern int git_config_from_file(config_fn_t fn, const char *, void *);
1599-
extern int git_config_from_mem(config_fn_t fn, const char *origin_type,
1607+
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
16001608
const char *name, const char *buf, size_t len, void *data);
16011609
extern void git_config_push_parameter(const char *text);
16021610
extern int git_config_from_parameters(config_fn_t fn, void *data);
@@ -1740,7 +1748,7 @@ extern int ignore_untracked_cache_config;
17401748
struct key_value_info {
17411749
const char *filename;
17421750
int linenr;
1743-
const char *origin_type;
1751+
enum config_origin_type origin_type;
17441752
enum config_scope scope;
17451753
};
17461754

config.c

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct config_source {
2424
size_t pos;
2525
} buf;
2626
} u;
27-
const char *origin_type;
27+
enum config_origin_type origin_type;
2828
const char *name;
2929
const char *path;
3030
int die_on_error;
@@ -245,6 +245,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
245245

246246
memset(&source, 0, sizeof(source));
247247
source.prev = cf;
248+
source.origin_type = CONFIG_ORIGIN_CMDLINE;
248249
cf = &source;
249250

250251
/* sq_dequote will write over it */
@@ -453,6 +454,8 @@ static int git_parse_source(config_fn_t fn, void *data)
453454
int comment = 0;
454455
int baselen = 0;
455456
struct strbuf *var = &cf->var;
457+
int error_return = 0;
458+
char *error_msg = NULL;
456459

457460
/* U+FEFF Byte Order Mark in UTF8 */
458461
const char *bomptr = utf8_bom;
@@ -507,10 +510,40 @@ static int git_parse_source(config_fn_t fn, void *data)
507510
if (get_value(fn, data, var) < 0)
508511
break;
509512
}
513+
514+
switch (cf->origin_type) {
515+
case CONFIG_ORIGIN_BLOB:
516+
error_msg = xstrfmt(_("bad config line %d in blob %s"),
517+
cf->linenr, cf->name);
518+
break;
519+
case CONFIG_ORIGIN_FILE:
520+
error_msg = xstrfmt(_("bad config line %d in file %s"),
521+
cf->linenr, cf->name);
522+
break;
523+
case CONFIG_ORIGIN_STDIN:
524+
error_msg = xstrfmt(_("bad config line %d in standard input"),
525+
cf->linenr);
526+
break;
527+
case CONFIG_ORIGIN_SUBMODULE_BLOB:
528+
error_msg = xstrfmt(_("bad config line %d in submodule-blob %s"),
529+
cf->linenr, cf->name);
530+
break;
531+
case CONFIG_ORIGIN_CMDLINE:
532+
error_msg = xstrfmt(_("bad config line %d in command line %s"),
533+
cf->linenr, cf->name);
534+
break;
535+
default:
536+
error_msg = xstrfmt(_("bad config line %d in %s"),
537+
cf->linenr, cf->name);
538+
}
539+
510540
if (cf->die_on_error)
511-
die(_("bad config line %d in %s %s"), cf->linenr, cf->origin_type, cf->name);
541+
die("%s", error_msg);
512542
else
513-
return error(_("bad config line %d in %s %s"), cf->linenr, cf->origin_type, cf->name);
543+
error_return = error("%s", error_msg);
544+
545+
free(error_msg);
546+
return error_return;
514547
}
515548

516549
static int parse_unit_factor(const char *end, uintmax_t *val)
@@ -619,16 +652,47 @@ int git_parse_ulong(const char *value, unsigned long *ret)
619652
NORETURN
620653
static void die_bad_number(const char *name, const char *value)
621654
{
622-
const char *reason = errno == ERANGE ?
623-
"out of range" :
624-
"invalid unit";
625655
if (!value)
626656
value = "";
627657

628-
if (cf && cf->origin_type && cf->name)
629-
die(_("bad numeric config value '%s' for '%s' in %s %s: %s"),
630-
value, name, cf->origin_type, cf->name, reason);
631-
die(_("bad numeric config value '%s' for '%s': %s"), value, name, reason);
658+
if (!(cf && cf->name))
659+
die(errno == ERANGE
660+
? _("bad numeric config value '%s' for '%s': out of range")
661+
: _("bad numeric config value '%s' for '%s': invalid unit"),
662+
value, name);
663+
664+
switch (cf->origin_type) {
665+
case CONFIG_ORIGIN_BLOB:
666+
die(errno == ERANGE
667+
? _("bad numeric config value '%s' for '%s' in blob %s: out of range")
668+
: _("bad numeric config value '%s' for '%s' in blob %s: invalid unit"),
669+
value, name, cf->name);
670+
case CONFIG_ORIGIN_FILE:
671+
die(errno == ERANGE
672+
? _("bad numeric config value '%s' for '%s' in file %s: out of range")
673+
: _("bad numeric config value '%s' for '%s' in file %s: invalid unit"),
674+
value, name, cf->name);
675+
case CONFIG_ORIGIN_STDIN:
676+
die(errno == ERANGE
677+
? _("bad numeric config value '%s' for '%s' in standard input: out of range")
678+
: _("bad numeric config value '%s' for '%s' in standard input: invalid unit"),
679+
value, name);
680+
case CONFIG_ORIGIN_SUBMODULE_BLOB:
681+
die(errno == ERANGE
682+
? _("bad numeric config value '%s' for '%s' in submodule-blob %s: out of range")
683+
: _("bad numeric config value '%s' for '%s' in submodule-blob %s: invalid unit"),
684+
value, name, cf->name);
685+
case CONFIG_ORIGIN_CMDLINE:
686+
die(errno == ERANGE
687+
? _("bad numeric config value '%s' for '%s' in command line %s: out of range")
688+
: _("bad numeric config value '%s' for '%s' in command line %s: invalid unit"),
689+
value, name, cf->name);
690+
default:
691+
die(errno == ERANGE
692+
? _("bad numeric config value '%s' for '%s' in %s: out of range")
693+
: _("bad numeric config value '%s' for '%s' in %s: invalid unit"),
694+
value, name, cf->name);
695+
}
632696
}
633697

634698
int git_config_int(const char *name, const char *value)
@@ -1110,7 +1174,8 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
11101174
}
11111175

11121176
static int do_config_from_file(config_fn_t fn,
1113-
const char *origin_type, const char *name, const char *path, FILE *f,
1177+
const enum config_origin_type origin_type,
1178+
const char *name, const char *path, FILE *f,
11141179
void *data)
11151180
{
11161181
struct config_source top;
@@ -1129,7 +1194,7 @@ static int do_config_from_file(config_fn_t fn,
11291194

11301195
static int git_config_from_stdin(config_fn_t fn, void *data)
11311196
{
1132-
return do_config_from_file(fn, "standard input", "", NULL, stdin, data);
1197+
return do_config_from_file(fn, CONFIG_ORIGIN_STDIN, "", NULL, stdin, data);
11331198
}
11341199

11351200
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
@@ -1140,14 +1205,14 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
11401205
f = fopen(filename, "r");
11411206
if (f) {
11421207
flockfile(f);
1143-
ret = do_config_from_file(fn, "file", filename, filename, f, data);
1208+
ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
11441209
funlockfile(f);
11451210
fclose(f);
11461211
}
11471212
return ret;
11481213
}
11491214

1150-
int git_config_from_mem(config_fn_t fn, const char *origin_type,
1215+
int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_type,
11511216
const char *name, const char *buf, size_t len, void *data)
11521217
{
11531218
struct config_source top;
@@ -1184,7 +1249,7 @@ static int git_config_from_blob_sha1(config_fn_t fn,
11841249
return error("reference '%s' does not point to a blob", name);
11851250
}
11861251

1187-
ret = git_config_from_mem(fn, "blob", name, buf, size, data);
1252+
ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size, data);
11881253
free(buf);
11891254

11901255
return ret;
@@ -1395,12 +1460,12 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
13951460
if (cf->name) {
13961461
kv_info->filename = strintern(cf->name);
13971462
kv_info->linenr = cf->linenr;
1398-
kv_info->origin_type = strintern(cf->origin_type);
1463+
kv_info->origin_type = cf->origin_type;
13991464
} else {
14001465
/* for values read from `git_config_from_parameters()` */
14011466
kv_info->filename = NULL;
14021467
kv_info->linenr = -1;
1403-
kv_info->origin_type = NULL;
1468+
kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
14041469
}
14051470
kv_info->scope = current_parsing_scope;
14061471
si->util = kv_info;
@@ -2481,14 +2546,28 @@ int parse_config_key(const char *var,
24812546

24822547
const char *current_config_origin_type(void)
24832548
{
2484-
const char *type;
2549+
int type;
24852550
if (current_config_kvi)
24862551
type = current_config_kvi->origin_type;
24872552
else if(cf)
24882553
type = cf->origin_type;
24892554
else
24902555
die("BUG: current_config_origin_type called outside config callback");
2491-
return type ? type : "command line";
2556+
2557+
switch (type) {
2558+
case CONFIG_ORIGIN_BLOB:
2559+
return "blob";
2560+
case CONFIG_ORIGIN_FILE:
2561+
return "file";
2562+
case CONFIG_ORIGIN_STDIN:
2563+
return "standard input";
2564+
case CONFIG_ORIGIN_SUBMODULE_BLOB:
2565+
return "submodule-blob";
2566+
case CONFIG_ORIGIN_CMDLINE:
2567+
return "command line";
2568+
default:
2569+
die("BUG: unknown config origin type");
2570+
}
24922571
}
24932572

24942573
const char *current_config_name(void)

submodule-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
442442
parameter.commit_sha1 = commit_sha1;
443443
parameter.gitmodules_sha1 = sha1;
444444
parameter.overwrite = 0;
445-
git_config_from_mem(parse_config, "submodule-blob", rev.buf,
445+
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
446446
config, config_size, &parameter);
447447
strbuf_release(&rev);
448448
free(config);

0 commit comments

Comments
 (0)