Mark more strings for translation
cover Mark more strings for translation
Not much to write here. I make a note whenever I see unstranslated strings during review and this is the result. There are some more code changes than just adding _() though, e.g. 10/12.
Nguyễn Thái Ngọc Duy (12):
git.c: mark more strings for translation
alias.c: mark split_cmdline_strerror() strings for translation archive.c: mark more strings for translation
attr.c: mark more string for translation read-cache.c: mark more strings for translation read-cache.c: add missing colon separators
reflog: mark strings for translation
remote.c: mark messages for translation
repack: mark more strings for translation
parse-options: replace opterror() with optname() parse-options.c: mark more strings for translation
fsck: mark strings for translation
alias.c | 4 +- archive.c | 8 +-- attr.c | 2 +- builtin/fsck.c | 113 ++++++++++++++++++++----------------- builtin/merge.c | 4 +- builtin/reflog.c | 34 ++++++----- builtin/repack.c | 26 ++++----- builtin/revert.c | 3 +- git.c | 32 +++++------ parse-options-cb.c | 7 ++- parse-options.c | 64 +++++++++++---------- parse-options.h | 5 +- read-cache.c | 73 ++++++++++++------------ ref-filter.c | 8 ++- remote.c | 49 ++++++++-------- t/t0040-parse-options.sh | 4 +- t/t1410-reflog.sh | 6 +- t/t1450-fsck.sh | 52 ++++++++--------- t/t4211-line-log.sh | 2 +- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +- 21 files changed, 264 insertions(+), 242 deletions(-)
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 1/12 git.c: mark more strings for translation
--- git.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
git.c +15 -15
@@ -338,27 +338,27 @@ static int handle_alias(int *argcp, const char ***argv)if (ret >=0 )/* normal exit */ exit (ret); -die_errno ("while expanding alias '%s': '%s'" , - alias_command, alias_string +1 ); +die_errno (_ ("while expanding alias '%s': '%s'" ), + alias_command, alias_string +1 ); } count =split_cmdline (alias_string, &new_argv);if (count <0 ) -die ("Bad alias.%s string: %s" , alias_command, +die (_ ("bad alias.%s string: %s" ), alias_command,split_cmdline_strerror (count)); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) -die ("alias '%s' changes environment variables.\n" -"You can use '!git' in the alias to do this" , - alias_command); +die (_ ("alias '%s' changes environment variables.\n" +"You can use '!git' in the alias to do this" ), + alias_command);memmove (new_argv - option_count, new_argv, count *sizeof (char *)); new_argv -= option_count;if (count <1 ) -die ("empty alias for %s" , alias_command); +die (_ ("empty alias for %s" ), alias_command);if (!strcmp (alias_command, new_argv[0 ])) -die ("recursive alias: %s" , alias_command); +die (_ ("recursive alias: %s" ), alias_command); trace_argv_printf(new_argv, "trace: alias expansion: %s =>",
@@ -409,7 +409,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if (!help &&get_super_prefix ()) {if (!(p->option &SUPPORT_SUPER_PREFIX )) -die ("%s doesn't support --super-prefix" , p->cmd); +BUG ("%s doesn't support --super-prefix" , p->cmd); }if (!help && p->option &NEED_WORK_TREE )
@@ -433,11 +433,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)/* Check for ENOSPC and EIO errors.. */ if (fflush (stdout)) -die_errno ("write failure on standard output" ); +die_errno (_ ("write failure on standard output" ));if (ferror (stdout)) -die ("unknown write failure on standard output" ); +die (_ ("unknown write failure on standard output" ));if (fclose (stdout)) -die_errno ("close failed on standard output" ); +die_errno (_ ("close failed on standard output" ));return 0 ; }
@@ -648,7 +648,7 @@ static void execv_dashed_external(const char **argv)int status;if (get_super_prefix ()) -die ("%s doesn't support --super-prefix" , argv[0 ]); +BUG ("%s doesn't support --super-prefix" , argv[0 ]);if (use_pager ==-1 && !is_builtin (argv[0 ])) use_pager =check_pager_config (argv[0 ]);
@@ -760,7 +760,7 @@ int cmd_main(int argc, const char **argv)if (skip_prefix (cmd,"git-" , &cmd)) { argv[0 ] = cmd;handle_builtin (argc, argv); -die ("cannot handle %s as a builtin" , cmd); +die (_ ("cannot handle %s as a builtin" ), cmd); }/* Look for flags.. */
@@ -773,7 +773,7 @@ int cmd_main(int argc, const char **argv) }else {/* The user didn't specify a command; give them help */ commit_pager_choice (); -printf ("usage: %s\n\n" , git_usage_string); +printf (_ ("usage: %s\n\n" ), git_usage_string);list_common_cmds_help ();printf ("\n%s\n" ,_ (git_more_info_string));exit (1 );
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 2/12 alias.c: mark split_cmdline_strerror() strings for translation
In reply to Nguyễn Thái Ngọc DuyThis function can be part of translated messages. To make sure we don't have a sentence with mixed languages, mark the strings for translation, but only use translated strings in places we know we will output translated strings.
--- alias.c | 4 ++-- builtin/merge.c | 2 +- git.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
alias.c +2 -2
@@ -47,8 +47,8 @@ void list_aliases(struct string_list *list)#define SPLIT_CMDLINE_BAD_ENDING 1#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2static const char *split_cmdline_errors[] = { -"cmdline ends with \\" , -"unclosed quote" +N_ ("cmdline ends with \\" ), +N_ ("unclosed quote" ) };int split_cmdline (char *cmdline,const char ***argv)
builtin/merge.c +1 -1
@@ -577,7 +577,7 @@ static void parse_branch_merge_options(char *bmo) argc =split_cmdline (bmo, &argv);if (argc <0 )die (_ ("Bad branch.%s.mergeoptions string: %s" ), branch, -split_cmdline_strerror (argc)); +_ (split_cmdline_strerror (argc)));REALLOC_ARRAY (argv, argc +2 );MOVE_ARRAY (argv +1 , argv, argc +1 ); argc++;
git.c +1 -1
@@ -344,7 +344,7 @@ static int handle_alias(int *argcp, const char ***argv) count =split_cmdline (alias_string, &new_argv);if (count <0 )die (_ ("bad alias.%s string: %s" ), alias_command, -split_cmdline_strerror (count)); +_ (split_cmdline_strerror (count))); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) die(_("alias '%s' changes environment variables.\n"
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 3/12 archive.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duy--- archive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
archive.c +4 -4
@@ -385,12 +385,12 @@ static void parse_treeish_arg(const char **argv,int refnamelen = colon - name;if (!dwim_ref (name, refnamelen, &oid, &ref)) -die ("no such ref: %.*s" , refnamelen, name); +die (_ ("no such ref: %.*s" ), refnamelen, name);free (ref); }if (get_oid (name, &oid)) -die ("Not a valid object name" ); +die (_ ("'%s' is not a valid object name" ), name); commit =lookup_commit_reference_gently (ar_args->repo, &oid,1 );if (commit) {
@@ -403,7 +403,7 @@ static void parse_treeish_arg(const char **argv, tree =parse_tree_indirect (&oid);if (tree ==NULL ) -die ("not a tree object" ); +die (_ ("%s is not a tree object" ),oid_to_hex (&oid));if (prefix) {struct object_id tree_oid;
@@ -413,7 +413,7 @@ static void parse_treeish_arg(const char **argv, err =get_tree_entry (&tree->object.oid, prefix, &tree_oid, &mode);if (err || !S_ISDIR (mode)) -die ("current working directory is untracked" ); +die (_ ("current working directory is untracked" )); tree =parse_tree_indirect (&tree_oid); }
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 4/12 attr.c: mark more string for translation
In reply to Nguyễn Thái Ngọc Duy--- attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
attr.c +1 -1
@@ -372,7 +372,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,if (strlen (ATTRIBUTE_MACRO_PREFIX ) < namelen &&starts_with (name,ATTRIBUTE_MACRO_PREFIX )) {if (!macro_ok) { -fprintf (stderr,"%s not allowed: %s:%d\n" , +fprintf (stderr,_ ("%s not allowed: %s:%d\n" ), name, src, lineno); goto fail_return; }
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 5/12 read-cache.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyThere are a couple other improvements on these strings as well:
- add missing colon (as separator)
- quote paths
- provide more information on error messages
- keep first word in lowercase
- some die() become BUG()
--- read-cache.c | 63 +++++++++++++++++++++++++------------------------ t/t1450-fsck.sh | 2 +- 2 files changed, 33 insertions(+), 32 deletions(-)
read-cache.c +32 -31
@@ -316,7 +316,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) changed |=DATA_CHANGED ;return changed;default : -die ("internal error: ce_mode is %o" , ce->ce_mode); +BUG ("unsupported ce_mode %o" , ce->ce_mode); } changed |=match_stat_data (&ce->ce_stat_data, st);
@@ -672,7 +672,8 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,struct cache_entry *new_entry;if (alias->ce_flags &CE_ADDED ) -die ("Will not add file alias '%s' ('%s' already exists in index)" , ce->name, alias->name); +die (_ ("will not add file alias '%s' ('%s' already exists in index)" ), + ce->name, alias->name);/* Ok, create the new entry using the name of the existing alias */ len =ce_namelen (alias);
@@ -687,7 +688,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce) {struct object_id oid;if (write_object_file ("" ,0 , blob_type, &oid)) -die ("cannot create an empty blob in the object database" ); +die (_ ("cannot create an empty blob in the object database" ));oidcpy (&ce->oid, &oid); }
@@ -708,7 +709,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, newflags |=HASH_RENORMALIZE ;if (!S_ISREG (st_mode) && !S_ISLNK (st_mode) && !S_ISDIR (st_mode)) -return error ("%s: can only add regular files, symbolic links or git-directories" , path); +return error (_ ("%s: can only add regular files, symbolic links or git-directories" ), path); namelen =strlen (path);if (S_ISDIR (st_mode)) {
@@ -763,7 +764,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,if (!intent_only) {if (index_path (istate, &ce->oid, path, st, newflags)) {discard_cache_entry (ce); -return error ("unable to index file %s" , path); +return error (_ ("unable to index file '%s'" ), path); } }else set_object_name_for_intent_to_add_entry (ce);
@@ -782,7 +783,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,discard_cache_entry (ce); else if (add_index_entry(istate, ce, add_option)) {discard_cache_entry (ce); -return error ("unable to add %s to index" , path); +return error (_ ("unable to add '%s' to index" ), path); }if (verbose && !was_same)printf ("add '%s'\n" , path);
@@ -793,7 +794,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags) {struct stat st;if (lstat (path, &st)) -die_errno ("unable to stat '%s'" , path); +die_errno (_ ("unable to stat '%s'" ), path);return add_to_index (istate, path, &st, flags); }
@@ -818,7 +819,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,int len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -844,7 +845,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct oint len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -1297,12 +1298,12 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_eif (!ok_to_add)return -1 ;if (!verify_path (ce->name, ce->ce_mode)) -return error ("Invalid path '%s'" , ce->name); +return error (_ ("invalid path '%s'" ), ce->name);if (!skip_df_check &&check_file_directory_conflict (istate, ce, pos, ok_to_replace)) {if (!ok_to_replace) -return error ("'%s' appears as both a file and as a directory" , +return error (_ ("'%s' appears as both a file and as a directory" ), ce->name); pos =index_name_stage_pos (istate, ce->name,ce_namelen (ce),ce_stage (ce)); pos = -pos-1 ;
@@ -1676,10 +1677,10 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)int hdr_version;if (hdr->hdr_signature !=htonl (CACHE_SIGNATURE )) -return error ("bad signature" ); +return error (_ ("bad signature 0x%08x" ), hdr->hdr_signature); hdr_version =ntohl (hdr->hdr_version);if (hdr_version <INDEX_FORMAT_LB ||INDEX_FORMAT_UB < hdr_version) -return error ("bad index version %d" , hdr_version); +return error (_ ("bad index version %d" ), hdr_version);if (!verify_index_checksum)return 0 ;
@@ -1688,7 +1689,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) the_hash_algo->update_fn (&c, hdr, size - the_hash_algo->rawsz); the_hash_algo->final_fn (hash, &c);if (!hasheq (hash, (unsigned char *)hdr + size - the_hash_algo->rawsz)) -return error ("bad index file sha1 signature" ); +return error (_ ("bad index file sha1 signature" ));return 0 ; }
@@ -1718,9 +1719,9 @@ static int read_index_extension(struct index_state *istate,break ;default :if (*ext <'A' ||'Z' < *ext) -return error ("index uses %.4s extension, which we do not understand" , +return error (_ ("index uses %.4s extension, which we do not understand" ), ext); -fprintf (stderr,"ignoring %.4s extension\n" , ext); +fprintf_ln (stderr,_ ("ignoring %.4s extension" ), ext);break ; }return 0 ;
@@ -1767,7 +1768,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, extended_flags =get_be16 (&ondisk2->flags2) <<16 ;/* We do not yet understand any bit out of CE_EXTENDED_FLAGS */ if (extended_flags & ~CE_EXTENDED_FLAGS ) -die ("Unknown index entry format %08x" , extended_flags); +die (_ ("unknown index entry format 0x%08x" ), extended_flags); flags |= extended_flags; name = ondisk2->name; }
@@ -1840,13 +1841,13 @@ static void check_ce_order(struct index_state *istate)int name_compare =strcmp (ce->name, next_ce->name);if (0 < name_compare) -die ("unordered stage entries in index" ); +die (_ ("unordered stage entries in index" ));if (!name_compare) {if (!ce_stage (ce)) -die ("multiple stage entries for merged file '%s'" , +die (_ ("multiple stage entries for merged file '%s'" ), ce->name);if (ce_stage (ce) >ce_stage (next_ce)) -die ("unordered stage entries for '%s'" , +die (_ ("unordered stage entries for '%s'" ), ce->name); } }
@@ -2149,19 +2150,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)if (fd <0 ) {if (!must_exist && errno ==ENOENT )return 0 ; -die_errno ("%s: index file open failed" , path); +die_errno (_ ("%s: index file open failed" ), path); }if (fstat (fd, &st)) -die_errno ("cannot stat the open index" ); +die_errno (_ ("%s: cannot stat the open index" ), path); mmap_size =xsize_t (st.st_size);if (mmap_size <sizeof (struct cache_header ) + the_hash_algo->rawsz) -die ("index file smaller than expected" ); +die (_ ("%s: index file smaller than expected" ), path); mmap =xmmap (NULL , mmap_size,PROT_READ ,MAP_PRIVATE , fd,0 );if (mmap ==MAP_FAILED ) -die_errno ("unable to map index file" ); +die_errno (_ ("%s: unable to map index file" ), path);close (fd); hdr = (const struct cache_header *)mmap;
@@ -2243,7 +2244,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) unmap:munmap ((void *)mmap, mmap_size); -die ("index file corrupt" ); +die (_ ("index file corrupt" )); }/*
@@ -2255,7 +2256,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)static void freshen_shared_index (const char *shared_index,int warn) {if (!check_and_freshen_file (shared_index,1 ) && warn) -warning ("could not freshen shared index '%s'" , shared_index); +warning (_ ("could not freshen shared index '%s'" ), shared_index); } int read_index_from(struct index_state *istate, const char *path,
@@ -2290,7 +2291,7 @@ int read_index_from(struct index_state *istate, const char *path, base_path =xstrfmt ("%s/sharedindex.%s" , gitdir, base_oid_hex); ret =do_read_index (split_index->base, base_path,1 );if (!oideq (&split_index->base_oid, &split_index->base->oid)) -die ("broken index, expect %s in %s, got %s" , +die (_ ("broken index, expect %s in %s, got %s" ), base_oid_hex, base_path,oid_to_hex (&split_index->base->oid));
@@ -2356,14 +2357,14 @@ void validate_cache_entries(const struct index_state *istate)for (i =0 ; i < istate->cache_nr; i++) {if (!istate) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); }else if (!istate->ce_mem_pool || !mem_pool_contains (istate->ce_mem_pool, istate->cache[i])) {if (!istate->split_index || !istate->split_index->base || !istate->split_index->base->ce_mem_pool || !mem_pool_contains (istate->split_index->base->ce_mem_pool, istate->cache[i])) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); } } }
@@ -3076,7 +3077,7 @@ static int write_shared_index(struct index_state *istate,return ret; ret =adjust_shared_perm (get_tempfile_path (*temp));if (ret) { -error ("cannot fix permission bits on %s" ,get_tempfile_path (*temp)); +error (_ ("cannot fix permission bits on '%s'" ),get_tempfile_path (*temp));return ret; } ret = rename_tempfile(temp,
@@ -3222,7 +3223,7 @@ int read_index_unmerged(struct index_state *istate) new_ce->ce_namelen = len; new_ce->ce_mode = ce->ce_mode;if (add_index_entry (istate, new_ce,ADD_CACHE_SKIP_DFCHECK )) -return error ("%s: cannot drop to stage #0" , +return error (_ ("%s: cannot drop to stage #0" ), new_ce->name); }return unmerged;
t/t1450-fsck.sh +1 -1
@@ -754,7 +754,7 @@ test_expect_success 'detect corrupt index file in fsck' ' test_when_finished "mv .git/index.backup .git/index" && corrupt_index_checksum && test_must_fail git fsck --cache 2>errors && - grep "bad index file" errors + test_i18ngrep "bad index file" errors ' test_done
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 6/12 read-cache.c: add missing colon separators
In reply to Nguyễn Thái Ngọc Duytypechange_fmt and added_fmt should have a colon before "needs update". Align the statements to make it easier to read and see. Also drop the unnecessary ().
--- read-cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
read-cache.c +5 -5
@@ -1492,11 +1492,11 @@ int refresh_index(struct index_state *istate, unsigned int flags, istate->cache_nr);trace_performance_enter (); - modified_fmt = (in_porcelain ?"M\t%s\n" :"%s: needs update\n" ); - deleted_fmt = (in_porcelain ?"D\t%s\n" :"%s: needs update\n" ); - typechange_fmt = (in_porcelain ?"T\t%s\n" :"%s needs update\n" ); - added_fmt = (in_porcelain ?"A\t%s\n" :"%s needs update\n" ); - unmerged_fmt = (in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ); + modified_fmt = in_porcelain ?"M\t%s\n" :"%s: needs update\n" ; + deleted_fmt = in_porcelain ?"D\t%s\n" :"%s: needs update\n" ; + typechange_fmt = in_porcelain ?"T\t%s\n" :"%s: needs update\n" ; + added_fmt = in_porcelain ?"A\t%s\n" :"%s: needs update\n" ; + unmerged_fmt = in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ;for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce, *new_entry;int cache_errno =0 ;
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 7/12 reflog: mark strings for translation
In reply to Nguyễn Thái Ngọc Duy--- builtin/reflog.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
builtin/reflog.c +19 -15
@@ -13,11 +13,15 @@/* NEEDSWORK: switch to using parse_options */ static const char reflog_expire_usage[] = -"git reflog expire [--expire=<time>] [--expire-unreachable=<time>] [--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] [--verbose] [--all] <refs>..." ; +N_ ("git reflog expire [--expire=<time>] " +"[--expire-unreachable=<time>] " +"[--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] " +"[--verbose] [--all] <refs>..." );static const char reflog_delete_usage[] = -"git reflog delete [--rewrite] [--updateref] [--dry-run | -n] [--verbose] <refs>..." ; +N_ ("git reflog delete [--rewrite] [--updateref] " +"[--dry-run | -n] [--verbose] <refs>..." );static const char reflog_exists_usage[] = -"git reflog exists <ref>" ; +N_ ("git reflog exists <ref>" );static timestamp_t default_reflog_expire;static timestamp_t default_reflog_expire_unreachable;
@@ -556,7 +560,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_expire_usage); +usage (_ (reflog_expire_usage));else break ; }
@@ -569,7 +573,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)if (cb.cmd.stalefix) {repo_init_revisions (the_repository, &cb.cmd.revs, prefix);if (flags &EXPIRE_REFLOGS_VERBOSE ) -printf ("Marking reachable objects..." ); +printf (_ ("Marking reachable objects..." ));mark_reachable_objects (&cb.cmd.revs,0 ,0 ,NULL );if (flags &EXPIRE_REFLOGS_VERBOSE )putchar ('\n' );
@@ -598,7 +602,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)char *ref;struct object_id oid;if (!dwim_log (argv[i],strlen (argv[i]), &oid, &ref)) { - status |=error ("%s points nowhere!" , argv[i]); + status |=error (_ ("%s points nowhere!" ), argv[i]);continue ; }set_reflog_expiry_param (&cb.cmd, explicit_expiry, ref);
@@ -644,13 +648,13 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_delete_usage); +usage (_ (reflog_delete_usage));else break ; }if (argc - i <1 ) -return error ("Nothing to delete?" ); +return error (_ ("nothing to delete?" ));for ( ; i < argc; i++) {const char *spec =strstr (argv[i],"@{" );
@@ -659,12 +663,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)int recno;if (!spec) { - status |=error ("Not a reflog: %s" , argv[i]); + status |=error (_ ("not a reflog: %s" ), argv[i]);continue ; }if (!dwim_log (argv[i], spec - argv[i], &oid, &ref)) { - status |=error ("no reflog for '%s'" , argv[i]); + status |=error (_ ("no reflog for '%s'" ), argv[i]);continue ; }
@@ -699,7 +703,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));else break ; }
@@ -707,10 +711,10 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix) start = i;if (argc - start !=1 ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));if (check_refname_format (argv[start],REFNAME_ALLOW_ONELEVEL )) -die ("invalid ref format: %s" , argv[start]); +die (_ ("invalid ref format: %s" ), argv[start]);return !reflog_exists (argv[start]); }
@@ -719,12 +723,12 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)*/ static const char reflog_usage[] = -"git reflog [ show | expire | delete | exists ]" ; +N_ ("git reflog [ show | expire | delete | exists ]" );int cmd_reflog (int argc,const char **argv,const char *prefix) {if (argc >1 && !strcmp (argv[1 ],"-h" )) -usage (reflog_usage); +usage (_ (reflog_usage));/* With no command, we default to showing it. */ if (argc <2 || *argv[1 ] =='-' )
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 8/12 remote.c: mark messages for translation
In reply to Nguyễn Thái Ngọc Duy--- remote.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-)
remote.c +25 -24
@@ -359,7 +359,7 @@ static int handle_config(const char *key, const char *value, void *cb)return 0 ;/* Handle remote.<name>.* variables */ if (*name =='/' ) { -warning ("Config remote shorthand cannot begin with '/': %s" , +warning (_ ("config remote shorthand cannot begin with '/': %s" ), name);return 0 ; }
@@ -406,7 +406,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->receivepack) remote->receivepack = v;else -error ("more than one receivepack given, using the first" ); +error (_ ("more than one receivepack given, using the first" )); }else if (!strcmp (subkey,"uploadpack" )) {const char *v;if (git_config_string (&v, key, value))
@@ -414,7 +414,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->uploadpack) remote->uploadpack = v;else -error ("more than one uploadpack given, using the first" ); +error (_ ("more than one uploadpack given, using the first" )); }else if (!strcmp (subkey,"tagopt" )) {if (!strcmp (value,"--no-tags" )) remote->fetch_tags =-1 ;
@@ -620,7 +620,7 @@ static void handle_duplicate(struct ref *ref1, struct ref *ref2)* FETCH_HEAD_IGNORE entries always appear at * the end of the list. */ -die (_ ("Internal error" )); +BUG ("Internal error" ); } }free (ref2->peer_ref);
@@ -680,7 +680,7 @@ static int match_name_with_pattern(const char *key, const char *name,size_t namelen;int ret;if (!kstar) -die ("Key '%s' of pattern had no '*'" , key); +die (_ ("key '%s' of pattern had no '*'" ), key); klen = kstar - key; ksuffixlen =strlen (kstar +1 ); namelen =strlen (name);
@@ -690,7 +690,7 @@ static int match_name_with_pattern(const char *key, const char *name,struct strbuf sb =STRBUF_INIT ;const char *vstar =strchr (value,'*' );if (!vstar) -die ("Value '%s' of pattern has no '*'" , value); +die (_ ("value '%s' of pattern has no '*'" ), value);strbuf_add (&sb, value, vstar - value);strbuf_add (&sb, name + klen, namelen - klen - ksuffixlen);strbuf_addstr (&sb, vstar +1 );
@@ -707,7 +707,7 @@ static void query_refspecs_multiple(struct refspec *rs,int find_src = !query->src;if (find_src && !query->dst) -error ("query_refspecs_multiple: need either src or dst" ); +BUG ("query_refspecs_multiple: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
@@ -735,7 +735,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)char **result = find_src ? &query->src : &query->dst;if (find_src && !query->dst) -return error ("query_refspecs: need either src or dst" ); +BUG ("query_refspecs: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
@@ -995,12 +995,12 @@ static int match_explicit_lhs(struct ref *src,* way to delete 'other' ref at the remote end. */ if (try_explicit_object_name (rs->src, match) <0 ) -return error ("src refspec %s does not match any." , rs->src); +return error (_ ("src refspec %s does not match any" ), rs->src);if (allocated_match) *allocated_match =1 ;return 0 ;default : -return error ("src refspec %s matches more than one." , rs->src); +return error (_ ("src refspec %s matches more than one" ), rs->src); } }
@@ -1030,7 +1030,7 @@ static int match_explicit(struct ref *src, struct ref *dst,if (!dst_value || ((flag &REF_ISSYMREF ) && !starts_with (dst_value,"refs/heads/" ))) -die ("%s cannot be resolved to branch." , +die (_ ("%s cannot be resolved to branch" ), matched_src->name); }
@@ -1041,30 +1041,30 @@ static int match_explicit(struct ref *src, struct ref *dst,if (starts_with (dst_value,"refs/" )) matched_dst =make_linked_ref (dst_value, dst_tail);else if (is_null_oid (&matched_src->new_oid)) -error ("unable to delete '%s': remote ref does not exist" , +error (_ ("unable to delete '%s': remote ref does not exist" ), dst_value);else if ((dst_guess =guess_ref (dst_value, matched_src))) { matched_dst =make_linked_ref (dst_guess, dst_tail);free (dst_guess); }else -error ("unable to push to unqualified destination: %s\n" -"The destination refspec neither matches an " -"existing ref on the remote nor\n" -"begins with refs/, and we are unable to " -"guess a prefix based on the source ref." , +error (_ ("unable to push to unqualified destination: %s\n" +"The destination refspec neither matches an " +"existing ref on the remote nor\n" +"begins with refs/, and we are unable to " +"guess a prefix based on the source ref." ), dst_value);break ;default : matched_dst =NULL ; -error ("dst refspec %s matches more than one." , +error (_ ("dst refspec %s matches more than one" ), dst_value);break ; }if (!matched_dst)return -1 ;if (matched_dst->peer_ref) -return error ("dst ref %s receives from more than one src." , - matched_dst->name); +return error (_ ("dst ref %s receives from more than one src" ), + matched_dst->name);else { matched_dst->peer_ref = allocated_src ? matched_src :
@@ -1750,7 +1750,7 @@ int get_fetch_map(const struct ref *remote_refs, ref_map =get_remote_ref (remote_refs, name); }if (!missing_ok && !ref_map) -die ("Couldn't find remote ref %s" , name); +die (_ ("couldn't find remote ref %s" ), name);if (ref_map) { ref_map->peer_ref =get_local_ref (refspec->dst);if (ref_map->peer_ref && refspec->force)
@@ -1763,7 +1763,7 @@ int get_fetch_map(const struct ref *remote_refs,if (!starts_with ((*rmp)->peer_ref->name,"refs/" ) ||check_refname_format ((*rmp)->peer_ref->name,0 )) {struct ref *ignore = *rmp; -error ("* Ignoring funny ref '%s' locally" , +error (_ ("* Ignoring funny ref '%s' locally" ), (*rmp)->peer_ref->name); *rmp = (*rmp)->next;free (ignore->peer_ref);
@@ -1858,7 +1858,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,repo_init_revisions (the_repository, &revs,NULL );setup_revisions (argv.argc, argv.argv, &revs,NULL );if (prepare_revision_walk (&revs)) -die ("revision walk setup failed" ); +die (_ ("revision walk setup failed" ));/* ... and count the commits on each side. */ while (1 ) {
@@ -2131,7 +2131,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, ielse if (!colon[1 ])oidclr (&entry->expect);else if (get_oid (colon +1 , &entry->expect)) -return error ("cannot parse expected object name '%s'" , colon +1 ); +return error (_ ("cannot parse expected object name '%s'" ), + colon +1 );return 0 ; }
Signature · 1 line
2.19.1.647.g708186aaf9
Re: [PATCH 08/12] remote.c: mark messages for translation
Quoted 4 lines · Nguyễn Thái Ngọc Duy
remote.c +0
-0@@ -995,12 +995,12 @@ static int match_explicit_lhs(struct ref *src,* way to delete 'other' ref at the remote end. */ if (try_explicit_object_name (rs->src, match) <0 )
remote.c static int match_explicit_lhs(struct ref *src, · line 1005
Quoted 10 lines
remote.c +2
-2-return error ("src refspec %s does not match any." , rs->src); +return error (_ ("src refspec %s does not match any" ), rs->src);if (allocated_match) *allocated_match =1 ;return 0 ;default : -return error ("src refspec %s matches more than one." , rs->src); +return error (_ ("src refspec %s matches more than one" ), rs->src); } }
These minor changes that are not accompanied by their own justification mean that the patches in this series cannot blindly be trusted, which in turn means that I won't have bandwidth to process this series properly for now.
I also saw die() -> BUG() that was not highlighted in the proposed log message; the single instance I happened to notice looked sensible, but I am not sure about the others.
There are other series in flight that touch the same area of code and in different ways, causing unnecessary conflicts, which does not help us either X-<.
Re: [PATCH 08/12] remote.c: mark messages for translation
Quoted 3 lines · Junio C Hamano
There are other series in flight that touch the same area of code and in different ways, causing unnecessary conflicts, which does not help us either X-<.
I will of course fix all other comments, but I can hold this off if it's causing too much trouble. I'm in no hurry to get anything merged fast.
Signature · 1 line
Duy
PATCH 9/12 repack: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duy--- builtin/repack.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
builtin/repack.c +13 -13
@@ -197,7 +197,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,if (cmd->in ==-1 ) {if (start_command (cmd)) -die ("Could not start pack-objects to repack promisor objects" ); +die (_ ("could not start pack-objects to repack promisor objects" )); }xwrite (cmd->in,oid_to_hex (oid),GIT_SHA1_HEXSZ );
@@ -236,7 +236,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,char *promisor_name;int fd;if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects." ));string_list_append (names, line.buf);/*
@@ -247,13 +247,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args, line.buf); fd =open (promisor_name,O_CREAT |O_EXCL |O_WRONLY ,0600 );if (fd <0 ) -die_errno ("unable to create '%s'" , promisor_name); +die_errno (("unable to create '%s'" ), promisor_name);close (fd);free (promisor_name); }fclose (out);if (finish_command (&cmd)) -die ("Could not finish pack-objects to repack promisor objects" ); +die (_ ("could not finish pack-objects to repack promisor objects" )); }#define ALL_INTO_ONE 1
@@ -408,7 +408,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) out =xfdopen (cmd.out,"r" );while (strbuf_getline_lf (&line, out) !=EOF ) {if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects" ));string_list_append (&names, line.buf); }fclose (out);
@@ -417,7 +417,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)return ret;if (!names.nr && !po_args.quiet) -printf ("Nothing new to pack.\n" ); +printf_ln (_ ("Nothing new to pack." ));/* * Ok we have prepared all new packfiles.
@@ -477,13 +477,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)if (rollback_failure.nr) {int i;fprintf (stderr, -"WARNING: Some packs in use have been renamed by\n" -"WARNING: prefixing old- to their name, in order to\n" -"WARNING: replace them with the new version of the\n" -"WARNING: file. But the operation failed, and the\n" -"WARNING: attempt to rename them back to their\n" -"WARNING: original names also failed.\n" -"WARNING: Please rename them in %s manually:\n" , packdir); +_ ("WARNING: Some packs in use have been renamed by\n" +"WARNING: prefixing old- to their name, in order to\n" +"WARNING: replace them with the new version of the\n" +"WARNING: file. But the operation failed, and the\n" +"WARNING: attempt to rename them back to their\n" +"WARNING: original names also failed.\n" +"WARNING: Please rename them in %s manually:\n" ), packdir);for (i =0 ; i < rollback_failure.nr; i++) fprintf(stderr, "WARNING: old-%s -> %s\n", rollback_failure.items[i].string,
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 10/12 parse-options: replace opterror() with optname()
In reply to Nguyễn Thái Ngọc DuyThere are a few issues with opterror()
- it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence.
- It's a wrapper around error() and needs some hack to let the compiler know it always returns -1.
- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
Kill it and produce the option name with optname(). The user will use error() directly. This solves the second and third problems.
It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling optname() when 'flags' is known in advance.
Mark of these strings for translation as well while at there.
--- builtin/merge.c | 2 +- builtin/revert.c | 3 ++- parse-options-cb.c | 7 ++++--- parse-options.c | 46 +++++++++++++++++++++++++-------------------- parse-options.h | 5 +---- ref-filter.c | 8 +++++--- t/t4211-line-log.sh | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-)
builtin/merge.c +1 -1
@@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx, ctx->argc--; arg = *++ctx->argv; }else -return opterror (opt,"requires a value" ,0 ); +return error (_ ("option `%s' requires a value" ), opt->long_name);if (buf->len)strbuf_addch (buf,'\n' );
builtin/revert.c +2 -1
@@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt, replay->mainline =strtol (arg, &end,10 );if (*end || replay->mainline <=0 ) -return opterror (opt,"expects a number greater than zero" ,0 ); +return error (_ ("option `%s' expects a number greater than zero" ), + opt->long_name);return 0 ; }
parse-options-cb.c +4 -3
@@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) }else { v =strtol (arg, (char **)&arg,10 );if (*arg) -return opterror (opt,"expects a numerical value" ,0 ); +return error (_ ("option `%s' expects a numerical value" ), + opt->long_name);if (v && v <MINIMUM_ABBREV ) v =MINIMUM_ABBREV ;else if (v >40 )
@@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg, arg = unset ?"never" : (const char *)opt->defval; value =git_config_colorbool (NULL , arg);if (value <0 ) -return opterror (opt, -"expects \"always\", \"auto\", or \"never\"" ,0 ); +return error (_ ("option `%s' expects \"always\", \"auto\", or \"never\"" ), + opt->long_name); *(int *)opt->value = value;return 0 ; }
parse-options.c +26 -20
99 lines not on this page · raw message
parse-options.h +1 -4
@@ -189,10 +189,7 @@ extern NORETURN void usage_msg_opt(const char *msg, const struct option *options);extern int optbug (const struct option *opt,const char *reason); -extern int opterror (const struct option *opt,const char *reason,int flags); -#if defined(__GNUC__) -#define opterror (o,r,f) (opterror((o),(r),(f)), const_error()) -#endif +const char *optname (const struct option *opt,int flags);/*----- incremental advanced APIs -----*/
ref-filter.c +5 -3
@@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)if (rf->merge) {if (no_merged) { -return opterror (opt,"is incompatible with --merged" ,0 ); +return error (_ ("option `%s' is incompatible with --merged" ), + opt->long_name); }else { -return opterror (opt,"is incompatible with --no-merged" ,0 ); +return error (_ ("option `%s' is incompatible with --no-merged" ), + opt->long_name); } }
@@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) rf->merge_commit =lookup_commit_reference_gently (the_repository, &oid,0 );if (!rf->merge_commit) -return opterror (opt,"must point to a commit" ,0 ); +return error (_ ("option `%s' must point to a commit" ), opt->long_name);return 0 ; }
t/t4211-line-log.sh +1 -1
@@ -25,7 +25,7 @@ canned_test_failure () { test_bad_opts () { test_expect_success "invalid args: $1" " test_must_fail git log $1 2>errors && - grep '$2' errors + test_i18ngrep '$2' errors " }
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 11/12 parse-options.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duy--- parse-options.c | 18 +++++++++--------- t/t0040-parse-options.sh | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)
parse-options.c +9 -9
@@ -197,7 +197,7 @@ static int get_value(struct parse_opt_ctx_t *p,return 0 ;default : -die ("should not happen, someone must be hit on the forehead" ); +BUG ("opt->type %d should not happen, someone must be hit on the forehead" , opt->type); } }
@@ -319,8 +319,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, }if (ambiguous_option) { - error("Ambiguous option: %s " - "(could be --%s%s or --%s%s)", + error(_("ambiguous option: %s " + "(could be --%s%s or --%s%s)"), arg, (ambiguous_flags & OPT_UNSET) ? "no-" : "", ambiguous_option->long_name,
@@ -353,7 +353,7 @@ static void check_typos(const char *arg, const struct option *options)return ;if (starts_with (arg,"no-" )) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); }
@@ -361,7 +361,7 @@ static void check_typos(const char *arg, const struct option *options)if (!options->long_name)continue ;if (starts_with (options->long_name, arg)) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); } }
@@ -424,7 +424,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->flags = flags;if ((flags &PARSE_OPT_KEEP_UNKNOWN ) && (flags &PARSE_OPT_STOP_AT_NON_OPTION )) -die ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" ); +BUG ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" );parse_options_check (options); }
@@ -644,11 +644,11 @@ int parse_options(int argc, const char **argv, const char *prefix,break ;default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) { -error ("unknown option `%s'" , ctx.argv[0 ] +2 ); +error (_ ("unknown option `%s'" ), ctx.argv[0 ] +2 ); }else if (isascii (*ctx.opt)) { -error ("unknown switch `%c'" , *ctx.opt); +error (_ ("unknown switch `%c'" ), *ctx.opt); }else { -error ("unknown non-ascii option in string: `%s'" , +error (_ ("unknown non-ascii option in string: `%s'" ), ctx.argv[0 ]); }usage_with_options (usagestr, options);
t/t0040-parse-options.sh +2 -2
@@ -228,7 +228,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -boolean >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' cat >typo.err <<\EOF
@@ -238,7 +238,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -ambiguous >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' test_expect_success 'keep some options as arguments' '
Signature · 1 line
2.19.1.647.g708186aaf9
PATCH 12/12 fsck: mark strings for translation
In reply to Nguyễn Thái Ngọc Duy--- builtin/fsck.c | 113 ++++++++++++++++++++----------------- t/t1410-reflog.sh | 6 +- t/t1450-fsck.sh | 50 ++++++++-------- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +- 5 files changed, 94 insertions(+), 85 deletions(-)
builtin/fsck.c +61 -52
@@ -108,8 +108,9 @@ static int fsck_config(const char *var, const char *value, void *cb)static void objreport (struct object *obj,const char *msg_type,const char *err) { -fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); +fprintf_ln (stderr,_ ("%s in %s %s: %s" ), + msg_type,printable_type (obj), +describe_object (obj), err); }static int objerror (struct object *obj,const char *err)
@@ -139,17 +140,18 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt*/ if (!obj) {/* ... these references to parent->fld are safe here */ -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf ("broken link from %7s %s\n" , - (type ==OBJ_ANY ?"unknown" :type_name (type)),"unknown" ); +printf_ln (_ ("broken link from %7s %s" ), +printable_type (parent),describe_object (parent)); +printf_ln (_ ("broken link from %7s %s" ), + (type ==OBJ_ANY ?_ ("unknown" ) :type_name (type)), +_ ("unknown" )); errors_found |=ERROR_REACHABLE ;return 1 ; }if (type !=OBJ_ANY && obj->type != type)/* ... and the reference to parent is safe here */ -objerror (parent,"wrong object type in link" ); +objerror (parent,_ ("wrong object type in link" ));if (obj->flags &REACHABLE )return 0 ;
@@ -165,10 +167,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_optif (!(obj->flags &HAS_OBJ )) {if (parent && !has_object_file (&obj->oid)) { -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf (" to %7s %s\n" , -printable_type (obj),describe_object (obj)); +printf_ln (_ ("broken link from %7s %s\n" +" to %7s %s" ), +printable_type (parent), +describe_object (parent), +printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ; }return 1 ;
@@ -232,8 +236,8 @@ static void check_reachable_object(struct object *obj)return ;if (has_object_pack (&obj->oid))return ;/* it is in pack - forget about it */ -printf ("missing %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("missing %s %s" ),printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ;return ; }
@@ -258,8 +262,8 @@ static void check_unreachable_object(struct object *obj)* since this is something that is prunable. */ if (show_unreachable) { -printf ("unreachable %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("unreachable %s %s" ),printable_type (obj), +describe_object (obj));return ; }
@@ -277,8 +281,8 @@ static void check_unreachable_object(struct object *obj)*/ if (!(obj->flags &USED )) {if (show_dangling) -printf ("dangling %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("dangling %s %s" ),printable_type (obj), +describe_object (obj));if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -286,18 +290,18 @@ static void check_unreachable_object(struct object *obj)FILE *f;if (safe_create_leading_directories_const (filename)) { -error ("Could not create lost-found" ); +error (_ ("could not create lost-found" ));free (filename);return ; } f =xfopen (filename,"w" );if (obj->type ==OBJ_BLOB ) {if (stream_blob_to_fd (fileno (f), &obj->oid,NULL ,1 )) -die_errno ("Could not write '%s'" , filename); +die_errno (_ ("could not write '%s'" ), filename); }else fprintf (f,"%s\n" ,describe_object (obj));if (fclose (f)) -die_errno ("Could not finish '%s'" , +die_errno (_ ("could not finish '%s'" ), filename);free (filename); }
@@ -314,7 +318,7 @@ static void check_unreachable_object(struct object *obj)static void check_object (struct object *obj) {if (verbose) -fprintf (stderr,"Checking %s\n" ,describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s" ),describe_object (obj));if (obj->flags &REACHABLE )check_reachable_object (obj);
@@ -332,7 +336,7 @@ static void check_connectivity(void)/* Look up all the requirements, warn about missing objects.. */ max =get_max_object_index ();if (verbose) -fprintf (stderr,"Checking connectivity (%d objects)\n" , max); +fprintf_ln (stderr,_ ("Checking connectivity (%d objects)" ), max);for (i =0 ; i < max; i++) {struct object *obj =get_indexed_object (i);
@@ -351,11 +355,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) obj->flags |=SEEN ;if (verbose) -fprintf (stderr,"Checking %s %s\n" , -printable_type (obj),describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s %s" ), +printable_type (obj),describe_object (obj));if (fsck_walk (obj,NULL , &fsck_obj_options)) -objerror (obj,"broken links" ); +objerror (obj,_ ("broken links" )); err =fsck_object (obj, buffer, size, &fsck_obj_options);if (err) goto out;
@@ -364,17 +368,19 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)struct commit *commit = (struct commit *) obj;if (!commit->parents && show_root) -printf ("root %s\n" ,describe_object (&commit->object)); +printf_ln (_ ("root %s" ), +describe_object (&commit->object)); }if (obj->type ==OBJ_TAG ) {struct tag *tag = (struct tag *) obj;if (show_tags && tag->tagged) { -printf ("tagged %s %s" ,printable_type (tag->tagged), -describe_object (tag->tagged)); -printf (" (%s) in %s\n" , tag->tag, -describe_object (&tag->object)); +printf (_ ("tagged %s %s (%s) in %s" ), +printable_type (tag->tagged), +describe_object (tag->tagged), + tag->tag, +describe_object (&tag->object)); } }
@@ -398,7 +404,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, eaten);if (!obj) { errors_found |=ERROR_OBJECT ; -return error ("%s: object corrupt or missing" ,oid_to_hex (oid)); +return error (_ ("%s: object corrupt or missing" ), +oid_to_hex (oid)); } obj->flags &= ~(REACHABLE |SEEN ); obj->flags |=HAS_OBJ ;
@@ -422,7 +429,8 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, obj->flags |=USED ;mark_object_reachable (obj); }else if (!is_promisor_object (oid)) { -error ("%s: invalid reflog entry %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid reflog entry %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ; } }
@@ -435,8 +443,8 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noidconst char *refname = cb_data;if (verbose) -fprintf (stderr,"Checking reflog %s->%s\n" , -oid_to_hex (ooid),oid_to_hex (noid)); +fprintf_ln (stderr,_ ("Checking reflog %s->%s" ), +oid_to_hex (ooid),oid_to_hex (noid));fsck_handle_reflog_oid (refname, ooid,0 );fsck_handle_reflog_oid (refname, noid, timestamp);
@@ -465,13 +473,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, default_refs++;return 0 ; } -error ("%s: invalid sha1 pointer %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid sha1 pointer %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ;/* We'll continue with the rest despite the error.. */ return 0 ; }if (obj->type !=OBJ_COMMIT &&is_branch (refname)) { -error ("%s: not a commit" , refname); +error (_ ("%s: not a commit" ), refname); errors_found |=ERROR_REFS ; } default_refs++;
@@ -505,7 +514,7 @@ static void get_default_heads(void)* "show_unreachable" flag. */ if (!default_refs) { -fprintf (stderr,"notice: No default references\n" ); +fprintf_ln (stderr,_ ("notice: No default references" )); show_unreachable =0 ; } }
@@ -520,7 +529,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (read_loose_object (path, oid, &type, &size, &contents) <0 ) { errors_found |=ERROR_OBJECT ; -error ("%s: object corrupt or missing: %s" , +error (_ ("%s: object corrupt or missing: %s" ),oid_to_hex (oid), path);return 0 ;/* keep checking other objects */ }
@@ -533,7 +542,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (!obj) { errors_found |=ERROR_OBJECT ; -error ("%s: object could not be parsed: %s" , +error (_ ("%s: object could not be parsed: %s" ),oid_to_hex (oid), path);if (!eaten)free (contents);
@@ -553,7 +562,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)static int fsck_cruft (const char *basename,const char *path,void *data) {if (!starts_with (basename,"tmp_obj_" )) -fprintf (stderr,"bad sha1 file: %s\n" , path); +fprintf_ln (stderr,_ ("bad sha1 file: %s" ), path);return 0 ; }
@@ -568,7 +577,7 @@ static void fsck_object_dir(const char *path)struct progress *progress =NULL ;if (verbose) -fprintf (stderr,"Checking object directory\n" ); +fprintf_ln (stderr,_ ("Checking object directory" ));if (show_progress) progress =start_progress (_ ("Checking object directories" ),256 );
@@ -584,28 +593,28 @@ static int fsck_head_link(void)int null_is_error =0 ;if (verbose) -fprintf (stderr,"Checking HEAD link\n" ); +fprintf_ln (stderr,_ ("Checking HEAD link" )); head_points_at =resolve_ref_unsafe ("HEAD" ,0 , &head_oid,NULL );if (!head_points_at) { errors_found |=ERROR_REFS ; -return error ("Invalid HEAD" ); +return error (_ ("invalid HEAD" )); }if (!strcmp (head_points_at,"HEAD" ))/* detached HEAD */ null_is_error =1 ;else if (!starts_with (head_points_at,"refs/heads/" )) { errors_found |=ERROR_REFS ; -return error ("HEAD points to something strange (%s)" , +return error (_ ("HEAD points to something strange (%s)" ), head_points_at); }if (is_null_oid (&head_oid)) {if (null_is_error) { errors_found |=ERROR_REFS ; -return error ("HEAD: detached HEAD points at nothing" ); +return error (_ ("HEAD: detached HEAD points at nothing" )); } -fprintf (stderr,"notice: HEAD points to an unborn branch (%s)\n" , - head_points_at +11 ); +fprintf_ln (stderr,_ ("notice: HEAD points to an unborn branch (%s)" ), + head_points_at +11 ); }return 0 ; }
@@ -616,12 +625,12 @@ static int fsck_cache_tree(struct cache_tree *it)int err =0 ;if (verbose) -fprintf (stderr,"Checking cache tree\n" ); +fprintf_ln (stderr,_ ("Checking cache tree" ));if (0 <= it->entry_count) {struct object *obj =parse_object (the_repository, &it->oid);if (!obj) { -error ("%s: invalid sha1 pointer in cache-tree" , +error (_ ("%s: invalid sha1 pointer in cache-tree" ),oid_to_hex (&it->oid)); errors_found |=ERROR_REFS ;return 1 ;
@@ -632,7 +641,7 @@ static int fsck_cache_tree(struct cache_tree *it) obj, xstrdup(":"));mark_object_reachable (obj);if (obj->type !=OBJ_TREE ) - err |=objerror (obj,"non-tree in cache-tree" ); + err |=objerror (obj,_ ("non-tree in cache-tree" )); }for (i =0 ; i < it->subtree_nr; i++) err |=fsck_cache_tree (it->down[i]->cache_tree);
@@ -774,7 +783,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (!obj || !(obj->flags &HAS_OBJ )) {if (is_promisor_object (&oid))continue ; -error ("%s: object missing" ,oid_to_hex (&oid)); +error (_ ("%s: object missing" ),oid_to_hex (&oid)); errors_found |=ERROR_OBJECT ;continue ; }
@@ -786,7 +795,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)mark_object_reachable (obj);continue ; } -error ("invalid parameter: expected sha1, got '%s'" , arg); +error (_ ("invalid parameter: expected sha1, got '%s'" ), arg); errors_found |=ERROR_OBJECT ; }
t/t1410-reflog.sh +3 -3
@@ -20,12 +20,12 @@ check_have () { } check_fsck () { - output=$(git fsck --full) + git fsck --full >fsck.output case "$1" in '') - test -z "$output" ;; + test_must_be_empty fsck.output ;; *) - echo "$output" | grep "$1" ;; + test_i18ngrep "$1" fsck.output ;; esac }
t/t1450-fsck.sh +25 -25
189 lines not on this page · raw message
t/t6050-replace.sh +2 -2
@@ -133,8 +133,8 @@ test_expect_success 'tag replaced commit' ' test_expect_success '"git fsck" works' ' git fsck master >fsck_master.out && - grep "dangling commit $R" fsck_master.out && - grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + test_i18ngrep "dangling commit $R" fsck_master.out && + test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" '
t/t7415-submodule-names.sh +3 -3
@@ -154,7 +154,7 @@ test_expect_success 'fsck detects symlinked .gitmodules file' ' # symlink detector; this grep string comes from the config # variable name and will not be translated. test_must_fail git fsck 2>output && - grep gitmodulesSymlink output + test_i18ngrep gitmodulesSymlink output ) '
@@ -172,7 +172,7 @@ test_expect_success 'fsck detects non-blob .gitmodules' ' git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree && test_must_fail git fsck 2>output && - grep gitmodulesBlob output + test_i18ngrep gitmodulesBlob output ) '
@@ -186,7 +186,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' ' git commit -m "broken gitmodules" && git fsck 2>output && - grep gitmodulesParse output && + test_i18ngrep gitmodulesParse output && test_i18ngrep ! "bad config" output ) '
Signature · 1 line
2.19.1.647.g708186aaf9
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 14 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/fsck.c | 113 ++++++++++++++++++++----------------- t/t1410-reflog.sh | 6 +- t/t1450-fsck.sh | 50 ++++++++-------- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +- 5 files changed, 94 insertions(+), 85 deletions(-)builtin/fsck.c +0
-0
builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 111
Quoted 6 lines
builtin/fsck.c +1
-2@@ -108,8 +108,9 @@ static int fsck_config(const char *var, const char *value, void *cb)static void objreport (struct object *obj,const char *msg_type,const char *err) { -fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),
Are the (f)printf() -> (f)printf_ln() changes all over 'builtin/fsck.c' really necessary to mark strings for translation?
t/t1450-fsck.sh test_expect_success 'fsck --name-objects' ' · line 597
Quoted 11 lines
t/t1450-fsck.sh +1
-1@@ -594,7 +594,7 @@ test_expect_success 'fsck --name-objects' ' remove_object $(git rev-parse julius:caesar.t) && test_must_fail git fsck --name-objects >out && tree=$(git rev-parse --verify julius:) && - egrep "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out + test -n "$GETTEXT_POISON" || egrep "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out
'test_i18ngrep' accepts all 'grep' options, so this could be written as:
test_i18ngrep -E "..." out
There might be something else wrong with the patch, because now this test tends to fail on current 'pu' on Travis CI:
[... snipped output from 'test_commit' ...]
+git rev-parse julius:caesar.t
+remove_object be45bbd3809e0829297cefa576e699c134abacfd
+sha1_file be45bbd3809e0829297cefa576e699c134abacfd
+remainder=45bbd3809e0829297cefa576e699c134abacfd
+firsttwo=be
+echo .git/objects/be/45bbd3809e0829297cefa576e699c134abacfd
+rm .git/objects/be/45bbd3809e0829297cefa576e699c134abacfd
+test_must_fail git fsck --name-objects
+_test_ok=
+git fsck --name-objects
+exit_code=2
+test 2 -eq 0
+test_match_signal 13 2
+test 2 = 141
+test 2 = 269
+return 1
+test 2 -gt 129
+test 2 -eq 127
+test 2 -eq 126
+return 0
+git rev-parse --verify julius:
+tree=c2fab98f409a47394d992eca10a20e0b22377c0c
+test -n
+egrep c2fab98f409a47394d992eca10a20e0b22377c0c \((refs/heads/master|HEAD)@\{[0-9]*\}: out
error: last command exited with $?=1
not ok 65 - fsck --name-objectsThe contents of 'out':
broken link from tree be45bbd3809e0829297cefa576e699c134abacfd (refs/heads/master@{1112912113}:caesar.t)
to blob be45bbd3809e0829297cefa576e699c134abacfd (refs/heads/master@{1112912113}:caesar.t) missing blob be45bbd3809e0829297cefa576e699c134abacfd (refs/heads/master@{1112912113}:caesar.t)
On a related (side)note, I think it would be better if this 'grep' pattern were more explicit about which of the three lines it is supposed to match.
Anyway, I couldn't reproduce the failure locally yet, but, admittedly, I didn't try that hard... And my builds on Travis CI haven't yet come that far to try this topic on its own.
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 6 lines · SZEDER Gábor
builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 111
Quoted 3 lines
builtin/fsck.c +1
-2-fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),Are the (f)printf() -> (f)printf_ln() changes all over '
builtin/fsck.c' really necessary to mark strings for translation?
It is beyond absolute minimum but I saw it argued here that this makes it easier to manage the .po and .pot files if your message strings do not end with LF, a you are much less likely to _add_ unneeded LF to the translated string than _lose_ LF at the end of translated string.
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · SZEDER Gábor
Quoted 3 lines
builtin/fsck.c +1
-2-fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),
Quoted 8 lines
Quoted 2 lines
Are the (f)printf() -> (f)printf_ln() changes all over '
builtin/fsck.c' really necessary to mark strings for translation?It is beyond absolute minimum but I saw it argued here that this makes it easier to manage the .po and .pot files if your message strings do not end with LF, a you are much less likely to _add_ unneeded LF to the translated string than _lose_ LF at the end of translated string.
Especially when \n plays an important role and we don't trust translators to keep it [1] [2]. It's probably a too defensive stance and often does not apply, so nowadays I do it just to keep a consistent pattern in the code.
[1] https://public-inbox.org/git/20120308220131.GA10122@burratino/#t
[2] but then translators can crash programs anyway (e.g. changing %d to %s...) we just trust gettext tools to catch problems early.
Signature · 1 line
Duy
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 17 lines · Duy Nguyen
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · SZEDER Gábor
Quoted 3 lines
builtin/fsck.c +1
-2-fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),Quoted 8 lines
Quoted 2 lines
Are the (f)printf() -> (f)printf_ln() changes all over '
builtin/fsck.c' really necessary to mark strings for translation?It is beyond absolute minimum but I saw it argued here that this makes it easier to manage the .po and .pot files if your message strings do not end with LF, a you are much less likely to _add_ unneeded LF to the translated string than _lose_ LF at the end of translated string.
Quoted 8 lines
Especially when \n plays an important role and we don't trust translators to keep it [1] [2]. It's probably a too defensive stance and often does not apply, so nowadays I do it just to keep a consistent pattern in the code.
[1] https://public-inbox.org/git/20120308220131.GA10122@burratino/#t
[2] but then translators can crash programs anyway (e.g. changing %d to %s...) we just trust gettext tools to catch problems early.
As Jonathan pointed out in the follow-up message[1] this sort of thing is checked for in msgfmt, so sure, let's strip the \n, but it's really not something we need to worry about. Likewise with translators turning "%s" into "%d" (or "% s") or whatever.
$ git diff -U0
diff --git a/po/de.po b/po/de.po
index 47986814c9..62de46c63d 100644
--- a/po/de.po
+++ b/po/de.po
@@ -23 +23 @@ msgid "%shint: %.*s%s\n"
-msgstr "%sHinweis: %.*s%s\n"
+msgstr "%sHinweis: %.*s%s"
$ make [...]
[...]
po/de.po:23: 'msgid' and 'msgstr' entries do not both end with '\n'
msgfmt: found 1 fatal error
3470 translated messages.
make: *** [Makefile:2488: po/build/locale/de/LC_MESSAGES/git.mo] Error 11. https://public-inbox.org/git/CACsJy8AcUy9FZiiehGc7mEL4i+XP6u0pmH1rGoR-WZnhYT1UMQ@mail.gmail.com/
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 48 lines · Ævar Arnfjörð Bjarmason
Quoted 17 lines · Duy Nguyen
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · SZEDER Gábor
Quoted 3 lines
builtin/fsck.c +1
-2-fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),Quoted 8 lines
Quoted 2 lines
Are the (f)printf() -> (f)printf_ln() changes all over '
builtin/fsck.c' really necessary to mark strings for translation?It is beyond absolute minimum but I saw it argued here that this makes it easier to manage the .po and .pot files if your message strings do not end with LF, a you are much less likely to _add_ unneeded LF to the translated string than _lose_ LF at the end of translated string.
Quoted 8 lines
Especially when \n plays an important role and we don't trust translators to keep it [1] [2]. It's probably a too defensive stance and often does not apply, so nowadays I do it just to keep a consistent pattern in the code.
[1] https://public-inbox.org/git/20120308220131.GA10122@burratino/#t
[2] but then translators can crash programs anyway (e.g. changing %d to %s...) we just trust gettext tools to catch problems early.As Jonathan pointed out in the follow-up message[1] this sort of thing is checked for in msgfmt, so sure, let's strip the \n, but it's really not something we need to worry about. Likewise with translators turning "%s" into "%d" (or "% s") or whatever.
$ git diff -U0 diff --git a/po/de.po b/po/de.po index 47986814c9..62de46c63d 100644 --- a/po/de.po +++ b/po/de.po @@ -23 +23 @@ msgid "%shint: %.*s%s\n" -msgstr "%sHinweis: %.*s%s\n" +msgstr "%sHinweis: %.*s%s" $ make [...] [...] po/de.po:23: 'msgid' and 'msgstr' entries do not both end with '\n' msgfmt: found 1 fatal error 3470 translated messages. make: *** [Makefile:2488: po/build/locale/de/LC_MESSAGES/git.mo] Error 1
Quoted 1 line
1. https://public-inbox.org/git/CACsJy8AcUy9FZiiehGc7mEL4i+XP6u0pmH1rGoR-WZnhYT1UMQ@mail.gmail.com/
...to add to that, if there *are* formatting errors that --check doesn't spot let's hear about it so we can just patch gettext upstream:
https://github.com/autotools-mirror/gettext/blob/master/gettext-tools/src/msgl-check.c#L572-L756
Unlike the rest of our stack where we need to support however many years old tools we can freely rely on bleeding-edge gettext features, since the only person we need to convince to upgrade is Jiang. I.e. he accepts the PRs from translators, (presumably) runs msgfmt --check and then submits the result to Junio.
See the "Usually..." paragraph in my 66f5f6dca9 ("C style: use standard style for "TRANSLATORS" comments", 2017-05-11) for an example. We already rely on a fairly recent gettext toolchain.
Re: [PATCH 12/12] fsck: mark strings for translation
Quoted 6 lines · Ævar Arnfjörð Bjarmason <[email protected]> 于2018年10月30日周二 上午1:43写道:
On Mon, Oct 29 2018, Ævar Arnfjörð Bjarmason wrote:
Unlike the rest of our stack where we need to support however many years old tools we can freely rely on bleeding-edge gettext features, since the only person we need to convince to upgrade is Jiang. I.e. he accepts the PRs from translators, (presumably) runs msgfmt --check and then submits the result to Junio.
I used a shell script to check commits before I send a pull request to Junio. This script is in the po-helper branch, see:
https://github.com/git-l10n/git-po/tree/po-helper
It can catch unmatched '\n' errors (missing or unnecessary '\n').
$ git diff
diff --git a/po/zh_CN.po b/po/zh_CN.po
index eabd4d1f8e..6b0d9ebc60 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -5157,7 +5157,7 @@ msgstr "略过补丁 '%s'。"
#
#, perl-format
msgid "Skipping %s with backup suffix '%s'.\n"
-msgstr "略过 %s 含备份后缀 '%s'。\n"
+msgstr "略过 %s 含备份后缀 '%s'。"
#
#, c-format
msgid "Skipping repository %s\n"$ LC_ALL=C po-helper.sh check ------------------------------------------------------------ bg.po : 3958 translated messages. ca.po : 3328 translated messages, 18 fuzzy translations, 30 untranslated messages. de.po : 3958 translated messages. es.po : 3958 translated messages. fr.po : 3957 translated messages, 1 fuzzy translation. is.po : 14 translated messages. it.po : 716 translated messages, 350 untranslated messages. ko.po : 3608 translated messages. pt_PT.po : 3198 translated messages. ru.po : 3366 translated messages, 594 untranslated messages. sv.po : 3958 translated messages. vi.po : 3958 translated messages. zh_CN.po : po/zh_CN.po:19717: 'msgid' and 'msgstr' entries do not both end with '\n' msgfmt: found 1 fatal error 3958 translated messages. ------------------------------------------------------------ Show updates of git.pot...
# Nothing changed. (run 'make pot' first)
------------------------------------------------------------
Check commits...
0 commits checked complete.
------------------------------------------------------------
Note: If you want to check for upstream l10n update, run:
Note:
Note: po-helper.sh check update <remote>
------------------------------------------------------------
So, no warry about it. BTW, I agree with Jonathan.
Quoted 4 lines
Jonathan said:
IMHO the advantage of leaving the \n out in the message is not so much that we don't trust translators but more that where we can make their lives easier, we should.
--
Jiang Xin
Re: [PATCH 12/12] fsck: mark strings for translation
In reply to Ævar Arnfjörð BjarmasonHi,
Quoted 16 lines · Ævar Arnfjörð Bjarmason
Quoted 16 lines · Junio C Hamano
Quoted 15 lines
Quoted 8 lines · SZEDER Gábor
builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 111
Quoted 3 lines · Nguyễn Thái Ngọc Duy
builtin/fsck.c +1
-2-fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); + fprintf_ln(stderr, _("%s in %s %s: %s"),Are the (f)printf() -> (f)printf_ln() changes all over '
builtin/fsck.c' really necessary to mark strings for translation?It is beyond absolute minimum but I saw it argued here that this makes it easier to manage the .po and .pot files if your message strings do not end with LF, a you are much less likely to _add_ unneeded LF to the translated string than _lose_ LF at the end of translated string.
[...]
Quoted 4 lines
As Jonathan pointed out in the follow-up message[1] this sort of thing is checked for in msgfmt, so sure, let's strip the \n, but it's really not something we need to worry about. Likewise with translators turning "%s" into "%d" (or "% s") or whatever.
IMHO the advantage of leaving the \n out in the message is not so much that we don't trust translators but more that where we can make their lives easier, we should.
In other words, I'm glad the patch does that, and Ævar, I agree.
Thanks, both.
Jonathan
Re: [PATCH 12/12] fsck: mark strings for translation
In reply to SZEDER GáborQuoted 7 lines · SZEDER Gábor
The contents of 'out':
broken link from tree
be45bbd3809e0829297cefa576e699c134abacfd(refs/heads/master@{1112912113}:caesar.t)to blob be45bbd3809e0829297cefa576e699c134abacfd (refs/heads/master@{1112912113}:caesar.t)missing blob
be45bbd3809e0829297cefa576e699c134abacfd(refs/heads/master@{1112912113}:caesar.t)On a related (side)note, I think it would be better if this 'grep'
I found the problem. Some function returns static string which works fine when we do two printf()'s, one call of that function per printf(). But when combining two printf() in one, we have a problem. Thanks for catching.
Signature · 1 line
Duy
v2 cover Mark more strings for translation
In reply to Nguyễn Thái Ngọc Duyv2 splits non-trivial changes out to keep i18n patches simpler. A few more word legos in fsck are removed. v2 also fixes a bug in fsck that makes it print object id incorrectly.
Nguyễn Thái Ngọc Duy (16):
git.c: mark more strings for translation
alias.c: mark split_cmdline_strerror() strings for translation archive.c: mark more strings for translation
attr.c: mark more string for translation read-cache.c: turn die("internal error") to BUG() read-cache.c: mark more strings for translation read-cache.c: add missing colon separators
reflog: mark strings for translation
remote.c: turn some error() or die() to BUG() remote.c: mark messages for translation
repack: mark more strings for translation
parse-options: replace opterror() with optname() parse-options.c: turn some die() to BUG() parse-options.c: mark more strings for translation
fsck: reduce word legos to help i18n
fsck: mark strings for translation
alias.c | 4 +- archive.c | 8 +- attr.c | 4 +- builtin/fsck.c | 156 +++++++++++++++++++++---------------- builtin/merge.c | 4 +- builtin/reflog.c | 34 ++++---- builtin/repack.c | 26 +++---- builtin/revert.c | 3 +- git.c | 32 ++++---- parse-options-cb.c | 7 +- parse-options.c | 64 ++++++++------- parse-options.h | 5 +- read-cache.c | 73 ++++++++--------- ref-filter.c | 8 +- remote.c | 49 ++++++------ t/t0040-parse-options.sh | 4 +- t/t1410-reflog.sh | 6 +- t/t1450-fsck.sh | 52 ++++++------- t/t4211-line-log.sh | 2 +- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +- 21 files changed, 292 insertions(+), 259 deletions(-)
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 1/16 git.c: mark more strings for translation
One string is slightly updated to keep consistency with the rest:die() should with lowercase.
--- git.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
git.c +15 -15
@@ -338,27 +338,27 @@ static int handle_alias(int *argcp, const char ***argv)if (ret >=0 )/* normal exit */ exit (ret); -die_errno ("while expanding alias '%s': '%s'" , - alias_command, alias_string +1 ); +die_errno (_ ("while expanding alias '%s': '%s'" ), + alias_command, alias_string +1 ); } count =split_cmdline (alias_string, &new_argv);if (count <0 ) -die ("Bad alias.%s string: %s" , alias_command, +die (_ ("bad alias.%s string: %s" ), alias_command,split_cmdline_strerror (count)); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) -die ("alias '%s' changes environment variables.\n" -"You can use '!git' in the alias to do this" , - alias_command); +die (_ ("alias '%s' changes environment variables.\n" +"You can use '!git' in the alias to do this" ), + alias_command);memmove (new_argv - option_count, new_argv, count *sizeof (char *)); new_argv -= option_count;if (count <1 ) -die ("empty alias for %s" , alias_command); +die (_ ("empty alias for %s" ), alias_command);if (!strcmp (alias_command, new_argv[0 ])) -die ("recursive alias: %s" , alias_command); +die (_ ("recursive alias: %s" ), alias_command); trace_argv_printf(new_argv, "trace: alias expansion: %s =>",
@@ -409,7 +409,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if (!help &&get_super_prefix ()) {if (!(p->option &SUPPORT_SUPER_PREFIX )) -die ("%s doesn't support --super-prefix" , p->cmd); +die (_ ("%s doesn't support --super-prefix" ), p->cmd); }if (!help && p->option &NEED_WORK_TREE )
@@ -433,11 +433,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)/* Check for ENOSPC and EIO errors.. */ if (fflush (stdout)) -die_errno ("write failure on standard output" ); +die_errno (_ ("write failure on standard output" ));if (ferror (stdout)) -die ("unknown write failure on standard output" ); +die (_ ("unknown write failure on standard output" ));if (fclose (stdout)) -die_errno ("close failed on standard output" ); +die_errno (_ ("close failed on standard output" ));return 0 ; }
@@ -648,7 +648,7 @@ static void execv_dashed_external(const char **argv)int status;if (get_super_prefix ()) -die ("%s doesn't support --super-prefix" , argv[0 ]); +die (_ ("%s doesn't support --super-prefix" ), argv[0 ]);if (use_pager ==-1 && !is_builtin (argv[0 ])) use_pager =check_pager_config (argv[0 ]);
@@ -760,7 +760,7 @@ int cmd_main(int argc, const char **argv)if (skip_prefix (cmd,"git-" , &cmd)) { argv[0 ] = cmd;handle_builtin (argc, argv); -die ("cannot handle %s as a builtin" , cmd); +die (_ ("cannot handle %s as a builtin" ), cmd); }/* Look for flags.. */
@@ -773,7 +773,7 @@ int cmd_main(int argc, const char **argv) }else {/* The user didn't specify a command; give them help */ commit_pager_choice (); -printf ("usage: %s\n\n" , git_usage_string); +printf (_ ("usage: %s\n\n" ), git_usage_string);list_common_cmds_help ();printf ("\n%s\n" ,_ (git_more_info_string));exit (1 );
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 01/16] git.c: mark more strings for translation
Quoted 2 lines · Nguyễn Thái Ngọc Duy
One string is slightly updated to keep consistency with the rest:
die()should with lowercase.
s/should/& begin/, I think, in which case I could locally touch up.
Quoted 97 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- git.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)git.c +15
-15@@ -338,27 +338,27 @@ static int handle_alias(int *argcp, const char ***argv)if (ret >=0 )/* normal exit */ exit (ret); -die_errno ("while expanding alias '%s': '%s'" , - alias_command, alias_string +1 ); +die_errno (_ ("while expanding alias '%s': '%s'" ), + alias_command, alias_string +1 ); } count =split_cmdline (alias_string, &new_argv);if (count <0 ) -die ("Bad alias.%s string: %s" , alias_command, +die (_ ("bad alias.%s string: %s" ), alias_command,split_cmdline_strerror (count)); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) -die ("alias '%s' changes environment variables.\n" -"You can use '!git' in the alias to do this" , - alias_command); +die (_ ("alias '%s' changes environment variables.\n" +"You can use '!git' in the alias to do this" ), + alias_command);memmove (new_argv - option_count, new_argv, count *sizeof (char *)); new_argv -= option_count;if (count <1 ) -die ("empty alias for %s" , alias_command); +die (_ ("empty alias for %s" ), alias_command);if (!strcmp (alias_command, new_argv[0 ])) -die ("recursive alias: %s" , alias_command); +die (_ ("recursive alias: %s" ), alias_command); trace_argv_printf(new_argv, "trace: alias expansion: %s =>",@@ -409,7 +409,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if (!help &&get_super_prefix ()) {if (!(p->option &SUPPORT_SUPER_PREFIX )) -die ("%s doesn't support --super-prefix" , p->cmd); +die (_ ("%s doesn't support --super-prefix" ), p->cmd); }if (!help && p->option &NEED_WORK_TREE )@@ -433,11 +433,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)/* Check for ENOSPC and EIO errors.. */ if (fflush (stdout)) -die_errno ("write failure on standard output" ); +die_errno (_ ("write failure on standard output" ));if (ferror (stdout)) -die ("unknown write failure on standard output" ); +die (_ ("unknown write failure on standard output" ));if (fclose (stdout)) -die_errno ("close failed on standard output" ); +die_errno (_ ("close failed on standard output" ));return 0 ; }@@ -648,7 +648,7 @@ static void execv_dashed_external(const char **argv)int status;if (get_super_prefix ()) -die ("%s doesn't support --super-prefix" , argv[0 ]); +die (_ ("%s doesn't support --super-prefix" ), argv[0 ]);if (use_pager ==-1 && !is_builtin (argv[0 ])) use_pager =check_pager_config (argv[0 ]);@@ -760,7 +760,7 @@ int cmd_main(int argc, const char **argv)if (skip_prefix (cmd,"git-" , &cmd)) { argv[0 ] = cmd;handle_builtin (argc, argv); -die ("cannot handle %s as a builtin" , cmd); +die (_ ("cannot handle %s as a builtin" ), cmd); }/* Look for flags.. */ @@ -773,7 +773,7 @@ int cmd_main(int argc, const char **argv) }else {/* The user didn't specify a command; give them help */ commit_pager_choice (); -printf ("usage: %s\n\n" , git_usage_string); +printf (_ ("usage: %s\n\n" ), git_usage_string);list_common_cmds_help ();printf ("\n%s\n" ,_ (git_more_info_string));exit (1 );
PATCH v2 2/16 alias.c: mark split_cmdline_strerror() strings for translation
In reply to Nguyễn Thái Ngọc DuyThis function can be part of translated messages. To make sure we don't have a sentence with mixed languages, mark the strings for translation, but only use translated strings in places we know we will output translated strings.
--- alias.c | 4 ++-- builtin/merge.c | 2 +- git.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
alias.c +2 -2
@@ -47,8 +47,8 @@ void list_aliases(struct string_list *list)#define SPLIT_CMDLINE_BAD_ENDING 1#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2static const char *split_cmdline_errors[] = { -"cmdline ends with \\" , -"unclosed quote" +N_ ("cmdline ends with \\" ), +N_ ("unclosed quote" ) };int split_cmdline (char *cmdline,const char ***argv)
builtin/merge.c +1 -1
@@ -577,7 +577,7 @@ static void parse_branch_merge_options(char *bmo) argc =split_cmdline (bmo, &argv);if (argc <0 )die (_ ("Bad branch.%s.mergeoptions string: %s" ), branch, -split_cmdline_strerror (argc)); +_ (split_cmdline_strerror (argc)));REALLOC_ARRAY (argv, argc +2 );MOVE_ARRAY (argv +1 , argv, argc +1 ); argc++;
git.c +1 -1
@@ -344,7 +344,7 @@ static int handle_alias(int *argcp, const char ***argv) count =split_cmdline (alias_string, &new_argv);if (count <0 )die (_ ("bad alias.%s string: %s" ), alias_command, -split_cmdline_strerror (count)); +_ (split_cmdline_strerror (count))); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) die(_("alias '%s' changes environment variables.\n"
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 3/16 archive.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo messages also print extra information to be more useful
--- archive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
archive.c +4 -4
@@ -385,12 +385,12 @@ static void parse_treeish_arg(const char **argv,int refnamelen = colon - name;if (!dwim_ref (name, refnamelen, &oid, &ref)) -die ("no such ref: %.*s" , refnamelen, name); +die (_ ("no such ref: %.*s" ), refnamelen, name);free (ref); }if (get_oid (name, &oid)) -die ("Not a valid object name" ); +die (_ ("not a valid object name: %s" ), name); commit =lookup_commit_reference_gently (ar_args->repo, &oid,1 );if (commit) {
@@ -403,7 +403,7 @@ static void parse_treeish_arg(const char **argv, tree =parse_tree_indirect (&oid);if (tree ==NULL ) -die ("not a tree object" ); +die (_ ("not a tree object: %s" ),oid_to_hex (&oid));if (prefix) {struct object_id tree_oid;
@@ -413,7 +413,7 @@ static void parse_treeish_arg(const char **argv, err =get_tree_entry (&tree->object.oid, prefix, &tree_oid, &mode);if (err || !S_ISDIR (mode)) -die ("current working directory is untracked" ); +die (_ ("current working directory is untracked" )); tree =parse_tree_indirect (&tree_oid); }
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 03/16] archive.c: mark more strings for translation
Quoted 13 lines · Nguyễn Thái Ngọc Duy
Two messages also print extra information to be more useful
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- archive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)archive.c +0
-0@@ -385,12 +385,12 @@ static void parse_treeish_arg(const char **argv,int refnamelen = colon - name;
archive.c static void parse_treeish_arg(const char **argv, · line 393
Quoted 10 lines
archive.c +2
-2if (!dwim_ref (name, refnamelen, &oid, &ref)) -die ("no such ref: %.*s" , refnamelen, name); +die (_ ("no such ref: %.*s" ), refnamelen, name);free (ref); }if (get_oid (name, &oid)) -die ("Not a valid object name" ); +die (_ ("not a valid object name: %s" ), name);
Much better than the previous one that gave the name upfront.
archive.c static void parse_treeish_arg(const char **argv, · line 406
Quoted 9 lines
archive.c +1
-1commit =lookup_commit_reference_gently (ar_args->repo, &oid,1 );if (commit) {@@ -403,7 +403,7 @@ static void parse_treeish_arg(const char **argv, tree =parse_tree_indirect (&oid);if (tree ==NULL ) -die ("not a tree object" ); +die (_ ("not a tree object: %s" ),oid_to_hex (&oid));
Likewise; as oid_to_hex() would be quite long compared to the rest of the message, this is a vast improvement from the previous round.
Quoted 11 lines
archive.c +1
-1if (prefix) {struct object_id tree_oid;@@ -413,7 +413,7 @@ static void parse_treeish_arg(const char **argv, err =get_tree_entry (&tree->object.oid, prefix, &tree_oid, &mode);if (err || !S_ISDIR (mode)) -die ("current working directory is untracked" ); +die (_ ("current working directory is untracked" )); tree =parse_tree_indirect (&tree_oid); }
PATCH v2 4/16 attr.c: mark more string for translation
In reply to Nguyễn Thái Ngọc Duy--- attr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
attr.c +2 -2
@@ -372,8 +372,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,if (strlen (ATTRIBUTE_MACRO_PREFIX ) < namelen &&starts_with (name,ATTRIBUTE_MACRO_PREFIX )) {if (!macro_ok) { -fprintf (stderr,"%s not allowed: %s:%d\n" , - name, src, lineno); +fprintf_ln (stderr,_ ("%s not allowed: %s:%d" ), + name, src, lineno); goto fail_return; } is_macro =1 ;
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 5/16 read-cache.c: turn die("internal error") to BUG()
In reply to Nguyễn Thái Ngọc Duy--- read-cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
read-cache.c +3 -3
@@ -316,7 +316,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) changed |=DATA_CHANGED ;return changed;default : -die ("internal error: ce_mode is %o" , ce->ce_mode); +BUG ("unsupported ce_mode: %o" , ce->ce_mode); } changed |=match_stat_data (&ce->ce_stat_data, st);
@@ -2356,14 +2356,14 @@ void validate_cache_entries(const struct index_state *istate)for (i =0 ; i < istate->cache_nr; i++) {if (!istate) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); }else if (!istate->ce_mem_pool || !mem_pool_contains (istate->ce_mem_pool, istate->cache[i])) {if (!istate->split_index || !istate->split_index->base || !istate->split_index->base->ce_mem_pool || !mem_pool_contains (istate->split_index->base->ce_mem_pool, istate->cache[i])) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); } } }
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 05/16] read-cache.c: turn die("internal error") to BUG()
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- read-cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Makes sense; thanks.
Quoted 31 lines
read-cache.c +3
-3@@ -316,7 +316,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) changed |=DATA_CHANGED ;return changed;default : -die ("internal error: ce_mode is %o" , ce->ce_mode); +BUG ("unsupported ce_mode: %o" , ce->ce_mode); } changed |=match_stat_data (&ce->ce_stat_data, st);@@ -2356,14 +2356,14 @@ void validate_cache_entries(const struct index_state *istate)for (i =0 ; i < istate->cache_nr; i++) {if (!istate) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); }else if (!istate->ce_mem_pool || !mem_pool_contains (istate->ce_mem_pool, istate->cache[i])) {if (!istate->split_index || !istate->split_index->base || !istate->split_index->base->ce_mem_pool || !mem_pool_contains (istate->split_index->base->ce_mem_pool, istate->cache[i])) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); } } }
PATCH v2 6/16 read-cache.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyThere are a couple other improvements on these strings as well:
- add missing colon (as separator)
- quote paths
- provide more information on error messages
- keep first word in lowercase
--- read-cache.c | 57 +++++++++++++++++++++++++------------------------ t/t1450-fsck.sh | 2 +- 2 files changed, 30 insertions(+), 29 deletions(-)
read-cache.c +29 -28
@@ -672,7 +672,8 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,struct cache_entry *new_entry;if (alias->ce_flags &CE_ADDED ) -die ("Will not add file alias '%s' ('%s' already exists in index)" , ce->name, alias->name); +die (_ ("will not add file alias '%s' ('%s' already exists in index)" ), + ce->name, alias->name);/* Ok, create the new entry using the name of the existing alias */ len =ce_namelen (alias);
@@ -687,7 +688,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce) {struct object_id oid;if (write_object_file ("" ,0 , blob_type, &oid)) -die ("cannot create an empty blob in the object database" ); +die (_ ("cannot create an empty blob in the object database" ));oidcpy (&ce->oid, &oid); }
@@ -708,7 +709,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, newflags |=HASH_RENORMALIZE ;if (!S_ISREG (st_mode) && !S_ISLNK (st_mode) && !S_ISDIR (st_mode)) -return error ("%s: can only add regular files, symbolic links or git-directories" , path); +return error (_ ("%s: can only add regular files, symbolic links or git-directories" ), path); namelen =strlen (path);if (S_ISDIR (st_mode)) {
@@ -763,7 +764,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,if (!intent_only) {if (index_path (istate, &ce->oid, path, st, newflags)) {discard_cache_entry (ce); -return error ("unable to index file %s" , path); +return error (_ ("unable to index file '%s'" ), path); } }else set_object_name_for_intent_to_add_entry (ce);
@@ -782,7 +783,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,discard_cache_entry (ce); else if (add_index_entry(istate, ce, add_option)) {discard_cache_entry (ce); -return error ("unable to add %s to index" , path); +return error (_ ("unable to add '%s' to index" ), path); }if (verbose && !was_same)printf ("add '%s'\n" , path);
@@ -793,7 +794,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags) {struct stat st;if (lstat (path, &st)) -die_errno ("unable to stat '%s'" , path); +die_errno (_ ("unable to stat '%s'" ), path);return add_to_index (istate, path, &st, flags); }
@@ -818,7 +819,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,int len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -844,7 +845,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct oint len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -1297,12 +1298,12 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_eif (!ok_to_add)return -1 ;if (!verify_path (ce->name, ce->ce_mode)) -return error ("Invalid path '%s'" , ce->name); +return error (_ ("invalid path '%s'" ), ce->name);if (!skip_df_check &&check_file_directory_conflict (istate, ce, pos, ok_to_replace)) {if (!ok_to_replace) -return error ("'%s' appears as both a file and as a directory" , +return error (_ ("'%s' appears as both a file and as a directory" ), ce->name); pos =index_name_stage_pos (istate, ce->name,ce_namelen (ce),ce_stage (ce)); pos = -pos-1 ;
@@ -1676,10 +1677,10 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)int hdr_version;if (hdr->hdr_signature !=htonl (CACHE_SIGNATURE )) -return error ("bad signature" ); +return error (_ ("bad signature 0x%08x" ), hdr->hdr_signature); hdr_version =ntohl (hdr->hdr_version);if (hdr_version <INDEX_FORMAT_LB ||INDEX_FORMAT_UB < hdr_version) -return error ("bad index version %d" , hdr_version); +return error (_ ("bad index version %d" ), hdr_version);if (!verify_index_checksum)return 0 ;
@@ -1688,7 +1689,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) the_hash_algo->update_fn (&c, hdr, size - the_hash_algo->rawsz); the_hash_algo->final_fn (hash, &c);if (!hasheq (hash, (unsigned char *)hdr + size - the_hash_algo->rawsz)) -return error ("bad index file sha1 signature" ); +return error (_ ("bad index file sha1 signature" ));return 0 ; }
@@ -1718,9 +1719,9 @@ static int read_index_extension(struct index_state *istate,break ;default :if (*ext <'A' ||'Z' < *ext) -return error ("index uses %.4s extension, which we do not understand" , +return error (_ ("index uses %.4s extension, which we do not understand" ), ext); -fprintf (stderr,"ignoring %.4s extension\n" , ext); +fprintf_ln (stderr,_ ("ignoring %.4s extension" ), ext);break ; }return 0 ;
@@ -1767,7 +1768,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, extended_flags =get_be16 (&ondisk2->flags2) <<16 ;/* We do not yet understand any bit out of CE_EXTENDED_FLAGS */ if (extended_flags & ~CE_EXTENDED_FLAGS ) -die ("Unknown index entry format %08x" , extended_flags); +die (_ ("unknown index entry format 0x%08x" ), extended_flags); flags |= extended_flags; name = ondisk2->name; }
@@ -1840,13 +1841,13 @@ static void check_ce_order(struct index_state *istate)int name_compare =strcmp (ce->name, next_ce->name);if (0 < name_compare) -die ("unordered stage entries in index" ); +die (_ ("unordered stage entries in index" ));if (!name_compare) {if (!ce_stage (ce)) -die ("multiple stage entries for merged file '%s'" , +die (_ ("multiple stage entries for merged file '%s'" ), ce->name);if (ce_stage (ce) >ce_stage (next_ce)) -die ("unordered stage entries for '%s'" , +die (_ ("unordered stage entries for '%s'" ), ce->name); } }
@@ -2149,19 +2150,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)if (fd <0 ) {if (!must_exist && errno ==ENOENT )return 0 ; -die_errno ("%s: index file open failed" , path); +die_errno (_ ("%s: index file open failed" ), path); }if (fstat (fd, &st)) -die_errno ("cannot stat the open index" ); +die_errno (_ ("%s: cannot stat the open index" ), path); mmap_size =xsize_t (st.st_size);if (mmap_size <sizeof (struct cache_header ) + the_hash_algo->rawsz) -die ("index file smaller than expected" ); +die (_ ("%s: index file smaller than expected" ), path); mmap =xmmap (NULL , mmap_size,PROT_READ ,MAP_PRIVATE , fd,0 );if (mmap ==MAP_FAILED ) -die_errno ("unable to map index file" ); +die_errno (_ ("%s: unable to map index file" ), path);close (fd); hdr = (const struct cache_header *)mmap;
@@ -2243,7 +2244,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) unmap:munmap ((void *)mmap, mmap_size); -die ("index file corrupt" ); +die (_ ("index file corrupt" )); }/*
@@ -2255,7 +2256,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)static void freshen_shared_index (const char *shared_index,int warn) {if (!check_and_freshen_file (shared_index,1 ) && warn) -warning ("could not freshen shared index '%s'" , shared_index); +warning (_ ("could not freshen shared index '%s'" ), shared_index); } int read_index_from(struct index_state *istate, const char *path,
@@ -2290,7 +2291,7 @@ int read_index_from(struct index_state *istate, const char *path, base_path =xstrfmt ("%s/sharedindex.%s" , gitdir, base_oid_hex); ret =do_read_index (split_index->base, base_path,1 );if (!oideq (&split_index->base_oid, &split_index->base->oid)) -die ("broken index, expect %s in %s, got %s" , +die (_ ("broken index, expect %s in %s, got %s" ), base_oid_hex, base_path,oid_to_hex (&split_index->base->oid));
@@ -3076,7 +3077,7 @@ static int write_shared_index(struct index_state *istate,return ret; ret =adjust_shared_perm (get_tempfile_path (*temp));if (ret) { -error ("cannot fix permission bits on %s" ,get_tempfile_path (*temp)); +error (_ ("cannot fix permission bits on '%s'" ),get_tempfile_path (*temp));return ret; } ret = rename_tempfile(temp,
@@ -3222,7 +3223,7 @@ int read_index_unmerged(struct index_state *istate) new_ce->ce_namelen = len; new_ce->ce_mode = ce->ce_mode;if (add_index_entry (istate, new_ce,ADD_CACHE_SKIP_DFCHECK )) -return error ("%s: cannot drop to stage #0" , +return error (_ ("%s: cannot drop to stage #0" ), new_ce->name); }return unmerged;
t/t1450-fsck.sh +1 -1
@@ -754,7 +754,7 @@ test_expect_success 'detect corrupt index file in fsck' ' test_when_finished "mv .git/index.backup .git/index" && corrupt_index_checksum && test_must_fail git fsck --cache 2>errors && - grep "bad index file" errors + test_i18ngrep "bad index file" errors ' test_done
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 7/16 read-cache.c: add missing colon separators
In reply to Nguyễn Thái Ngọc Duytypechange_fmt and added_fmt should have a colon before "needs update". Align the statements to make it easier to read and see. Also drop the unnecessary ().
--- read-cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
read-cache.c +5 -5
@@ -1492,11 +1492,11 @@ int refresh_index(struct index_state *istate, unsigned int flags, istate->cache_nr);trace_performance_enter (); - modified_fmt = (in_porcelain ?"M\t%s\n" :"%s: needs update\n" ); - deleted_fmt = (in_porcelain ?"D\t%s\n" :"%s: needs update\n" ); - typechange_fmt = (in_porcelain ?"T\t%s\n" :"%s needs update\n" ); - added_fmt = (in_porcelain ?"A\t%s\n" :"%s needs update\n" ); - unmerged_fmt = (in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ); + modified_fmt = in_porcelain ?"M\t%s\n" :"%s: needs update\n" ; + deleted_fmt = in_porcelain ?"D\t%s\n" :"%s: needs update\n" ; + typechange_fmt = in_porcelain ?"T\t%s\n" :"%s: needs update\n" ; + added_fmt = in_porcelain ?"A\t%s\n" :"%s: needs update\n" ; + unmerged_fmt = in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ;for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce, *new_entry;int cache_errno =0 ;
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 07/16] read-cache.c: add missing colon separators
Quoted 8 lines · Nguyễn Thái Ngọc Duy
typechange_fmtandadded_fmtshould have a colon before "needs update". Align the statements to make it easier to read and see. Also drop the unnecessary ().Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- read-cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Sensible. Thanks.
Quoted 21 lines
read-cache.c +5
-5@@ -1492,11 +1492,11 @@ int refresh_index(struct index_state *istate, unsigned int flags, istate->cache_nr);trace_performance_enter (); - modified_fmt = (in_porcelain ?"M\t%s\n" :"%s: needs update\n" ); - deleted_fmt = (in_porcelain ?"D\t%s\n" :"%s: needs update\n" ); - typechange_fmt = (in_porcelain ?"T\t%s\n" :"%s needs update\n" ); - added_fmt = (in_porcelain ?"A\t%s\n" :"%s needs update\n" ); - unmerged_fmt = (in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ); + modified_fmt = in_porcelain ?"M\t%s\n" :"%s: needs update\n" ; + deleted_fmt = in_porcelain ?"D\t%s\n" :"%s: needs update\n" ; + typechange_fmt = in_porcelain ?"T\t%s\n" :"%s: needs update\n" ; + added_fmt = in_porcelain ?"A\t%s\n" :"%s: needs update\n" ; + unmerged_fmt = in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ;for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce, *new_entry;int cache_errno =0 ;
PATCH v2 8/16 reflog: mark strings for translation
In reply to Nguyễn Thái Ngọc DuyOne string "nothing to delete?" is rephrased to be more helpful.
--- builtin/reflog.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
builtin/reflog.c +19 -15
@@ -13,11 +13,15 @@/* NEEDSWORK: switch to using parse_options */ static const char reflog_expire_usage[] = -"git reflog expire [--expire=<time>] [--expire-unreachable=<time>] [--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] [--verbose] [--all] <refs>..." ; +N_ ("git reflog expire [--expire=<time>] " +"[--expire-unreachable=<time>] " +"[--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] " +"[--verbose] [--all] <refs>..." );static const char reflog_delete_usage[] = -"git reflog delete [--rewrite] [--updateref] [--dry-run | -n] [--verbose] <refs>..." ; +N_ ("git reflog delete [--rewrite] [--updateref] " +"[--dry-run | -n] [--verbose] <refs>..." );static const char reflog_exists_usage[] = -"git reflog exists <ref>" ; +N_ ("git reflog exists <ref>" );static timestamp_t default_reflog_expire;static timestamp_t default_reflog_expire_unreachable;
@@ -556,7 +560,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_expire_usage); +usage (_ (reflog_expire_usage));else break ; }
@@ -569,7 +573,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)if (cb.cmd.stalefix) {repo_init_revisions (the_repository, &cb.cmd.revs, prefix);if (flags &EXPIRE_REFLOGS_VERBOSE ) -printf ("Marking reachable objects..." ); +printf (_ ("Marking reachable objects..." ));mark_reachable_objects (&cb.cmd.revs,0 ,0 ,NULL );if (flags &EXPIRE_REFLOGS_VERBOSE )putchar ('\n' );
@@ -598,7 +602,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)char *ref;struct object_id oid;if (!dwim_log (argv[i],strlen (argv[i]), &oid, &ref)) { - status |=error ("%s points nowhere!" , argv[i]); + status |=error (_ ("%s points nowhere!" ), argv[i]);continue ; }set_reflog_expiry_param (&cb.cmd, explicit_expiry, ref);
@@ -644,13 +648,13 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_delete_usage); +usage (_ (reflog_delete_usage));else break ; }if (argc - i <1 ) -return error ("Nothing to delete?" ); +return error (_ ("no reflog specified to delete" ));for ( ; i < argc; i++) {const char *spec =strstr (argv[i],"@{" );
@@ -659,12 +663,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)int recno;if (!spec) { - status |=error ("Not a reflog: %s" , argv[i]); + status |=error (_ ("not a reflog: %s" ), argv[i]);continue ; }if (!dwim_log (argv[i], spec - argv[i], &oid, &ref)) { - status |=error ("no reflog for '%s'" , argv[i]); + status |=error (_ ("no reflog for '%s'" ), argv[i]);continue ; }
@@ -699,7 +703,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));else break ; }
@@ -707,10 +711,10 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix) start = i;if (argc - start !=1 ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));if (check_refname_format (argv[start],REFNAME_ALLOW_ONELEVEL )) -die ("invalid ref format: %s" , argv[start]); +die (_ ("invalid ref format: %s" ), argv[start]);return !reflog_exists (argv[start]); }
@@ -719,12 +723,12 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)*/ static const char reflog_usage[] = -"git reflog [ show | expire | delete | exists ]" ; +N_ ("git reflog [ show | expire | delete | exists ]" );int cmd_reflog (int argc,const char **argv,const char *prefix) {if (argc >1 && !strcmp (argv[1 ],"-h" )) -usage (reflog_usage); +usage (_ (reflog_usage));/* With no command, we default to showing it. */ if (argc <2 || *argv[1 ] =='-' )
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 08/16] reflog: mark strings for translation
builtin/reflog.c static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) · line 657
Quoted 3 lines · Nguyễn Thái Ngọc Duy
builtin/reflog.c +1
-1if (argc - i <1 ) -return error ("Nothing to delete?" ); +return error (_ ("no reflog specified to delete" ));
Better. Thanks.
PATCH v2 9/16 remote.c: turn some error() or die() to BUG()
In reply to Nguyễn Thái Ngọc DuyThe first error, "internal error", is clearly a BUG(). The second two are meant to catch calls with invalid parameters and should never happen outside the test suite.
--- remote.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
remote.c +3 -3
@@ -620,7 +620,7 @@ static void handle_duplicate(struct ref *ref1, struct ref *ref2)* FETCH_HEAD_IGNORE entries always appear at * the end of the list. */ -die (_ ("Internal error" )); +BUG ("Internal error" ); } }free (ref2->peer_ref);
@@ -707,7 +707,7 @@ static void query_refspecs_multiple(struct refspec *rs,int find_src = !query->src;if (find_src && !query->dst) -error ("query_refspecs_multiple: need either src or dst" ); +BUG ("query_refspecs_multiple: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
@@ -735,7 +735,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)char **result = find_src ? &query->src : &query->dst;if (find_src && !query->dst) -return error ("query_refspecs: need either src or dst" ); +BUG ("query_refspecs: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 09/16] remote.c: turn some error() or die() to BUG()
Quoted 3 lines · Nguyễn Thái Ngọc Duy
The first error, "internal error", is clearly a
BUG(). The second two are meant to catch calls with invalid parameters and should never happen outside the test suite.
Sounds as if it would happen inside test suites.
I guess by "inside the test suite" you mean a test that links broken callers to this code as if it is a piece of library function, but "should never happen, even with invalid or malformed end-user request" would convey the point better, as the normal part of testing that is done by driing "git we just built from the command line should not hit these.
The changes all look sensible. Thanks.
Quoted 36 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- remote.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)remote.c +3
-3@@ -620,7 +620,7 @@ static void handle_duplicate(struct ref *ref1, struct ref *ref2)* FETCH_HEAD_IGNORE entries always appear at * the end of the list. */ -die (_ ("Internal error" )); +BUG ("Internal error" ); } }free (ref2->peer_ref);@@ -707,7 +707,7 @@ static void query_refspecs_multiple(struct refspec *rs,int find_src = !query->src;if (find_src && !query->dst) -error ("query_refspecs_multiple: need either src or dst" ); +BUG ("query_refspecs_multiple: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];@@ -735,7 +735,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)char **result = find_src ? &query->src : &query->dst;if (find_src && !query->dst) -return error ("query_refspecs: need either src or dst" ); +BUG ("query_refspecs: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
PATCH v2 10/16 remote.c: mark messages for translation
In reply to Nguyễn Thái Ngọc DuyThe two strings are slightly modified to be consistent with the rest:die() and error() start with a lowercase.
--- remote.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
remote.c +22 -21
@@ -359,7 +359,7 @@ static int handle_config(const char *key, const char *value, void *cb)return 0 ;/* Handle remote.<name>.* variables */ if (*name =='/' ) { -warning ("Config remote shorthand cannot begin with '/': %s" , +warning (_ ("config remote shorthand cannot begin with '/': %s" ), name);return 0 ; }
@@ -406,7 +406,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->receivepack) remote->receivepack = v;else -error ("more than one receivepack given, using the first" ); +error (_ ("more than one receivepack given, using the first" )); }else if (!strcmp (subkey,"uploadpack" )) {const char *v;if (git_config_string (&v, key, value))
@@ -414,7 +414,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->uploadpack) remote->uploadpack = v;else -error ("more than one uploadpack given, using the first" ); +error (_ ("more than one uploadpack given, using the first" )); }else if (!strcmp (subkey,"tagopt" )) {if (!strcmp (value,"--no-tags" )) remote->fetch_tags =-1 ;
@@ -680,7 +680,7 @@ static int match_name_with_pattern(const char *key, const char *name,size_t namelen;int ret;if (!kstar) -die ("Key '%s' of pattern had no '*'" , key); +die (_ ("key '%s' of pattern had no '*'" ), key); klen = kstar - key; ksuffixlen =strlen (kstar +1 ); namelen =strlen (name);
@@ -690,7 +690,7 @@ static int match_name_with_pattern(const char *key, const char *name,struct strbuf sb =STRBUF_INIT ;const char *vstar =strchr (value,'*' );if (!vstar) -die ("Value '%s' of pattern has no '*'" , value); +die (_ ("value '%s' of pattern has no '*'" ), value);strbuf_add (&sb, value, vstar - value);strbuf_add (&sb, name + klen, namelen - klen - ksuffixlen);strbuf_addstr (&sb, vstar +1 );
@@ -995,12 +995,12 @@ static int match_explicit_lhs(struct ref *src,* way to delete 'other' ref at the remote end. */ if (try_explicit_object_name (rs->src, match) <0 ) -return error ("src refspec %s does not match any." , rs->src); +return error (_ ("src refspec %s does not match any" ), rs->src);if (allocated_match) *allocated_match =1 ;return 0 ;default : -return error ("src refspec %s matches more than one." , rs->src); +return error (_ ("src refspec %s matches more than one" ), rs->src); } }
@@ -1030,7 +1030,7 @@ static int match_explicit(struct ref *src, struct ref *dst,if (!dst_value || ((flag &REF_ISSYMREF ) && !starts_with (dst_value,"refs/heads/" ))) -die ("%s cannot be resolved to branch." , +die (_ ("%s cannot be resolved to branch" ), matched_src->name); }
@@ -1041,30 +1041,30 @@ static int match_explicit(struct ref *src, struct ref *dst,if (starts_with (dst_value,"refs/" )) matched_dst =make_linked_ref (dst_value, dst_tail);else if (is_null_oid (&matched_src->new_oid)) -error ("unable to delete '%s': remote ref does not exist" , +error (_ ("unable to delete '%s': remote ref does not exist" ), dst_value);else if ((dst_guess =guess_ref (dst_value, matched_src))) { matched_dst =make_linked_ref (dst_guess, dst_tail);free (dst_guess); }else -error ("unable to push to unqualified destination: %s\n" -"The destination refspec neither matches an " -"existing ref on the remote nor\n" -"begins with refs/, and we are unable to " -"guess a prefix based on the source ref." , +error (_ ("unable to push to unqualified destination: %s\n" +"The destination refspec neither matches an " +"existing ref on the remote nor\n" +"begins with refs/, and we are unable to " +"guess a prefix based on the source ref." ), dst_value);break ;default : matched_dst =NULL ; -error ("dst refspec %s matches more than one." , +error (_ ("dst refspec %s matches more than one" ), dst_value);break ; }if (!matched_dst)return -1 ;if (matched_dst->peer_ref) -return error ("dst ref %s receives from more than one src." , - matched_dst->name); +return error (_ ("dst ref %s receives from more than one src" ), + matched_dst->name);else { matched_dst->peer_ref = allocated_src ? matched_src :
@@ -1750,7 +1750,7 @@ int get_fetch_map(const struct ref *remote_refs, ref_map =get_remote_ref (remote_refs, name); }if (!missing_ok && !ref_map) -die ("Couldn't find remote ref %s" , name); +die (_ ("couldn't find remote ref %s" ), name);if (ref_map) { ref_map->peer_ref =get_local_ref (refspec->dst);if (ref_map->peer_ref && refspec->force)
@@ -1763,7 +1763,7 @@ int get_fetch_map(const struct ref *remote_refs,if (!starts_with ((*rmp)->peer_ref->name,"refs/" ) ||check_refname_format ((*rmp)->peer_ref->name,0 )) {struct ref *ignore = *rmp; -error ("* Ignoring funny ref '%s' locally" , +error (_ ("* Ignoring funny ref '%s' locally" ), (*rmp)->peer_ref->name); *rmp = (*rmp)->next;free (ignore->peer_ref);
@@ -1858,7 +1858,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,repo_init_revisions (the_repository, &revs,NULL );setup_revisions (argv.argc, argv.argv, &revs,NULL );if (prepare_revision_walk (&revs)) -die ("revision walk setup failed" ); +die (_ ("revision walk setup failed" ));/* ... and count the commits on each side. */ while (1 ) {
@@ -2131,7 +2131,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, ielse if (!colon[1 ])oidclr (&entry->expect);else if (get_oid (colon +1 , &entry->expect)) -return error ("cannot parse expected object name '%s'" , colon +1 ); +return error (_ ("cannot parse expected object name '%s'" ), + colon +1 );return 0 ; }
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 11/16 repack: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo strings are slightly updated to be consistent with the rest: die() starts with lowercase.
--- builtin/repack.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
builtin/repack.c +13 -13
@@ -197,7 +197,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,if (cmd->in ==-1 ) {if (start_command (cmd)) -die ("Could not start pack-objects to repack promisor objects" ); +die (_ ("could not start pack-objects to repack promisor objects" )); }xwrite (cmd->in,oid_to_hex (oid),GIT_SHA1_HEXSZ );
@@ -236,7 +236,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,char *promisor_name;int fd;if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects." ));string_list_append (names, line.buf);/*
@@ -247,13 +247,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args, line.buf); fd =open (promisor_name,O_CREAT |O_EXCL |O_WRONLY ,0600 );if (fd <0 ) -die_errno ("unable to create '%s'" , promisor_name); +die_errno (_ ("unable to create '%s'" ), promisor_name);close (fd);free (promisor_name); }fclose (out);if (finish_command (&cmd)) -die ("Could not finish pack-objects to repack promisor objects" ); +die (_ ("could not finish pack-objects to repack promisor objects" )); }#define ALL_INTO_ONE 1
@@ -408,7 +408,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) out =xfdopen (cmd.out,"r" );while (strbuf_getline_lf (&line, out) !=EOF ) {if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects" ));string_list_append (&names, line.buf); }fclose (out);
@@ -417,7 +417,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)return ret;if (!names.nr && !po_args.quiet) -printf ("Nothing new to pack.\n" ); +printf_ln (_ ("Nothing new to pack." ));/* * Ok we have prepared all new packfiles.
@@ -477,13 +477,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)if (rollback_failure.nr) {int i;fprintf (stderr, -"WARNING: Some packs in use have been renamed by\n" -"WARNING: prefixing old- to their name, in order to\n" -"WARNING: replace them with the new version of the\n" -"WARNING: file. But the operation failed, and the\n" -"WARNING: attempt to rename them back to their\n" -"WARNING: original names also failed.\n" -"WARNING: Please rename them in %s manually:\n" , packdir); +_ ("WARNING: Some packs in use have been renamed by\n" +"WARNING: prefixing old- to their name, in order to\n" +"WARNING: replace them with the new version of the\n" +"WARNING: file. But the operation failed, and the\n" +"WARNING: attempt to rename them back to their\n" +"WARNING: original names also failed.\n" +"WARNING: Please rename them in %s manually:\n" ), packdir);for (i =0 ; i < rollback_failure.nr; i++) fprintf(stderr, "WARNING: old-%s -> %s\n", rollback_failure.items[i].string,
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 12/16 parse-options: replace opterror() with optname()
In reply to Nguyễn Thái Ngọc DuyThere are a few issues with opterror()
- it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence.
- It's a wrapper around error() and needs some hack to let the compiler know it always returns -1.
- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
Kill it and produce the option name with optname(). The user will use error() directly. This solves the second and third problems.
It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling optname() when 'flags' is known in advance.
Mark of these strings for translation as well while at there.
--- builtin/merge.c | 2 +- builtin/revert.c | 3 ++- parse-options-cb.c | 7 ++++--- parse-options.c | 46 +++++++++++++++++++++++++-------------------- parse-options.h | 5 +---- ref-filter.c | 8 +++++--- t/t4211-line-log.sh | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-)
builtin/merge.c +1 -1
@@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx, ctx->argc--; arg = *++ctx->argv; }else -return opterror (opt,"requires a value" ,0 ); +return error (_ ("option `%s' requires a value" ), opt->long_name);if (buf->len)strbuf_addch (buf,'\n' );
builtin/revert.c +2 -1
@@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt, replay->mainline =strtol (arg, &end,10 );if (*end || replay->mainline <=0 ) -return opterror (opt,"expects a number greater than zero" ,0 ); +return error (_ ("option `%s' expects a number greater than zero" ), + opt->long_name);return 0 ; }
parse-options-cb.c +4 -3
@@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) }else { v =strtol (arg, (char **)&arg,10 );if (*arg) -return opterror (opt,"expects a numerical value" ,0 ); +return error (_ ("option `%s' expects a numerical value" ), + opt->long_name);if (v && v <MINIMUM_ABBREV ) v =MINIMUM_ABBREV ;else if (v >40 )
@@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg, arg = unset ?"never" : (const char *)opt->defval; value =git_config_colorbool (NULL , arg);if (value <0 ) -return opterror (opt, -"expects \"always\", \"auto\", or \"never\"" ,0 ); +return error (_ ("option `%s' expects \"always\", \"auto\", or \"never\"" ), + opt->long_name); *(int *)opt->value = value;return 0 ; }
parse-options.c +26 -20
99 lines not on this page · raw message
parse-options.h +1 -4
@@ -189,10 +189,7 @@ extern NORETURN void usage_msg_opt(const char *msg, const struct option *options);extern int optbug (const struct option *opt,const char *reason); -extern int opterror (const struct option *opt,const char *reason,int flags); -#if defined(__GNUC__) -#define opterror (o,r,f) (opterror((o),(r),(f)), const_error()) -#endif +const char *optname (const struct option *opt,int flags);/*----- incremental advanced APIs -----*/
ref-filter.c +5 -3
@@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)if (rf->merge) {if (no_merged) { -return opterror (opt,"is incompatible with --merged" ,0 ); +return error (_ ("option `%s' is incompatible with --merged" ), + opt->long_name); }else { -return opterror (opt,"is incompatible with --no-merged" ,0 ); +return error (_ ("option `%s' is incompatible with --no-merged" ), + opt->long_name); } }
@@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) rf->merge_commit =lookup_commit_reference_gently (the_repository, &oid,0 );if (!rf->merge_commit) -return opterror (opt,"must point to a commit" ,0 ); +return error (_ ("option `%s' must point to a commit" ), opt->long_name);return 0 ; }
t/t4211-line-log.sh +1 -1
@@ -25,7 +25,7 @@ canned_test_failure () { test_bad_opts () { test_expect_success "invalid args: $1" " test_must_fail git log $1 2>errors && - grep '$2' errors + test_i18ngrep '$2' errors " }
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 12/16] parse-options: replace opterror() with optname()
Quoted 6 lines · Nguyễn Thái Ngọc Duy
There are a few issues with
opterror()- it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence.
Quoted 8 lines
- It's a wrapper around
error()and needs some hack to let the compiler know it always returns -1.- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
Kill it and produce the option name with
optname(). The user will useerror()directly. This solves the second and third problems.
The proposed log message is not very friendly to reviewers, as there is no hint what optname() does nor where it came from; it turns out that this patch introduces it.
Introduce optname() that does the early half of original opterror() to come up with the name of the option reported back to the user, and use it to kill opterror(). The callers of opterror() now directly call error() using the string returned by opterror() instead.
or something like that perhaps.
Theoretically not very friendly to topics in flight, but I do not expect there would be any right now that wants to add new callers of opterror().
I do agree with the reasoning behind this change. Thanks for working on it.
Quoted 239 lines
It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling
optname()when 'flags' is known in advance.Mark of these strings for translation as well while at there.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/merge.c | 2 +- builtin/revert.c | 3 ++- parse-options-cb.c | 7 ++++--- parse-options.c | 46 +++++++++++++++++++++++++-------------------- parse-options.h | 5 +---- ref-filter.c | 8 +++++--- t/t4211-line-log.sh | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-)builtin/merge.c +1
-1@@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx, ctx->argc--; arg = *++ctx->argv; }else -return opterror (opt,"requires a value" ,0 ); +return error (_ ("option `%s' requires a value" ), opt->long_name);if (buf->len)strbuf_addch (buf,'\n' );builtin/revert.c +2
-1@@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt, replay->mainline =strtol (arg, &end,10 );if (*end || replay->mainline <=0 ) -return opterror (opt,"expects a number greater than zero" ,0 ); +return error (_ ("option `%s' expects a number greater than zero" ), + opt->long_name);return 0 ; }parse-options-cb.c +4
-3@@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) }else { v =strtol (arg, (char **)&arg,10 );if (*arg) -return opterror (opt,"expects a numerical value" ,0 ); +return error (_ ("option `%s' expects a numerical value" ), + opt->long_name);if (v && v <MINIMUM_ABBREV ) v =MINIMUM_ABBREV ;else if (v >40 )@@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg, arg = unset ?"never" : (const char *)opt->defval; value =git_config_colorbool (NULL , arg);if (value <0 ) -return opterror (opt, -"expects \"always\", \"auto\", or \"never\"" ,0 ); +return error (_ ("option `%s' expects \"always\", \"auto\", or \"never\"" ), + opt->long_name); *(int *)opt->value = value;return 0 ; }parse-options.c +26
-20@@ -32,7 +32,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, p->argc--; *arg = *++p->argv; }else -return opterror (opt,"requires a value" , flags); +return error (_ ("%s requires a value" ),optname (opt, flags));return 0 ; }@@ -49,7 +49,6 @@ static int opt_command_mode_error(const struct option *opt, int flags) {const struct option *that; -struct strbuf message =STRBUF_INIT ;struct strbuf that_name =STRBUF_INIT ;/* @@ -67,13 +66,13 @@ static int opt_command_mode_error(const struct option *opt,strbuf_addf (&that_name,"--%s" , that->long_name); else strbuf_addf(&that_name, "-%c", that->short_name); -strbuf_addf (&message,": incompatible with %s" , that_name.buf); +error (_ ("%s is incompatible with %s" ), +optname (opt, flags), that_name.buf);strbuf_release (&that_name); -opterror (opt, message.buf, flags); -strbuf_release (&message);return -1 ; } -return opterror (opt,": incompatible with something else" , flags); +return error (_ ("%s : incompatible with something else" ), +optname (opt, flags)); } static int get_value(struct parse_opt_ctx_t *p,@@ -86,11 +85,11 @@ static int get_value(struct parse_opt_ctx_t *p,int err;if (unset && p->opt) -return opterror (opt,"takes no value" , flags); +return error (_ ("%s takes no value" ),optname (opt, flags));if (unset && (opt->flags &PARSE_OPT_NONEG )) -return opterror (opt,"isn't available" , flags); +return error (_ ("%s isn't available" ),optname (opt, flags));if (!(flags &OPT_SHORT ) && p->opt && (opt->flags &PARSE_OPT_NOARG )) -return opterror (opt,"takes no value" , flags); +return error (_ ("%s takes no value" ),optname (opt, flags));switch (opt->type) {case OPTION_LOWLEVEL_CALLBACK :@@ -176,7 +175,8 @@ static int get_value(struct parse_opt_ctx_t *p,return -1 ; *(int *)opt->value =strtol (arg, (char **)&s,10 );if (*s) -return opterror (opt,"expects a numerical value" , flags); +return error (_ ("%s expects a numerical value" ), +optname (opt, flags));return 0 ;case OPTION_MAGNITUDE :@@ -191,9 +191,9 @@ static int get_value(struct parse_opt_ctx_t *p,if (get_arg (p, opt, flags, &arg))return -1 ;if (!git_parse_ulong (arg, opt->value)) -return opterror (opt, -"expects a non-negative integer value with an optional k/m/g suffix" , - flags); +return error (_ ("%s expects a non-negative integer value" +" with an optional k/m/g suffix" ), +optname (opt, flags));return 0 ;default :@@ -257,7 +257,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,if (!rest)continue ;if (*rest =='=' ) -return opterror (options,"takes no value" , flags); +return error (_ ("%s takes no value" ), +optname (options, flags));if (*rest)continue ; p->out[p->cpidx++] = arg -2 ;@@ -773,12 +774,17 @@ void NORETURN usage_msg_opt(const char *msg,usage_with_options (usagestr, options); } -#undef opterror -int opterror (const struct option *opt,const char *reason,int flags) +const char *optname (const struct option *opt,int flags) { +static struct strbuf sb =STRBUF_INIT ; + +strbuf_reset (&sb);if (flags &OPT_SHORT ) -return error ("switch `%c' %s" , opt->short_name, reason); -if (flags &OPT_UNSET ) -return error ("option `no-%s' %s" , opt->long_name, reason); -return error ("option `%s' %s" , opt->long_name, reason); +strbuf_addf (&sb,"switch `%c'" , opt->short_name); +else if (flags &OPT_UNSET ) +strbuf_addf (&sb,"option `no-%s'" , opt->long_name); +else +strbuf_addf (&sb,"option `%s'" , opt->long_name); + +return sb.buf; }parse-options.h +1
-4@@ -189,10 +189,7 @@ extern NORETURN void usage_msg_opt(const char *msg, const struct option *options);extern int optbug (const struct option *opt,const char *reason); -extern int opterror (const struct option *opt,const char *reason,int flags); -#if defined(__GNUC__) -#define opterror (o,r,f) (opterror((o),(r),(f)), const_error()) -#endif +const char *optname (const struct option *opt,int flags);/*----- incremental advanced APIs -----*/ ref-filter.c +5
-3@@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)if (rf->merge) {if (no_merged) { -return opterror (opt,"is incompatible with --merged" ,0 ); +return error (_ ("option `%s' is incompatible with --merged" ), + opt->long_name); }else { -return opterror (opt,"is incompatible with --no-merged" ,0 ); +return error (_ ("option `%s' is incompatible with --no-merged" ), + opt->long_name); } }@@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) rf->merge_commit =lookup_commit_reference_gently (the_repository, &oid,0 );if (!rf->merge_commit) -return opterror (opt,"must point to a commit" ,0 ); +return error (_ ("option `%s' must point to a commit" ), opt->long_name);return 0 ; }t/t4211-line-log.sh +1
-1@@ -25,7 +25,7 @@ canned_test_failure () { test_bad_opts () { test_expect_success "invalid args: $1" " test_must_fail git log $1 2>errors && - grep '$2' errors + test_i18ngrep '$2' errors " }
Re: [PATCH v2 12/16] parse-options: replace opterror() with optname()
Quoted 27 lines · Junio C Hamano
Quoted 6 lines · Nguyễn Thái Ngọc Duy
There are a few issues with
opterror()- it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence.
Quoted 8 lines
- It's a wrapper around
error()and needs some hack to let the compiler know it always returns -1.- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
Kill it and produce the option name with
optname(). The user will useerror()directly. This solves the second and third problems.The proposed log message is not very friendly to reviewers, as there is no hint what
optname()does nor where it came from; it turns out that this patch introduces it.Introduce
optname()that does the early half of originalopterror()to come up with the name of the option reported back to the user, and use it to killopterror(). The callers ofopterror()now directly callerror()using the string returned byopterror()instead.
Quoted 9 lines
or something like that perhaps.
Theoretically not very friendly to topics in flight, but I do not expect there would be any right now that wants to add new callers of
opterror().I do agree with the reasoning behind this change. Thanks for working on it.
Also, this patch does not replace opterror() calls outside of the 'parse-options.c' file with optname(). This tickles my static-check.pl script, since optname() is an external function which is only called from 'parse-options.c'.
So, at present, optname() could be marked as a local 'static' symbol. However, I could also imagine it being used by new callers outside of 'parse-options.c' in the future. (maybe) Your call. ;-)
ATB,
Ramsay Jones
Re: [PATCH v2 12/16] parse-options: replace opterror() with optname()
Quoted 8 lines · Ramsay Jones
Also, this patch does not replace
opterror()calls outside of the 'parse-options.c' file withoptname(). This tickles my static-check.pl script, sinceoptname()is an external function which is only called from 'parse-options.c'.So, at present,
optname()could be marked as a local 'static' symbol. However, I could also imagine it being used by new callers outside of 'parse-options.c' in the future. (maybe) Your call. ;-)
One potential caller is the BUG() cases I added in:
https://public-inbox.org/git/[email protected]/
I actually thought about factoring out an optname() there, but saw that it involved memory ownership issues and punted (since those messages are just BUG()s anyway, and unlikely to be triggered). But if we have it, we could use it.
-Peff
Re: [PATCH v2 12/16] parse-options: replace opterror() with optname()
In reply to Ramsay JonesQuoted 8 lines · Ramsay Jones
Also, this patch does not replace
opterror()calls outside of the 'parse-options.c' file withoptname(). This tickles my static-check.pl script, sinceoptname()is an external function which is only called from 'parse-options.c'.So, at present,
optname()could be marked as a local 'static' symbol. However, I could also imagine it being used by new callers outside of 'parse-options.c' in the future. (maybe) Your call. ;-)
I was making it static, but the compiler complained about undefined function and I would need to either move optname() up in parse-options.c or add a forward declaration (but I was going to _remove_ the declaration!)
Since it could be potentially used by Jeff's series (and I think it does have potential in parse-options-cb.c), I'll just leave it exported and caress your static-check.pl script (how did it not catch optbug() not being used outside parse-options.c either)?
Signature · 1 line
Duy
Re: [PATCH v2 12/16] parse-options: replace opterror() with optname()
Quoted 10 lines · Duy Nguyen
Quoted 8 lines · Ramsay Jones
Also, this patch does not replace
opterror()calls outside of the 'parse-options.c' file withoptname(). This tickles my static-check.pl script, sinceoptname()is an external function which is only called from 'parse-options.c'.So, at present,
optname()could be marked as a local 'static' symbol. However, I could also imagine it being used by new callers outside of 'parse-options.c' in the future. (maybe) Your call. ;-)
Quoted 8 lines
I was making it static, but the compiler complained about undefined function and I would need to either move
optname()up inparse-options.cor add a forward declaration (but I was going to _remove_ the declaration!)Since it could be potentially used by Jeff's series (and I think it does have potential in
parse-options-cb.c), I'll just leave it exported and caress your static-check.pl script
Fair enough.
Quoted 2 lines
(how did it not catch
optbug()not being used outsideparse-options.ceither)?
It did, some time ago (presumably, I haven't checked). Which is to
say: the output from the master branch notes it:
$ grep parse-options sc
parse-options.o - optbug
$ ... but if it gets to the master branch I tend to forget it. (I have been meaning to go through the 'sc' file and clean out some of the 'easy' cases).
So, if optname() doesn't get any new callers, I will watch it go from 'pu' to 'next' and then to 'master' and ... ;-)
ATB,
Ramsay Jones
PATCH v2 13/16 parse-options.c: turn some die() to BUG()
In reply to Nguyễn Thái Ngọc DuyThese two strings are clearly not for the user to see. Reduce the violence in one string while at there.
--- parse-options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parse-options.c +2 -2
@@ -197,7 +197,7 @@ static int get_value(struct parse_opt_ctx_t *p,return 0 ;default : -die ("should not happen, someone must be hit on the forehead" ); +BUG ("opt->type %d should not happen" , opt->type); } }
@@ -424,7 +424,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->flags = flags;if ((flags &PARSE_OPT_KEEP_UNKNOWN ) && (flags &PARSE_OPT_STOP_AT_NON_OPTION )) -die ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" ); +BUG ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" );parse_options_check (options); }
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 13/16] parse-options.c: turn some die() to BUG()
parse-options.c static int get_value(struct parse_opt_ctx_t *p, · line 202
Quoted 12 lines · Nguyễn Thái Ngọc Duy
parse-options.c +1
-1@@ -197,7 +197,7 @@ static int get_value(struct parse_opt_ctx_t *p,return 0 ;default : -die ("should not happen, someone must be hit on the forehead" ); +BUG ("opt->type %d should not happen" , opt->type); } }
OK, this should not happen.
parse-options.c void parse_options_start(struct parse_opt_ctx_t *ctx, · line 427
Quoted 6 lines
parse-options.c +1
-1@@ -424,7 +424,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->flags = flags;if ((flags &PARSE_OPT_KEEP_UNKNOWN ) && (flags &PARSE_OPT_STOP_AT_NON_OPTION )) -die ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" ); +BUG ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" );
The correctness of this conversion was not immediately obvious, as "git rev-parse --parse-options" could allow end-users to specify flags, and when these two flags came together from that codepath, it is an end-user error that should be diagnosed with die(), not BUG().
It turns out that stop-at-non-option can be passed, but keep-unknown is not (yet) available to the codepath, so this conversion to BUG() is correct---an end user futzing with Git correctly compiled from a bug-free source should not be able to trigger this.
PATCH v2 14/16 parse-options.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyOne error is updated to start with lowercase to be consistent with the rest.
--- parse-options.c | 14 +++++++------- t/t0040-parse-options.sh | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-)
parse-options.c +7 -7
@@ -319,8 +319,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, }if (ambiguous_option) { - error("Ambiguous option: %s " - "(could be --%s%s or --%s%s)", + error(_("ambiguous option: %s " + "(could be --%s%s or --%s%s)"), arg, (ambiguous_flags & OPT_UNSET) ? "no-" : "", ambiguous_option->long_name,
@@ -353,7 +353,7 @@ static void check_typos(const char *arg, const struct option *options)return ;if (starts_with (arg,"no-" )) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); }
@@ -361,7 +361,7 @@ static void check_typos(const char *arg, const struct option *options)if (!options->long_name)continue ;if (starts_with (options->long_name, arg)) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); } }
@@ -644,11 +644,11 @@ int parse_options(int argc, const char **argv, const char *prefix,break ;default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) { -error ("unknown option `%s'" , ctx.argv[0 ] +2 ); +error (_ ("unknown option `%s'" ), ctx.argv[0 ] +2 ); }else if (isascii (*ctx.opt)) { -error ("unknown switch `%c'" , *ctx.opt); +error (_ ("unknown switch `%c'" ), *ctx.opt); }else { -error ("unknown non-ascii option in string: `%s'" , +error (_ ("unknown non-ascii option in string: `%s'" ), ctx.argv[0 ]); }usage_with_options (usagestr, options);
t/t0040-parse-options.sh +2 -2
@@ -228,7 +228,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -boolean >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' cat >typo.err <<\EOF
@@ -238,7 +238,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -ambiguous >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' test_expect_success 'keep some options as arguments' '
Signature · 1 line
2.19.1.1005.gac84295441
PATCH v2 15/16 fsck: reduce word legos to help i18n
In reply to Nguyễn Thái Ngọc DuyThese messages will be marked for translation later. Reduce word legos and give translators almost full phrases. describe_object() is updated so that it can be called from printf() twice.
While at there, remove \n from the strings to reduce a bit of work from translators.
--- builtin/fsck.c | 62 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-)
builtin/fsck.c +37 -25
@@ -52,16 +52,24 @@ static int name_objects;static const char *describe_object (struct object *obj) { -static struct strbuf buf =STRBUF_INIT ; -char *name = name_objects ? -lookup_decoration (fsck_walk_options.object_names, obj) :NULL ; +static struct strbuf bufs[4 ] = { +STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT + }; +static int b =0 ; +struct strbuf *buf; +char *name =NULL ; -strbuf_reset (&buf); -strbuf_addstr (&buf,oid_to_hex (&obj->oid)); +if (name_objects) + name =lookup_decoration (fsck_walk_options.object_names, obj); + + buf = bufs + b; + b = (b +1 ) %ARRAY_SIZE (bufs); +strbuf_reset (buf); +strbuf_addstr (buf,oid_to_hex (&obj->oid));if (name) -strbuf_addf (&buf," (%s)" , name); +strbuf_addf (buf," (%s)" , name); -return buf.buf; +return buf->buf; }static const char *printable_type (struct object *obj)
@@ -105,25 +113,26 @@ static int fsck_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } -static void objreport (struct object *obj,const char *msg_type, -const char *err) -{ -fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); -} -static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err); +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), err);return -1 ; }static int fsck_error_func (struct fsck_options *o,struct object *obj,int type,const char *message) { -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message); -return (type ==FSCK_WARN ) ?0 :1 ; +if (type ==FSCK_WARN ) { +fprintf_ln (stderr,"warning in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 0 ; + } + +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 1 ; }static struct object_array pending;
@@ -165,10 +174,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_optif (!(obj->flags &HAS_OBJ )) {if (parent && !has_object_file (&obj->oid)) { -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf (" to %7s %s\n" , -printable_type (obj),describe_object (obj)); +printf_ln ("broken link from %7s %s\n" +" to %7s %s" , +printable_type (parent), +describe_object (parent), +printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ; }return 1 ;
@@ -371,10 +382,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)struct tag *tag = (struct tag *) obj;if (show_tags && tag->tagged) { -printf ("tagged %s %s" ,printable_type (tag->tagged), -describe_object (tag->tagged)); -printf (" (%s) in %s\n" , tag->tag, -describe_object (&tag->object)); +printf_ln ("tagged %s %s (%s) in %s" , +printable_type (tag->tagged), +describe_object (tag->tagged), + tag->tag, +describe_object (&tag->object)); } }
Signature · 1 line
2.19.1.1005.gac84295441
Re: [PATCH v2 15/16] fsck: reduce word legos to help i18n
builtin/fsck.c static int name_objects; · line 57
Quoted 8 lines · Nguyễn Thái Ngọc Duy
static const char *describe_object(struct object *obj) {
builtin/fsck.c +3
-3-static struct strbuf buf =STRBUF_INIT ; -char *name = name_objects ? -lookup_decoration (fsck_walk_options.object_names, obj) :NULL ; +static struct strbuf bufs[4 ] = { +STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT + };
If you need to repeat _INIT anyway, perhaps you want to actively omit the 4 from above, no? If you typed 6 by mistake instead, you'd be in trouble when using the last two elements.
builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 122
Quoted 8 lines
static int
objerror(struct object *obj, const char *err){builtin/fsck.c +2
-1errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err); +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), err);return -1 ; }
Makes sense.
Quoted 4 lines
static int fsck_error_func(struct
fsck_options*o,builtin/fsck.c +0
-1struct object *obj, int type, const char *message) { - objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 135
Quoted 10 lines
builtin/fsck.c +9
-1-return (type ==FSCK_WARN ) ?0 :1 ; +if (type ==FSCK_WARN ) { +fprintf_ln (stderr,"warning in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 0 ; + } + +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 1 ;
Make it look more symmetrical like the original, perhaps by
if (type == FSCK_WARN) {
...
return 0;
} else { /* FSCK_ERROR */
...
return 1;
}Actually, wouldn't it be clearer to see what is going on, if we did it like this instead?
const char *fmt = (type == FSCK_WARN)
? N_("warning in %s %s: %s")
: N_("error in %s %s: %s");
fprintf_ln(stderr, _(fmt),
printable_type(obj), describe_object(obj), message);
return (type == FSCK_WARN) ? 0 : 1;It would show that in either case we show these three things in the message. I dunno.
Re: [PATCH v2 15/16] fsck: reduce word legos to help i18n
Quoted 35 lines · Junio C Hamano
Quoted 4 lines
static int fsck_error_func(struct
fsck_options*o,
struct object *obj, int type, const char *message)
{builtin/fsck.c +0
-1-objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message);builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 135
Quoted 10 lines
builtin/fsck.c +9
-1-return (type ==FSCK_WARN ) ?0 :1 ; +if (type ==FSCK_WARN ) { +fprintf_ln (stderr,"warning in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 0 ; + } + +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 1 ;Make it look more symmetrical like the original, perhaps by
if (type == FSCK_WARN) { ... return 0; } else { /* FSCK_ERROR */ ... return 1; }Actually, wouldn't it be clearer to see what is going on, if we did it like this instead?
const char *fmt = (type == FSCK_WARN) ? N_("warning in %s %s: %s") : N_("error in %s %s: %s"); fprintf_ln(stderr, _(fmt), printable_type(obj), describe_object(obj), message); return (type == FSCK_WARN) ? 0 : 1;
Quoted 2 lines
It would show that in either case we show these three things in the message. I dunno.
Specifying "type == FSCK_WARN" twice triggers me (what if we add a third fsck type?) so I just turn this to a switch/case block instead (and get to know the third fsck type FSCK_IGNORE).
Signature · 1 line
Duy
PATCH v2 16/16 fsck: mark strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo die() are updated to start with lowercase to be consistent with the rest.
--- builtin/fsck.c | 106 ++++++++++++++++++++----------------- t/t1410-reflog.sh | 6 +-- t/t1450-fsck.sh | 50 ++++++++--------- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +-- 5 files changed, 90 insertions(+), 82 deletions(-)
builtin/fsck.c +57 -49
@@ -85,7 +85,7 @@ static const char *printable_type(struct object *obj) ret =type_name (obj->type);if (!ret) - ret ="unknown" ; + ret =_ ("unknown" );return ret; }
@@ -116,7 +116,8 @@ static int fsck_config(const char *var, const char *value, void *cb)static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ; -fprintf_ln (stderr,"error in %s %s: %s" , +/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ +fprintf_ln (stderr,_ ("error in %s %s: %s" ),printable_type (obj),describe_object (obj), err);return -1 ; }
@@ -125,12 +126,14 @@ static int fsck_error_func(struct fsck_options *o, struct object *obj, int type, const char *message) { if (type == FSCK_WARN) { - fprintf_ln(stderr, "warning in %s %s: %s", + /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */ + fprintf_ln(stderr, _("warning in %s %s: %s"), printable_type(obj), describe_object(obj), message);return 0 ; } -fprintf_ln (stderr,"error in %s %s: %s" , +/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ +fprintf_ln (stderr,_ ("error in %s %s: %s" ),printable_type (obj),describe_object (obj), message);return 1 ; }
@@ -148,17 +151,18 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt*/ if (!obj) {/* ... these references to parent->fld are safe here */ -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf ("broken link from %7s %s\n" , - (type ==OBJ_ANY ?"unknown" :type_name (type)),"unknown" ); +printf_ln (_ ("broken link from %7s %s" ), +printable_type (parent),describe_object (parent)); +printf_ln (_ ("broken link from %7s %s" ), + (type ==OBJ_ANY ?_ ("unknown" ) :type_name (type)), +_ ("unknown" )); errors_found |=ERROR_REACHABLE ;return 1 ; }if (type !=OBJ_ANY && obj->type != type)/* ... and the reference to parent is safe here */ -objerror (parent,"wrong object type in link" ); +objerror (parent,_ ("wrong object type in link" ));if (obj->flags &REACHABLE )return 0 ;
@@ -174,8 +178,8 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_optif (!(obj->flags &HAS_OBJ )) {if (parent && !has_object_file (&obj->oid)) { - printf_ln("broken link from %7s %s\n" - " to %7s %s", + printf_ln(_("broken link from %7s %s\n" + " to %7s %s"), printable_type(parent), describe_object(parent), printable_type(obj),
@@ -243,8 +247,8 @@ static void check_reachable_object(struct object *obj)return ;if (has_object_pack (&obj->oid))return ;/* it is in pack - forget about it */ -printf ("missing %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("missing %s %s" ),printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ;return ; }
@@ -269,8 +273,8 @@ static void check_unreachable_object(struct object *obj)* since this is something that is prunable. */ if (show_unreachable) { -printf ("unreachable %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("unreachable %s %s" ),printable_type (obj), +describe_object (obj));return ; }
@@ -288,8 +292,8 @@ static void check_unreachable_object(struct object *obj)*/ if (!(obj->flags &USED )) {if (show_dangling) -printf ("dangling %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("dangling %s %s" ),printable_type (obj), +describe_object (obj));if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -297,18 +301,18 @@ static void check_unreachable_object(struct object *obj)FILE *f;if (safe_create_leading_directories_const (filename)) { -error ("Could not create lost-found" ); +error (_ ("could not create lost-found" ));free (filename);return ; } f =xfopen (filename,"w" );if (obj->type ==OBJ_BLOB ) {if (stream_blob_to_fd (fileno (f), &obj->oid,NULL ,1 )) -die_errno ("Could not write '%s'" , filename); +die_errno (_ ("could not write '%s'" ), filename); }else fprintf (f,"%s\n" ,describe_object (obj));if (fclose (f)) -die_errno ("Could not finish '%s'" , +die_errno (_ ("could not finish '%s'" ), filename);free (filename); }
@@ -325,7 +329,7 @@ static void check_unreachable_object(struct object *obj)static void check_object (struct object *obj) {if (verbose) -fprintf (stderr,"Checking %s\n" ,describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s" ),describe_object (obj));if (obj->flags &REACHABLE )check_reachable_object (obj);
@@ -343,7 +347,7 @@ static void check_connectivity(void)/* Look up all the requirements, warn about missing objects.. */ max =get_max_object_index ();if (verbose) -fprintf (stderr,"Checking connectivity (%d objects)\n" , max); +fprintf_ln (stderr,_ ("Checking connectivity (%d objects)" ), max);for (i =0 ; i < max; i++) {struct object *obj =get_indexed_object (i);
@@ -362,11 +366,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) obj->flags |=SEEN ;if (verbose) -fprintf (stderr,"Checking %s %s\n" , -printable_type (obj),describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s %s" ), +printable_type (obj),describe_object (obj));if (fsck_walk (obj,NULL , &fsck_obj_options)) -objerror (obj,"broken links" ); +objerror (obj,_ ("broken links" )); err =fsck_object (obj, buffer, size, &fsck_obj_options);if (err) goto out;
@@ -375,14 +379,15 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)struct commit *commit = (struct commit *) obj;if (!commit->parents && show_root) -printf ("root %s\n" ,describe_object (&commit->object)); +printf_ln (_ ("root %s" ), +describe_object (&commit->object)); }if (obj->type ==OBJ_TAG ) {struct tag *tag = (struct tag *) obj;if (show_tags && tag->tagged) { - printf_ln("tagged %s %s (%s) in %s", + printf_ln(_("tagged %s %s (%s) in %s"), printable_type(tag->tagged), describe_object(tag->tagged), tag->tag,
@@ -410,7 +415,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, eaten);if (!obj) { errors_found |=ERROR_OBJECT ; -return error ("%s: object corrupt or missing" ,oid_to_hex (oid)); +return error (_ ("%s: object corrupt or missing" ), +oid_to_hex (oid)); } obj->flags &= ~(REACHABLE |SEEN ); obj->flags |=HAS_OBJ ;
@@ -434,7 +440,8 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, obj->flags |=USED ;mark_object_reachable (obj); }else if (!is_promisor_object (oid)) { -error ("%s: invalid reflog entry %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid reflog entry %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ; } }
@@ -447,8 +454,8 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noidconst char *refname = cb_data;if (verbose) -fprintf (stderr,"Checking reflog %s->%s\n" , -oid_to_hex (ooid),oid_to_hex (noid)); +fprintf_ln (stderr,_ ("Checking reflog %s->%s" ), +oid_to_hex (ooid),oid_to_hex (noid));fsck_handle_reflog_oid (refname, ooid,0 );fsck_handle_reflog_oid (refname, noid, timestamp);
@@ -477,13 +484,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, default_refs++;return 0 ; } -error ("%s: invalid sha1 pointer %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid sha1 pointer %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ;/* We'll continue with the rest despite the error.. */ return 0 ; }if (obj->type !=OBJ_COMMIT &&is_branch (refname)) { -error ("%s: not a commit" , refname); +error (_ ("%s: not a commit" ), refname); errors_found |=ERROR_REFS ; } default_refs++;
@@ -517,7 +525,7 @@ static void get_default_heads(void)* "show_unreachable" flag. */ if (!default_refs) { -fprintf (stderr,"notice: No default references\n" ); +fprintf_ln (stderr,_ ("notice: No default references" )); show_unreachable =0 ; } }
@@ -532,7 +540,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (read_loose_object (path, oid, &type, &size, &contents) <0 ) { errors_found |=ERROR_OBJECT ; -error ("%s: object corrupt or missing: %s" , +error (_ ("%s: object corrupt or missing: %s" ),oid_to_hex (oid), path);return 0 ;/* keep checking other objects */ }
@@ -545,7 +553,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (!obj) { errors_found |=ERROR_OBJECT ; -error ("%s: object could not be parsed: %s" , +error (_ ("%s: object could not be parsed: %s" ),oid_to_hex (oid), path);if (!eaten)free (contents);
@@ -565,7 +573,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)static int fsck_cruft (const char *basename,const char *path,void *data) {if (!starts_with (basename,"tmp_obj_" )) -fprintf (stderr,"bad sha1 file: %s\n" , path); +fprintf_ln (stderr,_ ("bad sha1 file: %s" ), path);return 0 ; }
@@ -580,7 +588,7 @@ static void fsck_object_dir(const char *path)struct progress *progress =NULL ;if (verbose) -fprintf (stderr,"Checking object directory\n" ); +fprintf_ln (stderr,_ ("Checking object directory" ));if (show_progress) progress =start_progress (_ ("Checking object directories" ),256 );
@@ -596,28 +604,28 @@ static int fsck_head_link(void)int null_is_error =0 ;if (verbose) -fprintf (stderr,"Checking HEAD link\n" ); +fprintf_ln (stderr,_ ("Checking HEAD link" )); head_points_at =resolve_ref_unsafe ("HEAD" ,0 , &head_oid,NULL );if (!head_points_at) { errors_found |=ERROR_REFS ; -return error ("Invalid HEAD" ); +return error (_ ("invalid HEAD" )); }if (!strcmp (head_points_at,"HEAD" ))/* detached HEAD */ null_is_error =1 ;else if (!starts_with (head_points_at,"refs/heads/" )) { errors_found |=ERROR_REFS ; -return error ("HEAD points to something strange (%s)" , +return error (_ ("HEAD points to something strange (%s)" ), head_points_at); }if (is_null_oid (&head_oid)) {if (null_is_error) { errors_found |=ERROR_REFS ; -return error ("HEAD: detached HEAD points at nothing" ); +return error (_ ("HEAD: detached HEAD points at nothing" )); } -fprintf (stderr,"notice: HEAD points to an unborn branch (%s)\n" , - head_points_at +11 ); +fprintf_ln (stderr,_ ("notice: HEAD points to an unborn branch (%s)" ), + head_points_at +11 ); }return 0 ; }
@@ -628,12 +636,12 @@ static int fsck_cache_tree(struct cache_tree *it)int err =0 ;if (verbose) -fprintf (stderr,"Checking cache tree\n" ); +fprintf_ln (stderr,_ ("Checking cache tree" ));if (0 <= it->entry_count) {struct object *obj =parse_object (the_repository, &it->oid);if (!obj) { -error ("%s: invalid sha1 pointer in cache-tree" , +error (_ ("%s: invalid sha1 pointer in cache-tree" ),oid_to_hex (&it->oid)); errors_found |=ERROR_REFS ;return 1 ;
@@ -644,7 +652,7 @@ static int fsck_cache_tree(struct cache_tree *it) obj, xstrdup(":"));mark_object_reachable (obj);if (obj->type !=OBJ_TREE ) - err |=objerror (obj,"non-tree in cache-tree" ); + err |=objerror (obj,_ ("non-tree in cache-tree" )); }for (i =0 ; i < it->subtree_nr; i++) err |=fsck_cache_tree (it->down[i]->cache_tree);
@@ -786,7 +794,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (!obj || !(obj->flags &HAS_OBJ )) {if (is_promisor_object (&oid))continue ; -error ("%s: object missing" ,oid_to_hex (&oid)); +error (_ ("%s: object missing" ),oid_to_hex (&oid)); errors_found |=ERROR_OBJECT ;continue ; }
@@ -798,7 +806,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)mark_object_reachable (obj);continue ; } -error ("invalid parameter: expected sha1, got '%s'" , arg); +error (_ ("invalid parameter: expected sha1, got '%s'" ), arg); errors_found |=ERROR_OBJECT ; }
t/t1410-reflog.sh +3 -3
@@ -20,12 +20,12 @@ check_have () { } check_fsck () { - output=$(git fsck --full) + git fsck --full >fsck.output case "$1" in '') - test -z "$output" ;; + test_must_be_empty fsck.output ;; *) - echo "$output" | grep "$1" ;; + test_i18ngrep "$1" fsck.output ;; esac }
t/t1450-fsck.sh +25 -25
189 lines not on this page · raw message
t/t6050-replace.sh +2 -2
@@ -133,8 +133,8 @@ test_expect_success 'tag replaced commit' ' test_expect_success '"git fsck" works' ' git fsck master >fsck_master.out && - grep "dangling commit $R" fsck_master.out && - grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + test_i18ngrep "dangling commit $R" fsck_master.out && + test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" '
t/t7415-submodule-names.sh +3 -3
@@ -154,7 +154,7 @@ test_expect_success 'fsck detects symlinked .gitmodules file' ' # symlink detector; this grep string comes from the config # variable name and will not be translated. test_must_fail git fsck 2>output && - grep gitmodulesSymlink output + test_i18ngrep gitmodulesSymlink output ) '
@@ -172,7 +172,7 @@ test_expect_success 'fsck detects non-blob .gitmodules' ' git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree && test_must_fail git fsck 2>output && - grep gitmodulesBlob output + test_i18ngrep gitmodulesBlob output ) '
@@ -186,7 +186,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' ' git commit -m "broken gitmodules" && git fsck 2>output && - grep gitmodulesParse output && + test_i18ngrep gitmodulesParse output && test_i18ngrep ! "bad config" output ) '
Signature · 1 line
2.19.1.1005.gac84295441
v3 cover Mark more strings for translation
In reply to Nguyễn Thái Ngọc Duyv3 is just small touchups here and there after the review comments from v2.
Range-diff against v2:
1: e77c203313 ! 1: 936f84d4b3 git.c: mark more strings for translation
@@ -3,7 +3,7 @@
git.c: mark more strings for translation
One string is slightly updated to keep consistency with the rest:
- die() should with lowercase.
+ die() should begin with lowercase.
diff --git a/git.c b/git.c
--- a/git.c
2: 12c9468696 = 2: 8ff2de14bf alias.c: mark split_cmdline_strerror() strings for translation
3: bf662dc105 = 3: 8e147f6bff archive.c: mark more strings for translation
4: 1d032b0fdf = 4: 5d574460eb attr.c: mark more string for translation
5: 2c3ad8c262 = 5: 8e37efb756 read-cache.c: turn die("internal error") to BUG()
6: df25ac78b1 = 6: 83b7b6d029 read-cache.c: mark more strings for translation
7: 241e5a7450 = 7: 4bd085682d read-cache.c: add missing colon separators
8: 8f60728b0f = 8: fb72be3a1e reflog: mark strings for translation
9: 24d2ed6682 = 9: 711812d70b remote.c: turn some error() or die() to BUG()
10: 26e8cee291 = 10: 0213c1f5eb remote.c: mark messages for translation
11: 2409f76902 = 11: 85459c65ca repack: mark more strings for translation
12: afafe6771c ! 12: 21916a8fb4 parse-options: replace opterror() with optname()@@ -2,6 +2,11 @@
parse-options: replace opterror() with optname()
+ Introduce optname() that does the early half of original opterror() to
+ come up with the name of the option reported back to the user, and use
+ it to kill opterror(). The callers of opterror() now directly call
+ error() using the string returned by opterror() instead.
+
There are a few issues with opterror()
- it tries to assemble an English sentence from pieces. This is not
@@ -14,8 +19,7 @@
- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
- Kill it and produce the option name with optname(). The user will use
- error() directly. This solves the second and third problems.
+ Using error() directly solves the second and third problems.
It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if
13: e8b4af8fac = 13: 8c9d2985b5 parse-options.c: turn some die() to BUG()
14: c3530e162e = 14: b81cdeda46 parse-options.c: mark more strings for translation
15: 644c56780c ! 15: dd872fc39b fsck: reduce word legos to help i18n
@@ -19,7 +19,7 @@
- static struct strbuf buf = STRBUF_INIT;
- char *name = name_objects ?
- lookup_decoration(fsck_walk_options.object_names, obj) : NULL;
-+ static struct strbuf bufs[4] = {
++ static struct strbuf bufs[] = {
+ STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
+ };
+ static int b = 0;
@@ -69,15 +69,18 @@
{
- objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
- return (type == FSCK_WARN) ? 0 : 1;
-+ if (type == FSCK_WARN) {
++ switch (type) {
++ case FSCK_WARN:
+ fprintf_ln(stderr, "warning in %s %s: %s",
+ printable_type(obj), describe_object(obj), message);
+ return 0;
++ case FSCK_ERROR:
++ fprintf_ln(stderr, "error in %s %s: %s",
++ printable_type(obj), describe_object(obj), message);
++ return 1;
++ default:
++ BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
+ }
-+
-+ fprintf_ln(stderr, "error in %s %s: %s",
-+ printable_type(obj), describe_object(obj), message);
-+ return 1;
}
static struct object_array pending;
16: 61af36567b ! 16: 8f1bbd1c65 fsck: mark strings for translation
@@ -28,22 +28,21 @@
return -1;
}
@@
- struct object *obj, int type, const char *message)
{
- if (type == FSCK_WARN) {
+ switch (type) {
+ case FSCK_WARN:
- fprintf_ln(stderr, "warning in %s %s: %s",
+ /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
+ fprintf_ln(stderr, _("warning in %s %s: %s"),
printable_type(obj), describe_object(obj), message);
return 0;
- }
-
-- fprintf_ln(stderr, "error in %s %s: %s",
-+ /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
-+ fprintf_ln(stderr, _("error in %s %s: %s"),
- printable_type(obj), describe_object(obj), message);
- return 1;
- }
+ case FSCK_ERROR:
+- fprintf_ln(stderr, "error in %s %s: %s",
++ /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
++ fprintf_ln(stderr, _("error in %s %s: %s"),
+ printable_type(obj), describe_object(obj), message);
+ return 1;
+ default:
@@
*/
if (!obj) {Nguyễn Thái Ngọc Duy (16):
git.c: mark more strings for translation
alias.c: mark split_cmdline_strerror() strings for translation archive.c: mark more strings for translation
attr.c: mark more string for translation read-cache.c: turn die("internal error") to BUG() read-cache.c: mark more strings for translation read-cache.c: add missing colon separators
reflog: mark strings for translation
remote.c: turn some error() or die() to BUG() remote.c: mark messages for translation
repack: mark more strings for translation
parse-options: replace opterror() with optname() parse-options.c: turn some die() to BUG() parse-options.c: mark more strings for translation
fsck: reduce word legos to help i18n
fsck: mark strings for translation
alias.c | 4 +- archive.c | 8 +- attr.c | 4 +- builtin/fsck.c | 159 +++++++++++++++++++++---------------- builtin/merge.c | 4 +- builtin/reflog.c | 34 ++++---- builtin/repack.c | 26 +++--- builtin/revert.c | 3 +- git.c | 32 ++++---- parse-options-cb.c | 7 +- parse-options.c | 64 ++++++++------- parse-options.h | 5 +- read-cache.c | 73 ++++++++--------- ref-filter.c | 8 +- remote.c | 49 ++++++------ t/t0040-parse-options.sh | 4 +- t/t1410-reflog.sh | 6 +- t/t1450-fsck.sh | 52 ++++++------ t/t4211-line-log.sh | 2 +- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +- 21 files changed, 295 insertions(+), 259 deletions(-)
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 1/16 git.c: mark more strings for translation
One string is slightly updated to keep consistency with the rest:die() should begin with lowercase.
--- git.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
git.c +15 -15
@@ -338,27 +338,27 @@ static int handle_alias(int *argcp, const char ***argv)if (ret >=0 )/* normal exit */ exit (ret); -die_errno ("while expanding alias '%s': '%s'" , - alias_command, alias_string +1 ); +die_errno (_ ("while expanding alias '%s': '%s'" ), + alias_command, alias_string +1 ); } count =split_cmdline (alias_string, &new_argv);if (count <0 ) -die ("Bad alias.%s string: %s" , alias_command, +die (_ ("bad alias.%s string: %s" ), alias_command,split_cmdline_strerror (count)); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) -die ("alias '%s' changes environment variables.\n" -"You can use '!git' in the alias to do this" , - alias_command); +die (_ ("alias '%s' changes environment variables.\n" +"You can use '!git' in the alias to do this" ), + alias_command);memmove (new_argv - option_count, new_argv, count *sizeof (char *)); new_argv -= option_count;if (count <1 ) -die ("empty alias for %s" , alias_command); +die (_ ("empty alias for %s" ), alias_command);if (!strcmp (alias_command, new_argv[0 ])) -die ("recursive alias: %s" , alias_command); +die (_ ("recursive alias: %s" ), alias_command); trace_argv_printf(new_argv, "trace: alias expansion: %s =>",
@@ -409,7 +409,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if (!help &&get_super_prefix ()) {if (!(p->option &SUPPORT_SUPER_PREFIX )) -die ("%s doesn't support --super-prefix" , p->cmd); +die (_ ("%s doesn't support --super-prefix" ), p->cmd); }if (!help && p->option &NEED_WORK_TREE )
@@ -433,11 +433,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)/* Check for ENOSPC and EIO errors.. */ if (fflush (stdout)) -die_errno ("write failure on standard output" ); +die_errno (_ ("write failure on standard output" ));if (ferror (stdout)) -die ("unknown write failure on standard output" ); +die (_ ("unknown write failure on standard output" ));if (fclose (stdout)) -die_errno ("close failed on standard output" ); +die_errno (_ ("close failed on standard output" ));return 0 ; }
@@ -648,7 +648,7 @@ static void execv_dashed_external(const char **argv)int status;if (get_super_prefix ()) -die ("%s doesn't support --super-prefix" , argv[0 ]); +die (_ ("%s doesn't support --super-prefix" ), argv[0 ]);if (use_pager ==-1 && !is_builtin (argv[0 ])) use_pager =check_pager_config (argv[0 ]);
@@ -760,7 +760,7 @@ int cmd_main(int argc, const char **argv)if (skip_prefix (cmd,"git-" , &cmd)) { argv[0 ] = cmd;handle_builtin (argc, argv); -die ("cannot handle %s as a builtin" , cmd); +die (_ ("cannot handle %s as a builtin" ), cmd); }/* Look for flags.. */
@@ -773,7 +773,7 @@ int cmd_main(int argc, const char **argv) }else {/* The user didn't specify a command; give them help */ commit_pager_choice (); -printf ("usage: %s\n\n" , git_usage_string); +printf (_ ("usage: %s\n\n" ), git_usage_string);list_common_cmds_help ();printf ("\n%s\n" ,_ (git_more_info_string));exit (1 );
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 2/16 alias.c: mark split_cmdline_strerror() strings for translation
In reply to Nguyễn Thái Ngọc DuyThis function can be part of translated messages. To make sure we don't have a sentence with mixed languages, mark the strings for translation, but only use translated strings in places we know we will output translated strings.
--- alias.c | 4 ++-- builtin/merge.c | 2 +- git.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
alias.c +2 -2
@@ -47,8 +47,8 @@ void list_aliases(struct string_list *list)#define SPLIT_CMDLINE_BAD_ENDING 1#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2static const char *split_cmdline_errors[] = { -"cmdline ends with \\" , -"unclosed quote" +N_ ("cmdline ends with \\" ), +N_ ("unclosed quote" ) };int split_cmdline (char *cmdline,const char ***argv)
builtin/merge.c +1 -1
@@ -577,7 +577,7 @@ static void parse_branch_merge_options(char *bmo) argc =split_cmdline (bmo, &argv);if (argc <0 )die (_ ("Bad branch.%s.mergeoptions string: %s" ), branch, -split_cmdline_strerror (argc)); +_ (split_cmdline_strerror (argc)));REALLOC_ARRAY (argv, argc +2 );MOVE_ARRAY (argv +1 , argv, argc +1 ); argc++;
git.c +1 -1
@@ -344,7 +344,7 @@ static int handle_alias(int *argcp, const char ***argv) count =split_cmdline (alias_string, &new_argv);if (count <0 )die (_ ("bad alias.%s string: %s" ), alias_command, -split_cmdline_strerror (count)); +_ (split_cmdline_strerror (count))); option_count =handle_options (&new_argv, &count, &envchanged);if (envchanged) die(_("alias '%s' changes environment variables.\n"
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 3/16 archive.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo messages also print extra information to be more useful
--- archive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
archive.c +4 -4
@@ -385,12 +385,12 @@ static void parse_treeish_arg(const char **argv,int refnamelen = colon - name;if (!dwim_ref (name, refnamelen, &oid, &ref)) -die ("no such ref: %.*s" , refnamelen, name); +die (_ ("no such ref: %.*s" ), refnamelen, name);free (ref); }if (get_oid (name, &oid)) -die ("Not a valid object name" ); +die (_ ("not a valid object name: %s" ), name); commit =lookup_commit_reference_gently (ar_args->repo, &oid,1 );if (commit) {
@@ -403,7 +403,7 @@ static void parse_treeish_arg(const char **argv, tree =parse_tree_indirect (&oid);if (tree ==NULL ) -die ("not a tree object" ); +die (_ ("not a tree object: %s" ),oid_to_hex (&oid));if (prefix) {struct object_id tree_oid;
@@ -413,7 +413,7 @@ static void parse_treeish_arg(const char **argv, err =get_tree_entry (&tree->object.oid, prefix, &tree_oid, &mode);if (err || !S_ISDIR (mode)) -die ("current working directory is untracked" ); +die (_ ("current working directory is untracked" )); tree =parse_tree_indirect (&tree_oid); }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 4/16 attr.c: mark more string for translation
In reply to Nguyễn Thái Ngọc Duy--- attr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
attr.c +2 -2
@@ -372,8 +372,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,if (strlen (ATTRIBUTE_MACRO_PREFIX ) < namelen &&starts_with (name,ATTRIBUTE_MACRO_PREFIX )) {if (!macro_ok) { -fprintf (stderr,"%s not allowed: %s:%d\n" , - name, src, lineno); +fprintf_ln (stderr,_ ("%s not allowed: %s:%d" ), + name, src, lineno); goto fail_return; } is_macro =1 ;
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 5/16 read-cache.c: turn die("internal error") to BUG()
In reply to Nguyễn Thái Ngọc Duy--- read-cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
read-cache.c +3 -3
@@ -316,7 +316,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) changed |=DATA_CHANGED ;return changed;default : -die ("internal error: ce_mode is %o" , ce->ce_mode); +BUG ("unsupported ce_mode: %o" , ce->ce_mode); } changed |=match_stat_data (&ce->ce_stat_data, st);
@@ -2356,14 +2356,14 @@ void validate_cache_entries(const struct index_state *istate)for (i =0 ; i < istate->cache_nr; i++) {if (!istate) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); }else if (!istate->ce_mem_pool || !mem_pool_contains (istate->ce_mem_pool, istate->cache[i])) {if (!istate->split_index || !istate->split_index->base || !istate->split_index->base->ce_mem_pool || !mem_pool_contains (istate->split_index->base->ce_mem_pool, istate->cache[i])) { -die ("internal error: cache entry is not allocated from expected memory pool" ); +BUG ("cache entry is not allocated from expected memory pool" ); } } }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 6/16 read-cache.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyThere are a couple other improvements on these strings as well:
- add missing colon (as separator)
- quote paths
- provide more information on error messages
- keep first word in lowercase
--- read-cache.c | 57 +++++++++++++++++++++++++------------------------ t/t1450-fsck.sh | 2 +- 2 files changed, 30 insertions(+), 29 deletions(-)
read-cache.c +29 -28
@@ -672,7 +672,8 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,struct cache_entry *new_entry;if (alias->ce_flags &CE_ADDED ) -die ("Will not add file alias '%s' ('%s' already exists in index)" , ce->name, alias->name); +die (_ ("will not add file alias '%s' ('%s' already exists in index)" ), + ce->name, alias->name);/* Ok, create the new entry using the name of the existing alias */ len =ce_namelen (alias);
@@ -687,7 +688,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce) {struct object_id oid;if (write_object_file ("" ,0 , blob_type, &oid)) -die ("cannot create an empty blob in the object database" ); +die (_ ("cannot create an empty blob in the object database" ));oidcpy (&ce->oid, &oid); }
@@ -708,7 +709,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, newflags |=HASH_RENORMALIZE ;if (!S_ISREG (st_mode) && !S_ISLNK (st_mode) && !S_ISDIR (st_mode)) -return error ("%s: can only add regular files, symbolic links or git-directories" , path); +return error (_ ("%s: can only add regular files, symbolic links or git-directories" ), path); namelen =strlen (path);if (S_ISDIR (st_mode)) {
@@ -763,7 +764,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,if (!intent_only) {if (index_path (istate, &ce->oid, path, st, newflags)) {discard_cache_entry (ce); -return error ("unable to index file %s" , path); +return error (_ ("unable to index file '%s'" ), path); } }else set_object_name_for_intent_to_add_entry (ce);
@@ -782,7 +783,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,discard_cache_entry (ce); else if (add_index_entry(istate, ce, add_option)) {discard_cache_entry (ce); -return error ("unable to add %s to index" , path); +return error (_ ("unable to add '%s' to index" ), path); }if (verbose && !was_same)printf ("add '%s'\n" , path);
@@ -793,7 +794,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags) {struct stat st;if (lstat (path, &st)) -die_errno ("unable to stat '%s'" , path); +die_errno (_ ("unable to stat '%s'" ), path);return add_to_index (istate, path, &st, flags); }
@@ -818,7 +819,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,int len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -844,7 +845,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct oint len;if (!verify_path (path, mode)) { -error ("Invalid path '%s'" , path); +error (_ ("invalid path '%s'" ), path);return NULL ; }
@@ -1297,12 +1298,12 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_eif (!ok_to_add)return -1 ;if (!verify_path (ce->name, ce->ce_mode)) -return error ("Invalid path '%s'" , ce->name); +return error (_ ("invalid path '%s'" ), ce->name);if (!skip_df_check &&check_file_directory_conflict (istate, ce, pos, ok_to_replace)) {if (!ok_to_replace) -return error ("'%s' appears as both a file and as a directory" , +return error (_ ("'%s' appears as both a file and as a directory" ), ce->name); pos =index_name_stage_pos (istate, ce->name,ce_namelen (ce),ce_stage (ce)); pos = -pos-1 ;
@@ -1676,10 +1677,10 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)int hdr_version;if (hdr->hdr_signature !=htonl (CACHE_SIGNATURE )) -return error ("bad signature" ); +return error (_ ("bad signature 0x%08x" ), hdr->hdr_signature); hdr_version =ntohl (hdr->hdr_version);if (hdr_version <INDEX_FORMAT_LB ||INDEX_FORMAT_UB < hdr_version) -return error ("bad index version %d" , hdr_version); +return error (_ ("bad index version %d" ), hdr_version);if (!verify_index_checksum)return 0 ;
@@ -1688,7 +1689,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) the_hash_algo->update_fn (&c, hdr, size - the_hash_algo->rawsz); the_hash_algo->final_fn (hash, &c);if (!hasheq (hash, (unsigned char *)hdr + size - the_hash_algo->rawsz)) -return error ("bad index file sha1 signature" ); +return error (_ ("bad index file sha1 signature" ));return 0 ; }
@@ -1718,9 +1719,9 @@ static int read_index_extension(struct index_state *istate,break ;default :if (*ext <'A' ||'Z' < *ext) -return error ("index uses %.4s extension, which we do not understand" , +return error (_ ("index uses %.4s extension, which we do not understand" ), ext); -fprintf (stderr,"ignoring %.4s extension\n" , ext); +fprintf_ln (stderr,_ ("ignoring %.4s extension" ), ext);break ; }return 0 ;
@@ -1767,7 +1768,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, extended_flags =get_be16 (&ondisk2->flags2) <<16 ;/* We do not yet understand any bit out of CE_EXTENDED_FLAGS */ if (extended_flags & ~CE_EXTENDED_FLAGS ) -die ("Unknown index entry format %08x" , extended_flags); +die (_ ("unknown index entry format 0x%08x" ), extended_flags); flags |= extended_flags; name = ondisk2->name; }
@@ -1840,13 +1841,13 @@ static void check_ce_order(struct index_state *istate)int name_compare =strcmp (ce->name, next_ce->name);if (0 < name_compare) -die ("unordered stage entries in index" ); +die (_ ("unordered stage entries in index" ));if (!name_compare) {if (!ce_stage (ce)) -die ("multiple stage entries for merged file '%s'" , +die (_ ("multiple stage entries for merged file '%s'" ), ce->name);if (ce_stage (ce) >ce_stage (next_ce)) -die ("unordered stage entries for '%s'" , +die (_ ("unordered stage entries for '%s'" ), ce->name); } }
@@ -2149,19 +2150,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)if (fd <0 ) {if (!must_exist && errno ==ENOENT )return 0 ; -die_errno ("%s: index file open failed" , path); +die_errno (_ ("%s: index file open failed" ), path); }if (fstat (fd, &st)) -die_errno ("cannot stat the open index" ); +die_errno (_ ("%s: cannot stat the open index" ), path); mmap_size =xsize_t (st.st_size);if (mmap_size <sizeof (struct cache_header ) + the_hash_algo->rawsz) -die ("index file smaller than expected" ); +die (_ ("%s: index file smaller than expected" ), path); mmap =xmmap (NULL , mmap_size,PROT_READ ,MAP_PRIVATE , fd,0 );if (mmap ==MAP_FAILED ) -die_errno ("unable to map index file" ); +die_errno (_ ("%s: unable to map index file" ), path);close (fd); hdr = (const struct cache_header *)mmap;
@@ -2243,7 +2244,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) unmap:munmap ((void *)mmap, mmap_size); -die ("index file corrupt" ); +die (_ ("index file corrupt" )); }/*
@@ -2255,7 +2256,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)static void freshen_shared_index (const char *shared_index,int warn) {if (!check_and_freshen_file (shared_index,1 ) && warn) -warning ("could not freshen shared index '%s'" , shared_index); +warning (_ ("could not freshen shared index '%s'" ), shared_index); } int read_index_from(struct index_state *istate, const char *path,
@@ -2290,7 +2291,7 @@ int read_index_from(struct index_state *istate, const char *path, base_path =xstrfmt ("%s/sharedindex.%s" , gitdir, base_oid_hex); ret =do_read_index (split_index->base, base_path,1 );if (!oideq (&split_index->base_oid, &split_index->base->oid)) -die ("broken index, expect %s in %s, got %s" , +die (_ ("broken index, expect %s in %s, got %s" ), base_oid_hex, base_path,oid_to_hex (&split_index->base->oid));
@@ -3076,7 +3077,7 @@ static int write_shared_index(struct index_state *istate,return ret; ret =adjust_shared_perm (get_tempfile_path (*temp));if (ret) { -error ("cannot fix permission bits on %s" ,get_tempfile_path (*temp)); +error (_ ("cannot fix permission bits on '%s'" ),get_tempfile_path (*temp));return ret; } ret = rename_tempfile(temp,
@@ -3222,7 +3223,7 @@ int read_index_unmerged(struct index_state *istate) new_ce->ce_namelen = len; new_ce->ce_mode = ce->ce_mode;if (add_index_entry (istate, new_ce,ADD_CACHE_SKIP_DFCHECK )) -return error ("%s: cannot drop to stage #0" , +return error (_ ("%s: cannot drop to stage #0" ), new_ce->name); }return unmerged;
t/t1450-fsck.sh +1 -1
@@ -754,7 +754,7 @@ test_expect_success 'detect corrupt index file in fsck' ' test_when_finished "mv .git/index.backup .git/index" && corrupt_index_checksum && test_must_fail git fsck --cache 2>errors && - grep "bad index file" errors + test_i18ngrep "bad index file" errors ' test_done
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 7/16 read-cache.c: add missing colon separators
In reply to Nguyễn Thái Ngọc Duytypechange_fmt and added_fmt should have a colon before "needs update". Align the statements to make it easier to read and see. Also drop the unnecessary ().
--- read-cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
read-cache.c +5 -5
@@ -1492,11 +1492,11 @@ int refresh_index(struct index_state *istate, unsigned int flags, istate->cache_nr);trace_performance_enter (); - modified_fmt = (in_porcelain ?"M\t%s\n" :"%s: needs update\n" ); - deleted_fmt = (in_porcelain ?"D\t%s\n" :"%s: needs update\n" ); - typechange_fmt = (in_porcelain ?"T\t%s\n" :"%s needs update\n" ); - added_fmt = (in_porcelain ?"A\t%s\n" :"%s needs update\n" ); - unmerged_fmt = (in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ); + modified_fmt = in_porcelain ?"M\t%s\n" :"%s: needs update\n" ; + deleted_fmt = in_porcelain ?"D\t%s\n" :"%s: needs update\n" ; + typechange_fmt = in_porcelain ?"T\t%s\n" :"%s: needs update\n" ; + added_fmt = in_porcelain ?"A\t%s\n" :"%s: needs update\n" ; + unmerged_fmt = in_porcelain ?"U\t%s\n" :"%s: needs merge\n" ;for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce, *new_entry;int cache_errno =0 ;
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 8/16 reflog: mark strings for translation
In reply to Nguyễn Thái Ngọc DuyOne string "nothing to delete?" is rephrased to be more helpful.
--- builtin/reflog.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
builtin/reflog.c +19 -15
@@ -13,11 +13,15 @@/* NEEDSWORK: switch to using parse_options */ static const char reflog_expire_usage[] = -"git reflog expire [--expire=<time>] [--expire-unreachable=<time>] [--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] [--verbose] [--all] <refs>..." ; +N_ ("git reflog expire [--expire=<time>] " +"[--expire-unreachable=<time>] " +"[--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] " +"[--verbose] [--all] <refs>..." );static const char reflog_delete_usage[] = -"git reflog delete [--rewrite] [--updateref] [--dry-run | -n] [--verbose] <refs>..." ; +N_ ("git reflog delete [--rewrite] [--updateref] " +"[--dry-run | -n] [--verbose] <refs>..." );static const char reflog_exists_usage[] = -"git reflog exists <ref>" ; +N_ ("git reflog exists <ref>" );static timestamp_t default_reflog_expire;static timestamp_t default_reflog_expire_unreachable;
@@ -556,7 +560,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_expire_usage); +usage (_ (reflog_expire_usage));else break ; }
@@ -569,7 +573,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)if (cb.cmd.stalefix) {repo_init_revisions (the_repository, &cb.cmd.revs, prefix);if (flags &EXPIRE_REFLOGS_VERBOSE ) -printf ("Marking reachable objects..." ); +printf (_ ("Marking reachable objects..." ));mark_reachable_objects (&cb.cmd.revs,0 ,0 ,NULL );if (flags &EXPIRE_REFLOGS_VERBOSE )putchar ('\n' );
@@ -598,7 +602,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)char *ref;struct object_id oid;if (!dwim_log (argv[i],strlen (argv[i]), &oid, &ref)) { - status |=error ("%s points nowhere!" , argv[i]); + status |=error (_ ("%s points nowhere!" ), argv[i]);continue ; }set_reflog_expiry_param (&cb.cmd, explicit_expiry, ref);
@@ -644,13 +648,13 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_delete_usage); +usage (_ (reflog_delete_usage));else break ; }if (argc - i <1 ) -return error ("Nothing to delete?" ); +return error (_ ("no reflog specified to delete" ));for ( ; i < argc; i++) {const char *spec =strstr (argv[i],"@{" );
@@ -659,12 +663,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)int recno;if (!spec) { - status |=error ("Not a reflog: %s" , argv[i]); + status |=error (_ ("not a reflog: %s" ), argv[i]);continue ; }if (!dwim_log (argv[i], spec - argv[i], &oid, &ref)) { - status |=error ("no reflog for '%s'" , argv[i]); + status |=error (_ ("no reflog for '%s'" ), argv[i]);continue ; }
@@ -699,7 +703,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)break ; }else if (arg[0 ] =='-' ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));else break ; }
@@ -707,10 +711,10 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix) start = i;if (argc - start !=1 ) -usage (reflog_exists_usage); +usage (_ (reflog_exists_usage));if (check_refname_format (argv[start],REFNAME_ALLOW_ONELEVEL )) -die ("invalid ref format: %s" , argv[start]); +die (_ ("invalid ref format: %s" ), argv[start]);return !reflog_exists (argv[start]); }
@@ -719,12 +723,12 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)*/ static const char reflog_usage[] = -"git reflog [ show | expire | delete | exists ]" ; +N_ ("git reflog [ show | expire | delete | exists ]" );int cmd_reflog (int argc,const char **argv,const char *prefix) {if (argc >1 && !strcmp (argv[1 ],"-h" )) -usage (reflog_usage); +usage (_ (reflog_usage));/* With no command, we default to showing it. */ if (argc <2 || *argv[1 ] =='-' )
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 9/16 remote.c: turn some error() or die() to BUG()
In reply to Nguyễn Thái Ngọc DuyThe first error, "internal error", is clearly a BUG(). The second two are meant to catch calls with invalid parameters and should never happen outside the test suite.
--- remote.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
remote.c +3 -3
@@ -620,7 +620,7 @@ static void handle_duplicate(struct ref *ref1, struct ref *ref2)* FETCH_HEAD_IGNORE entries always appear at * the end of the list. */ -die (_ ("Internal error" )); +BUG ("Internal error" ); } }free (ref2->peer_ref);
@@ -707,7 +707,7 @@ static void query_refspecs_multiple(struct refspec *rs,int find_src = !query->src;if (find_src && !query->dst) -error ("query_refspecs_multiple: need either src or dst" ); +BUG ("query_refspecs_multiple: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
@@ -735,7 +735,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)char **result = find_src ? &query->src : &query->dst;if (find_src && !query->dst) -return error ("query_refspecs: need either src or dst" ); +BUG ("query_refspecs: need either src or dst" );for (i =0 ; i < rs->nr; i++) {struct refspec_item *refspec = &rs->items[i];
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 10/16 remote.c: mark messages for translation
In reply to Nguyễn Thái Ngọc DuyThe two strings are slightly modified to be consistent with the rest:die() and error() start with a lowercase.
--- remote.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
remote.c +22 -21
@@ -359,7 +359,7 @@ static int handle_config(const char *key, const char *value, void *cb)return 0 ;/* Handle remote.<name>.* variables */ if (*name =='/' ) { -warning ("Config remote shorthand cannot begin with '/': %s" , +warning (_ ("config remote shorthand cannot begin with '/': %s" ), name);return 0 ; }
@@ -406,7 +406,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->receivepack) remote->receivepack = v;else -error ("more than one receivepack given, using the first" ); +error (_ ("more than one receivepack given, using the first" )); }else if (!strcmp (subkey,"uploadpack" )) {const char *v;if (git_config_string (&v, key, value))
@@ -414,7 +414,7 @@ static int handle_config(const char *key, const char *value, void *cb)if (!remote->uploadpack) remote->uploadpack = v;else -error ("more than one uploadpack given, using the first" ); +error (_ ("more than one uploadpack given, using the first" )); }else if (!strcmp (subkey,"tagopt" )) {if (!strcmp (value,"--no-tags" )) remote->fetch_tags =-1 ;
@@ -680,7 +680,7 @@ static int match_name_with_pattern(const char *key, const char *name,size_t namelen;int ret;if (!kstar) -die ("Key '%s' of pattern had no '*'" , key); +die (_ ("key '%s' of pattern had no '*'" ), key); klen = kstar - key; ksuffixlen =strlen (kstar +1 ); namelen =strlen (name);
@@ -690,7 +690,7 @@ static int match_name_with_pattern(const char *key, const char *name,struct strbuf sb =STRBUF_INIT ;const char *vstar =strchr (value,'*' );if (!vstar) -die ("Value '%s' of pattern has no '*'" , value); +die (_ ("value '%s' of pattern has no '*'" ), value);strbuf_add (&sb, value, vstar - value);strbuf_add (&sb, name + klen, namelen - klen - ksuffixlen);strbuf_addstr (&sb, vstar +1 );
@@ -995,12 +995,12 @@ static int match_explicit_lhs(struct ref *src,* way to delete 'other' ref at the remote end. */ if (try_explicit_object_name (rs->src, match) <0 ) -return error ("src refspec %s does not match any." , rs->src); +return error (_ ("src refspec %s does not match any" ), rs->src);if (allocated_match) *allocated_match =1 ;return 0 ;default : -return error ("src refspec %s matches more than one." , rs->src); +return error (_ ("src refspec %s matches more than one" ), rs->src); } }
@@ -1030,7 +1030,7 @@ static int match_explicit(struct ref *src, struct ref *dst,if (!dst_value || ((flag &REF_ISSYMREF ) && !starts_with (dst_value,"refs/heads/" ))) -die ("%s cannot be resolved to branch." , +die (_ ("%s cannot be resolved to branch" ), matched_src->name); }
@@ -1041,30 +1041,30 @@ static int match_explicit(struct ref *src, struct ref *dst,if (starts_with (dst_value,"refs/" )) matched_dst =make_linked_ref (dst_value, dst_tail);else if (is_null_oid (&matched_src->new_oid)) -error ("unable to delete '%s': remote ref does not exist" , +error (_ ("unable to delete '%s': remote ref does not exist" ), dst_value);else if ((dst_guess =guess_ref (dst_value, matched_src))) { matched_dst =make_linked_ref (dst_guess, dst_tail);free (dst_guess); }else -error ("unable to push to unqualified destination: %s\n" -"The destination refspec neither matches an " -"existing ref on the remote nor\n" -"begins with refs/, and we are unable to " -"guess a prefix based on the source ref." , +error (_ ("unable to push to unqualified destination: %s\n" +"The destination refspec neither matches an " +"existing ref on the remote nor\n" +"begins with refs/, and we are unable to " +"guess a prefix based on the source ref." ), dst_value);break ;default : matched_dst =NULL ; -error ("dst refspec %s matches more than one." , +error (_ ("dst refspec %s matches more than one" ), dst_value);break ; }if (!matched_dst)return -1 ;if (matched_dst->peer_ref) -return error ("dst ref %s receives from more than one src." , - matched_dst->name); +return error (_ ("dst ref %s receives from more than one src" ), + matched_dst->name);else { matched_dst->peer_ref = allocated_src ? matched_src :
@@ -1750,7 +1750,7 @@ int get_fetch_map(const struct ref *remote_refs, ref_map =get_remote_ref (remote_refs, name); }if (!missing_ok && !ref_map) -die ("Couldn't find remote ref %s" , name); +die (_ ("couldn't find remote ref %s" ), name);if (ref_map) { ref_map->peer_ref =get_local_ref (refspec->dst);if (ref_map->peer_ref && refspec->force)
@@ -1763,7 +1763,7 @@ int get_fetch_map(const struct ref *remote_refs,if (!starts_with ((*rmp)->peer_ref->name,"refs/" ) ||check_refname_format ((*rmp)->peer_ref->name,0 )) {struct ref *ignore = *rmp; -error ("* Ignoring funny ref '%s' locally" , +error (_ ("* Ignoring funny ref '%s' locally" ), (*rmp)->peer_ref->name); *rmp = (*rmp)->next;free (ignore->peer_ref);
@@ -1858,7 +1858,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,repo_init_revisions (the_repository, &revs,NULL );setup_revisions (argv.argc, argv.argv, &revs,NULL );if (prepare_revision_walk (&revs)) -die ("revision walk setup failed" ); +die (_ ("revision walk setup failed" ));/* ... and count the commits on each side. */ while (1 ) {
@@ -2131,7 +2131,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, ielse if (!colon[1 ])oidclr (&entry->expect);else if (get_oid (colon +1 , &entry->expect)) -return error ("cannot parse expected object name '%s'" , colon +1 ); +return error (_ ("cannot parse expected object name '%s'" ), + colon +1 );return 0 ; }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 11/16 repack: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo strings are slightly updated to be consistent with the rest: die() starts with lowercase.
--- builtin/repack.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
builtin/repack.c +13 -13
@@ -197,7 +197,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,if (cmd->in ==-1 ) {if (start_command (cmd)) -die ("Could not start pack-objects to repack promisor objects" ); +die (_ ("could not start pack-objects to repack promisor objects" )); }xwrite (cmd->in,oid_to_hex (oid),GIT_SHA1_HEXSZ );
@@ -236,7 +236,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,char *promisor_name;int fd;if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects." ));string_list_append (names, line.buf);/*
@@ -247,13 +247,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args, line.buf); fd =open (promisor_name,O_CREAT |O_EXCL |O_WRONLY ,0600 );if (fd <0 ) -die_errno ("unable to create '%s'" , promisor_name); +die_errno (_ ("unable to create '%s'" ), promisor_name);close (fd);free (promisor_name); }fclose (out);if (finish_command (&cmd)) -die ("Could not finish pack-objects to repack promisor objects" ); +die (_ ("could not finish pack-objects to repack promisor objects" )); }#define ALL_INTO_ONE 1
@@ -408,7 +408,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) out =xfdopen (cmd.out,"r" );while (strbuf_getline_lf (&line, out) !=EOF ) {if (line.len !=40 ) -die ("repack: Expecting 40 character sha1 lines only from pack-objects." ); +die (_ ("repack: Expecting 40 character sha1 lines only from pack-objects" ));string_list_append (&names, line.buf); }fclose (out);
@@ -417,7 +417,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)return ret;if (!names.nr && !po_args.quiet) -printf ("Nothing new to pack.\n" ); +printf_ln (_ ("Nothing new to pack." ));/* * Ok we have prepared all new packfiles.
@@ -477,13 +477,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)if (rollback_failure.nr) {int i;fprintf (stderr, -"WARNING: Some packs in use have been renamed by\n" -"WARNING: prefixing old- to their name, in order to\n" -"WARNING: replace them with the new version of the\n" -"WARNING: file. But the operation failed, and the\n" -"WARNING: attempt to rename them back to their\n" -"WARNING: original names also failed.\n" -"WARNING: Please rename them in %s manually:\n" , packdir); +_ ("WARNING: Some packs in use have been renamed by\n" +"WARNING: prefixing old- to their name, in order to\n" +"WARNING: replace them with the new version of the\n" +"WARNING: file. But the operation failed, and the\n" +"WARNING: attempt to rename them back to their\n" +"WARNING: original names also failed.\n" +"WARNING: Please rename them in %s manually:\n" ), packdir);for (i =0 ; i < rollback_failure.nr; i++) fprintf(stderr, "WARNING: old-%s -> %s\n", rollback_failure.items[i].string,
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 12/16 parse-options: replace opterror() with optname()
In reply to Nguyễn Thái Ngọc DuyIntroduce optname() that does the early half of original opterror() to come up with the name of the option reported back to the user, and use it to kill opterror(). The callers of opterror() now directly call error() using the string returned by opterror() instead.
There are a few issues with opterror()
- it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence.
- It's a wrapper around error() and needs some hack to let the compiler know it always returns -1.
- Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it.
Using error() directly solves the second and third problems.
It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling optname() when 'flags' is known in advance.
Mark of these strings for translation as well while at there.
--- builtin/merge.c | 2 +- builtin/revert.c | 3 ++- parse-options-cb.c | 7 ++++--- parse-options.c | 46 +++++++++++++++++++++++++-------------------- parse-options.h | 5 +---- ref-filter.c | 8 +++++--- t/t4211-line-log.sh | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-)
builtin/merge.c +1 -1
@@ -128,7 +128,7 @@ static int option_read_message(struct parse_opt_ctx_t *ctx, ctx->argc--; arg = *++ctx->argv; }else -return opterror (opt,"requires a value" ,0 ); +return error (_ ("option `%s' requires a value" ), opt->long_name);if (buf->len)strbuf_addch (buf,'\n' );
builtin/revert.c +2 -1
@@ -69,7 +69,8 @@ static int option_parse_m(const struct option *opt, replay->mainline =strtol (arg, &end,10 );if (*end || replay->mainline <=0 ) -return opterror (opt,"expects a number greater than zero" ,0 ); +return error (_ ("option `%s' expects a number greater than zero" ), + opt->long_name);return 0 ; }
parse-options-cb.c +4 -3
@@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) }else { v =strtol (arg, (char **)&arg,10 );if (*arg) -return opterror (opt,"expects a numerical value" ,0 ); +return error (_ ("option `%s' expects a numerical value" ), + opt->long_name);if (v && v <MINIMUM_ABBREV ) v =MINIMUM_ABBREV ;else if (v >40 )
@@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg, arg = unset ?"never" : (const char *)opt->defval; value =git_config_colorbool (NULL , arg);if (value <0 ) -return opterror (opt, -"expects \"always\", \"auto\", or \"never\"" ,0 ); +return error (_ ("option `%s' expects \"always\", \"auto\", or \"never\"" ), + opt->long_name); *(int *)opt->value = value;return 0 ; }
parse-options.c +26 -20
99 lines not on this page · raw message
parse-options.h +1 -4
@@ -189,10 +189,7 @@ extern NORETURN void usage_msg_opt(const char *msg, const struct option *options);extern int optbug (const struct option *opt,const char *reason); -extern int opterror (const struct option *opt,const char *reason,int flags); -#if defined(__GNUC__) -#define opterror (o,r,f) (opterror((o),(r),(f)), const_error()) -#endif +const char *optname (const struct option *opt,int flags);/*----- incremental advanced APIs -----*/
ref-filter.c +5 -3
@@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)if (rf->merge) {if (no_merged) { -return opterror (opt,"is incompatible with --merged" ,0 ); +return error (_ ("option `%s' is incompatible with --merged" ), + opt->long_name); }else { -return opterror (opt,"is incompatible with --no-merged" ,0 ); +return error (_ ("option `%s' is incompatible with --no-merged" ), + opt->long_name); } }
@@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) rf->merge_commit =lookup_commit_reference_gently (the_repository, &oid,0 );if (!rf->merge_commit) -return opterror (opt,"must point to a commit" ,0 ); +return error (_ ("option `%s' must point to a commit" ), opt->long_name);return 0 ; }
t/t4211-line-log.sh +1 -1
@@ -25,7 +25,7 @@ canned_test_failure () { test_bad_opts () { test_expect_success "invalid args: $1" " test_must_fail git log $1 2>errors && - grep '$2' errors + test_i18ngrep '$2' errors " }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 13/16 parse-options.c: turn some die() to BUG()
In reply to Nguyễn Thái Ngọc DuyThese two strings are clearly not for the user to see. Reduce the violence in one string while at there.
--- parse-options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parse-options.c +2 -2
@@ -197,7 +197,7 @@ static int get_value(struct parse_opt_ctx_t *p,return 0 ;default : -die ("should not happen, someone must be hit on the forehead" ); +BUG ("opt->type %d should not happen" , opt->type); } }
@@ -424,7 +424,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->flags = flags;if ((flags &PARSE_OPT_KEEP_UNKNOWN ) && (flags &PARSE_OPT_STOP_AT_NON_OPTION )) -die ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" ); +BUG ("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together" );parse_options_check (options); }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 14/16 parse-options.c: mark more strings for translation
In reply to Nguyễn Thái Ngọc DuyOne error is updated to start with lowercase to be consistent with the rest.
--- parse-options.c | 14 +++++++------- t/t0040-parse-options.sh | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-)
parse-options.c +7 -7
@@ -319,8 +319,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, }if (ambiguous_option) { - error("Ambiguous option: %s " - "(could be --%s%s or --%s%s)", + error(_("ambiguous option: %s " + "(could be --%s%s or --%s%s)"), arg, (ambiguous_flags & OPT_UNSET) ? "no-" : "", ambiguous_option->long_name,
@@ -353,7 +353,7 @@ static void check_typos(const char *arg, const struct option *options)return ;if (starts_with (arg,"no-" )) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); }
@@ -361,7 +361,7 @@ static void check_typos(const char *arg, const struct option *options)if (!options->long_name)continue ;if (starts_with (options->long_name, arg)) { -error ("did you mean `--%s` (with two dashes ?)" , arg); +error (_ ("did you mean `--%s` (with two dashes ?)" ), arg);exit (129 ); } }
@@ -644,11 +644,11 @@ int parse_options(int argc, const char **argv, const char *prefix,break ;default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) { -error ("unknown option `%s'" , ctx.argv[0 ] +2 ); +error (_ ("unknown option `%s'" ), ctx.argv[0 ] +2 ); }else if (isascii (*ctx.opt)) { -error ("unknown switch `%c'" , *ctx.opt); +error (_ ("unknown switch `%c'" ), *ctx.opt); }else { -error ("unknown non-ascii option in string: `%s'" , +error (_ ("unknown non-ascii option in string: `%s'" ), ctx.argv[0 ]); }usage_with_options (usagestr, options);
t/t0040-parse-options.sh +2 -2
@@ -228,7 +228,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -boolean >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' cat >typo.err <<\EOF
@@ -238,7 +238,7 @@ EOF test_expect_success 'detect possible typos' ' test_must_fail test-tool parse-options -ambiguous >output 2>output.err && test_must_be_empty output && - test_cmp typo.err output.err + test_i18ncmp typo.err output.err ' test_expect_success 'keep some options as arguments' '
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 15/16 fsck: reduce word legos to help i18n
In reply to Nguyễn Thái Ngọc DuyThese messages will be marked for translation later. Reduce word legos and give translators almost full phrases. describe_object() is updated so that it can be called from printf() twice.
While at there, remove \n from the strings to reduce a bit of work from translators.
--- builtin/fsck.c | 65 +++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 25 deletions(-)
builtin/fsck.c +40 -25
@@ -52,16 +52,24 @@ static int name_objects;static const char *describe_object (struct object *obj) { -static struct strbuf buf =STRBUF_INIT ; -char *name = name_objects ? -lookup_decoration (fsck_walk_options.object_names, obj) :NULL ; +static struct strbuf bufs[] = { +STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT + }; +static int b =0 ; +struct strbuf *buf; +char *name =NULL ; -strbuf_reset (&buf); -strbuf_addstr (&buf,oid_to_hex (&obj->oid)); +if (name_objects) + name =lookup_decoration (fsck_walk_options.object_names, obj); + + buf = bufs + b; + b = (b +1 ) %ARRAY_SIZE (bufs); +strbuf_reset (buf); +strbuf_addstr (buf,oid_to_hex (&obj->oid));if (name) -strbuf_addf (&buf," (%s)" , name); +strbuf_addf (buf," (%s)" , name); -return buf.buf; +return buf->buf; }static const char *printable_type (struct object *obj)
@@ -105,25 +113,29 @@ static int fsck_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } -static void objreport (struct object *obj,const char *msg_type, -const char *err) -{ -fprintf (stderr,"%s in %s %s: %s\n" , - msg_type,printable_type (obj),describe_object (obj), err); -} -static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err); +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), err);return -1 ; }static int fsck_error_func (struct fsck_options *o,struct object *obj,int type,const char *message) { -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message); -return (type ==FSCK_WARN ) ?0 :1 ; +switch (type) { +case FSCK_WARN : +fprintf_ln (stderr,"warning in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 0 ; +case FSCK_ERROR : +fprintf_ln (stderr,"error in %s %s: %s" , +printable_type (obj),describe_object (obj), message); +return 1 ; +default : +BUG ("%d (FSCK_IGNORE?) should never trigger this callback" , type); + } }static struct object_array pending;
@@ -165,10 +177,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_optif (!(obj->flags &HAS_OBJ )) {if (parent && !has_object_file (&obj->oid)) { -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf (" to %7s %s\n" , -printable_type (obj),describe_object (obj)); +printf_ln ("broken link from %7s %s\n" +" to %7s %s" , +printable_type (parent), +describe_object (parent), +printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ; }return 1 ;
@@ -371,10 +385,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)struct tag *tag = (struct tag *) obj;if (show_tags && tag->tagged) { -printf ("tagged %s %s" ,printable_type (tag->tagged), -describe_object (tag->tagged)); -printf (" (%s) in %s\n" , tag->tag, -describe_object (&tag->object)); +printf_ln ("tagged %s %s (%s) in %s" , +printable_type (tag->tagged), +describe_object (tag->tagged), + tag->tag, +describe_object (&tag->object)); } }
Signature · 1 line
2.19.1.1231.g84aef82467
PATCH v3 16/16 fsck: mark strings for translation
In reply to Nguyễn Thái Ngọc DuyTwo die() are updated to start with lowercase to be consistent with the rest.
--- builtin/fsck.c | 106 ++++++++++++++++++++----------------- t/t1410-reflog.sh | 6 +-- t/t1450-fsck.sh | 50 ++++++++--------- t/t6050-replace.sh | 4 +- t/t7415-submodule-names.sh | 6 +-- 5 files changed, 90 insertions(+), 82 deletions(-)
builtin/fsck.c +57 -49
@@ -85,7 +85,7 @@ static const char *printable_type(struct object *obj) ret =type_name (obj->type);if (!ret) - ret ="unknown" ; + ret =_ ("unknown" );return ret; }
@@ -116,7 +116,8 @@ static int fsck_config(const char *var, const char *value, void *cb)static int objerror (struct object *obj,const char *err) { errors_found |=ERROR_OBJECT ; -fprintf_ln (stderr,"error in %s %s: %s" , +/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ +fprintf_ln (stderr,_ ("error in %s %s: %s" ),printable_type (obj),describe_object (obj), err);return -1 ; }
@@ -126,11 +127,13 @@ static int fsck_error_func(struct fsck_options *o, {switch (type) {case FSCK_WARN : -fprintf_ln (stderr,"warning in %s %s: %s" , +/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */ +fprintf_ln (stderr,_ ("warning in %s %s: %s" ),printable_type (obj),describe_object (obj), message);return 0 ;case FSCK_ERROR : -fprintf_ln (stderr,"error in %s %s: %s" , +/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ +fprintf_ln (stderr,_ ("error in %s %s: %s" ),printable_type (obj),describe_object (obj), message);return 1 ;default :
@@ -151,17 +154,18 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt*/ if (!obj) {/* ... these references to parent->fld are safe here */ -printf ("broken link from %7s %s\n" , -printable_type (parent),describe_object (parent)); -printf ("broken link from %7s %s\n" , - (type ==OBJ_ANY ?"unknown" :type_name (type)),"unknown" ); +printf_ln (_ ("broken link from %7s %s" ), +printable_type (parent),describe_object (parent)); +printf_ln (_ ("broken link from %7s %s" ), + (type ==OBJ_ANY ?_ ("unknown" ) :type_name (type)), +_ ("unknown" )); errors_found |=ERROR_REACHABLE ;return 1 ; }if (type !=OBJ_ANY && obj->type != type)/* ... and the reference to parent is safe here */ -objerror (parent,"wrong object type in link" ); +objerror (parent,_ ("wrong object type in link" ));if (obj->flags &REACHABLE )return 0 ;
@@ -177,8 +181,8 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_optif (!(obj->flags &HAS_OBJ )) {if (parent && !has_object_file (&obj->oid)) { - printf_ln("broken link from %7s %s\n" - " to %7s %s", + printf_ln(_("broken link from %7s %s\n" + " to %7s %s"), printable_type(parent), describe_object(parent), printable_type(obj),
@@ -246,8 +250,8 @@ static void check_reachable_object(struct object *obj)return ;if (has_object_pack (&obj->oid))return ;/* it is in pack - forget about it */ -printf ("missing %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("missing %s %s" ),printable_type (obj), +describe_object (obj)); errors_found |=ERROR_REACHABLE ;return ; }
@@ -272,8 +276,8 @@ static void check_unreachable_object(struct object *obj)* since this is something that is prunable. */ if (show_unreachable) { -printf ("unreachable %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("unreachable %s %s" ),printable_type (obj), +describe_object (obj));return ; }
@@ -291,8 +295,8 @@ static void check_unreachable_object(struct object *obj)*/ if (!(obj->flags &USED )) {if (show_dangling) -printf ("dangling %s %s\n" ,printable_type (obj), -describe_object (obj)); +printf_ln (_ ("dangling %s %s" ),printable_type (obj), +describe_object (obj));if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other",
@@ -300,18 +304,18 @@ static void check_unreachable_object(struct object *obj)FILE *f;if (safe_create_leading_directories_const (filename)) { -error ("Could not create lost-found" ); +error (_ ("could not create lost-found" ));free (filename);return ; } f =xfopen (filename,"w" );if (obj->type ==OBJ_BLOB ) {if (stream_blob_to_fd (fileno (f), &obj->oid,NULL ,1 )) -die_errno ("Could not write '%s'" , filename); +die_errno (_ ("could not write '%s'" ), filename); }else fprintf (f,"%s\n" ,describe_object (obj));if (fclose (f)) -die_errno ("Could not finish '%s'" , +die_errno (_ ("could not finish '%s'" ), filename);free (filename); }
@@ -328,7 +332,7 @@ static void check_unreachable_object(struct object *obj)static void check_object (struct object *obj) {if (verbose) -fprintf (stderr,"Checking %s\n" ,describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s" ),describe_object (obj));if (obj->flags &REACHABLE )check_reachable_object (obj);
@@ -346,7 +350,7 @@ static void check_connectivity(void)/* Look up all the requirements, warn about missing objects.. */ max =get_max_object_index ();if (verbose) -fprintf (stderr,"Checking connectivity (%d objects)\n" , max); +fprintf_ln (stderr,_ ("Checking connectivity (%d objects)" ), max);for (i =0 ; i < max; i++) {struct object *obj =get_indexed_object (i);
@@ -365,11 +369,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) obj->flags |=SEEN ;if (verbose) -fprintf (stderr,"Checking %s %s\n" , -printable_type (obj),describe_object (obj)); +fprintf_ln (stderr,_ ("Checking %s %s" ), +printable_type (obj),describe_object (obj));if (fsck_walk (obj,NULL , &fsck_obj_options)) -objerror (obj,"broken links" ); +objerror (obj,_ ("broken links" )); err =fsck_object (obj, buffer, size, &fsck_obj_options);if (err) goto out;
@@ -378,14 +382,15 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)struct commit *commit = (struct commit *) obj;if (!commit->parents && show_root) -printf ("root %s\n" ,describe_object (&commit->object)); +printf_ln (_ ("root %s" ), +describe_object (&commit->object)); }if (obj->type ==OBJ_TAG ) {struct tag *tag = (struct tag *) obj;if (show_tags && tag->tagged) { - printf_ln("tagged %s %s (%s) in %s", + printf_ln(_("tagged %s %s (%s) in %s"), printable_type(tag->tagged), describe_object(tag->tagged), tag->tag,
@@ -413,7 +418,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, eaten);if (!obj) { errors_found |=ERROR_OBJECT ; -return error ("%s: object corrupt or missing" ,oid_to_hex (oid)); +return error (_ ("%s: object corrupt or missing" ), +oid_to_hex (oid)); } obj->flags &= ~(REACHABLE |SEEN ); obj->flags |=HAS_OBJ ;
@@ -437,7 +443,8 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, obj->flags |=USED ;mark_object_reachable (obj); }else if (!is_promisor_object (oid)) { -error ("%s: invalid reflog entry %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid reflog entry %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ; } }
@@ -450,8 +457,8 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noidconst char *refname = cb_data;if (verbose) -fprintf (stderr,"Checking reflog %s->%s\n" , -oid_to_hex (ooid),oid_to_hex (noid)); +fprintf_ln (stderr,_ ("Checking reflog %s->%s" ), +oid_to_hex (ooid),oid_to_hex (noid));fsck_handle_reflog_oid (refname, ooid,0 );fsck_handle_reflog_oid (refname, noid, timestamp);
@@ -480,13 +487,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, default_refs++;return 0 ; } -error ("%s: invalid sha1 pointer %s" , refname,oid_to_hex (oid)); +error (_ ("%s: invalid sha1 pointer %s" ), + refname,oid_to_hex (oid)); errors_found |=ERROR_REACHABLE ;/* We'll continue with the rest despite the error.. */ return 0 ; }if (obj->type !=OBJ_COMMIT &&is_branch (refname)) { -error ("%s: not a commit" , refname); +error (_ ("%s: not a commit" ), refname); errors_found |=ERROR_REFS ; } default_refs++;
@@ -520,7 +528,7 @@ static void get_default_heads(void)* "show_unreachable" flag. */ if (!default_refs) { -fprintf (stderr,"notice: No default references\n" ); +fprintf_ln (stderr,_ ("notice: No default references" )); show_unreachable =0 ; } }
@@ -535,7 +543,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (read_loose_object (path, oid, &type, &size, &contents) <0 ) { errors_found |=ERROR_OBJECT ; -error ("%s: object corrupt or missing: %s" , +error (_ ("%s: object corrupt or missing: %s" ),oid_to_hex (oid), path);return 0 ;/* keep checking other objects */ }
@@ -548,7 +556,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)if (!obj) { errors_found |=ERROR_OBJECT ; -error ("%s: object could not be parsed: %s" , +error (_ ("%s: object could not be parsed: %s" ),oid_to_hex (oid), path);if (!eaten)free (contents);
@@ -568,7 +576,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)static int fsck_cruft (const char *basename,const char *path,void *data) {if (!starts_with (basename,"tmp_obj_" )) -fprintf (stderr,"bad sha1 file: %s\n" , path); +fprintf_ln (stderr,_ ("bad sha1 file: %s" ), path);return 0 ; }
@@ -583,7 +591,7 @@ static void fsck_object_dir(const char *path)struct progress *progress =NULL ;if (verbose) -fprintf (stderr,"Checking object directory\n" ); +fprintf_ln (stderr,_ ("Checking object directory" ));if (show_progress) progress =start_progress (_ ("Checking object directories" ),256 );
@@ -599,28 +607,28 @@ static int fsck_head_link(void)int null_is_error =0 ;if (verbose) -fprintf (stderr,"Checking HEAD link\n" ); +fprintf_ln (stderr,_ ("Checking HEAD link" )); head_points_at =resolve_ref_unsafe ("HEAD" ,0 , &head_oid,NULL );if (!head_points_at) { errors_found |=ERROR_REFS ; -return error ("Invalid HEAD" ); +return error (_ ("invalid HEAD" )); }if (!strcmp (head_points_at,"HEAD" ))/* detached HEAD */ null_is_error =1 ;else if (!starts_with (head_points_at,"refs/heads/" )) { errors_found |=ERROR_REFS ; -return error ("HEAD points to something strange (%s)" , +return error (_ ("HEAD points to something strange (%s)" ), head_points_at); }if (is_null_oid (&head_oid)) {if (null_is_error) { errors_found |=ERROR_REFS ; -return error ("HEAD: detached HEAD points at nothing" ); +return error (_ ("HEAD: detached HEAD points at nothing" )); } -fprintf (stderr,"notice: HEAD points to an unborn branch (%s)\n" , - head_points_at +11 ); +fprintf_ln (stderr,_ ("notice: HEAD points to an unborn branch (%s)" ), + head_points_at +11 ); }return 0 ; }
@@ -631,12 +639,12 @@ static int fsck_cache_tree(struct cache_tree *it)int err =0 ;if (verbose) -fprintf (stderr,"Checking cache tree\n" ); +fprintf_ln (stderr,_ ("Checking cache tree" ));if (0 <= it->entry_count) {struct object *obj =parse_object (the_repository, &it->oid);if (!obj) { -error ("%s: invalid sha1 pointer in cache-tree" , +error (_ ("%s: invalid sha1 pointer in cache-tree" ),oid_to_hex (&it->oid)); errors_found |=ERROR_REFS ;return 1 ;
@@ -647,7 +655,7 @@ static int fsck_cache_tree(struct cache_tree *it) obj, xstrdup(":"));mark_object_reachable (obj);if (obj->type !=OBJ_TREE ) - err |=objerror (obj,"non-tree in cache-tree" ); + err |=objerror (obj,_ ("non-tree in cache-tree" )); }for (i =0 ; i < it->subtree_nr; i++) err |=fsck_cache_tree (it->down[i]->cache_tree);
@@ -789,7 +797,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (!obj || !(obj->flags &HAS_OBJ )) {if (is_promisor_object (&oid))continue ; -error ("%s: object missing" ,oid_to_hex (&oid)); +error (_ ("%s: object missing" ),oid_to_hex (&oid)); errors_found |=ERROR_OBJECT ;continue ; }
@@ -801,7 +809,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)mark_object_reachable (obj);continue ; } -error ("invalid parameter: expected sha1, got '%s'" , arg); +error (_ ("invalid parameter: expected sha1, got '%s'" ), arg); errors_found |=ERROR_OBJECT ; }
t/t1410-reflog.sh +3 -3
@@ -20,12 +20,12 @@ check_have () { } check_fsck () { - output=$(git fsck --full) + git fsck --full >fsck.output case "$1" in '') - test -z "$output" ;; + test_must_be_empty fsck.output ;; *) - echo "$output" | grep "$1" ;; + test_i18ngrep "$1" fsck.output ;; esac }
t/t1450-fsck.sh +25 -25
189 lines not on this page · raw message
t/t6050-replace.sh +2 -2
@@ -133,8 +133,8 @@ test_expect_success 'tag replaced commit' ' test_expect_success '"git fsck" works' ' git fsck master >fsck_master.out && - grep "dangling commit $R" fsck_master.out && - grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + test_i18ngrep "dangling commit $R" fsck_master.out && + test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" '
t/t7415-submodule-names.sh +3 -3
@@ -154,7 +154,7 @@ test_expect_success 'fsck detects symlinked .gitmodules file' ' # symlink detector; this grep string comes from the config # variable name and will not be translated. test_must_fail git fsck 2>output && - grep gitmodulesSymlink output + test_i18ngrep gitmodulesSymlink output ) '
@@ -172,7 +172,7 @@ test_expect_success 'fsck detects non-blob .gitmodules' ' git ls-tree HEAD | sed s/subdir/.gitmodules/ | git mktree && test_must_fail git fsck 2>output && - grep gitmodulesBlob output + test_i18ngrep gitmodulesBlob output ) '
@@ -186,7 +186,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' ' git commit -m "broken gitmodules" && git fsck 2>output && - grep gitmodulesParse output && + test_i18ngrep gitmodulesParse output && test_i18ngrep ! "bad config" output ) '
Signature · 1 line
2.19.1.1231.g84aef82467