Add IO-wrappers for filenames encoding <local encoding> <-> UTF-8
PATCH v2 1/3 Add IO-wrappers for filenames encoding <local encoding> <-> UTF-8
The point is to make Git aware of filenames local encoding and make it keep all filenames in UTF-8 internally. If `i18n.filenameslocalencoding' option was set via git-config to a correct <codepage> encoding, 2 things should be done:
1. Translate all filenames read by READDIR from <codepage> into UTF-8.
2. Translate all filenames passed to IO-routines from UTF-8 into <codepage>.
This patch provides:
1. Routines for reencoding filenames from local encoding into UTF-8 and back (taking `i18n.filenameslocalencoding' into consideration).
2. I18N-wrappers around OPENDIR, READDIR, OPEN, FOPEN, STAT, LSTAT, CHMOD, LINK AND UNLINK.
3. Makes git-config' support i18n.filenameslocalencoding' option.
--- Makefile | 2 + cache.h | 1 + config.c | 3 + environment.c | 1 + io-i18n.c | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ io-i18n.h | 33 ++++++++ 6 files changed, 271 insertions(+), 0 deletions(-) create mode 100644 io-i18n.c create mode 100644 io-i18n.h
Makefile +2 -0
@@ -459,6 +459,7 @@ LIB_H += tree-walk.h LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h +LIB_H += io-i18n.h LIB_H += wt-status.h LIB_OBJS += abspath.o
@@ -562,6 +563,7 @@ LIB_OBJS += unpack-trees.o LIB_OBJS += usage.o LIB_OBJS += userdiff.o LIB_OBJS += utf8.o +LIB_OBJS += io-i18n.o LIB_OBJS += walker.o LIB_OBJS += wrapper.o LIB_OBJS += write_or_die.o
cache.h +1 -0
@@ -919,6 +919,7 @@ extern int user_ident_explicitly_given;extern const char *git_commit_encoding;extern const char *git_log_output_encoding; +extern const char *git_filenames_local_encoding;extern const char *git_mailmap_file;/* IO helper functions */
config.c +3 -0
@@ -539,6 +539,9 @@ static int git_default_i18n_config(const char *var, const char *value)if (!strcmp (var,"i18n.logoutputencoding" ))return git_config_string (&git_log_output_encoding, var, value); +if (!strcmp (var,"i18n.filenameslocalencoding" )) +return git_config_string (&git_filenames_local_encoding, var, value); +/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
environment.c +1 -0
@@ -24,6 +24,7 @@ int warn_ambiguous_refs = 1;int repository_format_version;const char *git_commit_encoding;const char *git_log_output_encoding; +const char *git_filenames_local_encoding;int shared_repository =PERM_UMASK ;const char *apply_default_whitespace;const char *apply_default_ignorewhitespace;
io-i18n.c new file +231 -0
231 lines not on this page · raw message
io-i18n.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef GIT_IO_I18N_H +#define GIT_IO_I18N_H + +#define _FILE_OFFSET_BITS 64 + +#include <sys/stat.h> +#include <dirent.h> +#include <stdio.h> +#include <unistd.h> + +char *filename_to_local (const char * filename); +char *filename_to_utf8 (const char *filename); +int stat_i18n (const char *filename,struct stat *buf); +int lstat_i18n (const char *filename,struct stat *buf); +DIR *opendir_i18n (const char *dirname); +struct dirent *readdir_i18n (DIR *dirstream); +int open_i18n (const char *filename,int flags, ...); +FILE *fopen_i18n (const char *filename,const char *opentype); +int chmod_i18n (const char *filename,mode_t mode); +int link_i18n (const char *oldname,const char *newname); +int unlink_i18n (const char *filename); + +#define opendir (a) opendir_i18n(a) +#define fopen (a, b) fopen_i18n(a, b) +#define chmod (a, b) chmod_i18n(a, b) +#define open open_i18n +#define stat (a, b) stat_i18n(a, b) +#define lstat (a, b) lstat_i18n(a, b) +#define readdir (a) readdir_i18n(a) +#define unlink (a) unlink_i18n(a) +#define link (a, b) link_i18n(a, b) + +#endif /* GIT_IO_I18N_H */
Signature · 1 line
1.6.5.1
PATCH v2 2/3 Use I18N-wrappers everywhere in Git
--- abspath.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin-add.c | 1 + builtin-apply.c | 1 + builtin-archive.c | 1 + builtin-blame.c | 1 + builtin-clean.c | 1 + builtin-clone.c | 1 + builtin-commit.c | 1 + builtin-count-objects.c | 1 + builtin-diff.c | 1 + builtin-fast-export.c | 1 + builtin-fetch--tool.c | 1 + builtin-fetch-pack.c | 1 + builtin-fetch.c | 1 + builtin-fmt-merge-msg.c | 1 + builtin-fsck.c | 1 + builtin-gc.c | 1 + builtin-grep.c | 1 + builtin-help.c | 1 + builtin-init-db.c | 1 + builtin-ls-files.c | 1 + builtin-mailinfo.c | 1 + builtin-mailsplit.c | 1 + builtin-merge-file.c | 1 + builtin-merge.c | 1 + builtin-mv.c | 1 + builtin-pack-objects.c | 1 + builtin-prune-packed.c | 1 + builtin-prune.c | 1 + builtin-reflog.c | 1 + builtin-remote.c | 1 + builtin-rerere.c | 1 + builtin-rm.c | 1 + builtin-tag.c | 1 + builtin-update-index.c | 1 + builtin-verify-tag.c | 1 + bundle.c | 1 + check-racy.c | 1 + combine-diff.c | 1 + commit.c | 1 + config.c | 1 + copy.c | 1 + daemon.c | 1 + diff-lib.c | 1 + diff-no-index.c | 1 + diff.c | 1 + diffcore-order.c | 1 + dir.c | 1 + entry.c | 1 + fast-import.c | 1 + hash-object.c | 1 + help.c | 1 + http.c | 1 + index-pack.c | 1 + ll-merge.c | 1 + lockfile.c | 1 + mailmap.c | 1 + merge-recursive.c | 1 + pack-write.c | 1 + path.c | 1 + preload-index.c | 1 + read-cache.c | 1 + refs.c | 1 + remote.c | 1 + rerere.c | 1 + server-info.c | 1 + setup.c | 1 + sha1_file.c | 1 + sha1_name.c | 1 + shallow.c | 1 + strbuf.c | 1 + symlinks.c | 1 + test-chmtime.c | 1 + test-delta.c | 1 + trace.c | 1 + transport.c | 1 + unpack-trees.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 82 files changed, 82 insertions(+), 0 deletions(-)
abspath.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "io-i18n.h" /* * Do not use this for inspecting *tracked* content. When path is a
attr.c +1 -0
@@ -1,6 +1,7 @@#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "attr.h" +#include "io-i18n.h" const char git_attr__true[] ="(builtin)true" ;const char git_attr__false[] ="\0(builtin)false" ;
bisect.c +1 -0
@@ -9,6 +9,7 @@#include "run-command.h" #include "log-tree.h" #include "bisect.h" +#include "io-i18n.h" struct sha1_array {unsigned char (*sha1)[20 ];
branch.c +1 -0
@@ -3,6 +3,7 @@#include "refs.h" #include "remote.h" #include "commit.h" +#include "io-i18n.h" struct tracking {struct refspec spec;
builtin-add.c +1 -0
@@ -12,6 +12,7 @@#include "parse-options.h" #include "diff.h" #include "revision.h" +#include "io-i18n.h" static const char *const builtin_add_usage[] = {"git add [options] [--] <filepattern>..." ,
builtin-apply.c +1 -0
@@ -15,6 +15,7 @@#include "string-list.h" #include "dir.h" #include "parse-options.h" +#include "io-i18n.h" /* * --check turns on checking that the working tree matches the
builtin-archive.c +1 -0
@@ -8,6 +8,7 @@#include "parse-options.h" #include "pkt-line.h" #include "sideband.h" +#include "io-i18n.h" static void create_output_file (const char *output_file) {
builtin-blame.c +1 -0
@@ -20,6 +20,7 @@#include "mailmap.h" #include "parse-options.h" #include "utf8.h" +#include "io-i18n.h" static char blame_usage[] ="git blame [options] [rev-opts] [rev] [--] file" ;
builtin-clean.c +1 -0
@@ -11,6 +11,7 @@#include "dir.h" #include "parse-options.h" #include "quote.h" +#include "io-i18n.h" static int force =-1 ;/* unset */
builtin-clone.c +1 -0
@@ -23,6 +23,7 @@#include "branch.h" #include "remote.h" #include "run-command.h" +#include "io-i18n.h" /* * Overall FIXMEs:
builtin-commit.c +1 -0
@@ -24,6 +24,7 @@#include "string-list.h" #include "rerere.h" #include "unpack-trees.h" +#include "io-i18n.h" static const char *const builtin_commit_usage[] = {"git commit [options] [--] <filepattern>..." ,
builtin-count-objects.c +1 -0
@@ -8,6 +8,7 @@#include "dir.h" #include "builtin.h" #include "parse-options.h" +#include "io-i18n.h" static void count_objects(DIR *d, char *path, int len, int verbose, unsigned long *loose,
builtin-diff.c +1 -0
@@ -13,6 +13,7 @@#include "revision.h" #include "log-tree.h" #include "builtin.h" +#include "io-i18n.h" struct blobinfo {unsigned char sha1[20 ];
builtin-fast-export.c +1 -0
@@ -16,6 +16,7 @@#include "string-list.h" #include "utf8.h" #include "parse-options.h" +#include "io-i18n.h" static const char *fast_export_usage[] = {"git fast-export [rev-list-opts]" ,
builtin-fetch--tool.c +1 -0
@@ -3,6 +3,7 @@#include "refs.h" #include "commit.h" #include "sigchain.h" +#include "io-i18n.h" static char *get_stdin (void ) {
builtin-fetch-pack.c +1 -0
@@ -9,6 +9,7 @@#include "fetch-pack.h" #include "remote.h" #include "run-command.h" +#include "io-i18n.h" static int transfer_unpack_limit =-1 ;static int fetch_unpack_limit =-1 ;
builtin-fetch.c +1 -0
@@ -11,6 +11,7 @@#include "run-command.h" #include "parse-options.h" #include "sigchain.h" +#include "io-i18n.h" static const char *const builtin_fetch_usage[] = {"git fetch [options] [<repository> <refspec>...]" ,
builtin-fmt-merge-msg.c +1 -0
@@ -4,6 +4,7 @@#include "diff.h" #include "revision.h" #include "tag.h" +#include "io-i18n.h" static const char *const fmt_merge_msg_usage[] = {"git fmt-merge-msg [--log|--no-log] [--file <file>]" ,
builtin-fsck.c +1 -0
@@ -11,6 +11,7 @@#include "fsck.h" #include "parse-options.h" #include "dir.h" +#include "io-i18n.h" #define REACHABLE 0x0001#define SEEN 0x0002
builtin-gc.c +1 -0
@@ -14,6 +14,7 @@#include "cache.h" #include "parse-options.h" #include "run-command.h" +#include "io-i18n.h" #define FAILED_RUN "failed to run %s"
builtin-grep.c +1 -0
@@ -14,6 +14,7 @@#include "userdiff.h" #include "grep.h" #include "quote.h" +#include "io-i18n.h" #ifndef NO_EXTERNAL_GREP #ifdef __unix__
builtin-help.c +1 -0
@@ -10,6 +10,7 @@#include "parse-options.h" #include "run-command.h" #include "help.h" +#include "io-i18n.h" static struct man_viewer_list { struct man_viewer_list *next;
builtin-init-db.c +1 -0
@@ -7,6 +7,7 @@#include "builtin.h" #include "exec_cmd.h" #include "parse-options.h" +#include "io-i18n.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
builtin-ls-files.c +1 -0
@@ -11,6 +11,7 @@#include "builtin.h" #include "tree.h" #include "parse-options.h" +#include "io-i18n.h" static int abbrev;static int show_deleted;
builtin-mailinfo.c +1 -0
@@ -6,6 +6,7 @@#include "builtin.h" #include "utf8.h" #include "strbuf.h" +#include "io-i18n.h" static FILE *cmitmsg, *patchfile, *fin, *fout;
builtin-mailsplit.c +1 -0
@@ -8,6 +8,7 @@#include "builtin.h" #include "string-list.h" #include "strbuf.h" +#include "io-i18n.h" static const char git_mailsplit_usage[] ="git mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> [<mbox>|<Maildir>...]" ;
builtin-merge-file.c +1 -0
@@ -3,6 +3,7 @@#include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "parse-options.h" +#include "io-i18n.h" static const char *const merge_file_usage[] = {"git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2" ,
builtin-merge.c +1 -0
@@ -24,6 +24,7 @@#include "rerere.h" #include "help.h" #include "merge-recursive.h" +#include "io-i18n.h" #define DEFAULT_TWOHEAD (1<<0)#define DEFAULT_OCTOPUS (1<<1)
builtin-mv.c +1 -0
@@ -9,6 +9,7 @@#include "cache-tree.h" #include "string-list.h" #include "parse-options.h" +#include "io-i18n.h" static const char *const builtin_mv_usage[] = {"git mv [options] <source>... <destination>" ,
builtin-pack-objects.c +1 -0
@@ -16,6 +16,7 @@#include "list-objects.h" #include "progress.h" #include "refs.h" +#include "io-i18n.h" #ifdef THREADED_DELTA_SEARCH #include "thread-utils.h"
builtin-prune-packed.c +1 -0
@@ -2,6 +2,7 @@#include "cache.h" #include "progress.h" #include "parse-options.h" +#include "io-i18n.h" static const char *const prune_packed_usage[] = {"git prune-packed [-n|--dry-run] [-q|--quiet]" ,
builtin-prune.c +1 -0
@@ -6,6 +6,7 @@#include "reachable.h" #include "parse-options.h" #include "dir.h" +#include "io-i18n.h" static const char *const prune_usage[] = {"git prune [-n] [-v] [--expire <time>] [--] [<head>...]" ,
builtin-reflog.c +1 -0
@@ -7,6 +7,7 @@#include "diff.h" #include "revision.h" #include "reachable.h" +#include "io-i18n.h" /* * reflog expire
builtin-remote.c +1 -0
@@ -6,6 +6,7 @@#include "strbuf.h" #include "run-command.h" #include "refs.h" +#include "io-i18n.h" static const char *const builtin_remote_usage[] = {"git remote [-v | --verbose]" ,
builtin-rerere.c +1 -0
@@ -5,6 +5,7 @@#include "rerere.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" +#include "io-i18n.h" static const char git_rerere_usage[] ="git rerere [clear | status | diff | gc]" ;
builtin-rm.c +1 -0
@@ -9,6 +9,7 @@#include "cache-tree.h" #include "tree-walk.h" #include "parse-options.h" +#include "io-i18n.h" static const char *const builtin_rm_usage[] = {"git rm [options] [--] <file>..." ,
builtin-tag.c +1 -0
@@ -12,6 +12,7 @@#include "tag.h" #include "run-command.h" #include "parse-options.h" +#include "io-i18n.h" static const char *const git_tag_usage[] = {"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]" ,
builtin-update-index.c +1 -0
@@ -9,6 +9,7 @@#include "tree-walk.h" #include "builtin.h" #include "refs.h" +#include "io-i18n.h" /* * Default to not allowing changes to the list of files. The
builtin-verify-tag.c +1 -0
@@ -11,6 +11,7 @@#include "run-command.h" #include <signal.h> #include "parse-options.h" +#include "io-i18n.h" static const char *const verify_tag_usage[] = {"git verify-tag [-v|--verbose] <tag>..." ,
bundle.c +1 -0
@@ -7,6 +7,7 @@#include "list-objects.h" #include "run-command.h" #include "refs.h" +#include "io-i18n.h" static const char bundle_signature[] ="# v2 git bundle\n" ;
check-racy.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "io-i18n.h" int main (int ac,char **av) {
combine-diff.c +1 -0
@@ -7,6 +7,7 @@#include "xdiff-interface.h" #include "log-tree.h" #include "refs.h" +#include "io-i18n.h" static struct combine_diff_path *intersect_paths (struct combine_diff_path *curr,int n,int num_parent) {
commit.c +1 -0
@@ -5,6 +5,7 @@#include "utf8.h" #include "diff.h" #include "revision.h" +#include "io-i18n.h" int save_commit_buffer =1 ;
config.c +1 -0
@@ -7,6 +7,7 @@*/ #include "cache.h" #include "exec_cmd.h" +#include "io-i18n.h" #define MAXNAME (256)
copy.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "io-i18n.h" int copy_fd (int ifd,int ofd) {
daemon.c +1 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" +#include "io-i18n.h" #include <syslog.h>
diff-lib.c +1 -0
@@ -10,6 +10,7 @@#include "cache-tree.h" #include "unpack-trees.h" #include "refs.h" +#include "io-i18n.h" /* * diff-files
diff-no-index.c +1 -0
@@ -15,6 +15,7 @@#include "log-tree.h" #include "builtin.h" #include "string-list.h" +#include "io-i18n.h" static int read_directory (const char *path,struct string_list *list) {
diff.c +1 -0
@@ -13,6 +13,7 @@#include "utf8.h" #include "userdiff.h" #include "sigchain.h" +#include "io-i18n.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0
diffcore-order.c +1 -0
@@ -4,6 +4,7 @@#include "cache.h" #include "diff.h" #include "diffcore.h" +#include "io-i18n.h" static char **order;static int order_cnt;
dir.c +1 -0
@@ -8,6 +8,7 @@#include "cache.h" #include "dir.h" #include "refs.h" +#include "io-i18n.h" struct path_simplify {int len;
entry.c +1 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "blob.h" #include "dir.h" +#include "io-i18n.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
fast-import.c +1 -0
@@ -152,6 +152,7 @@ Format of STDIN stream:#include "csum-file.h" #include "quote.h" #include "exec_cmd.h" +#include "io-i18n.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
hash-object.c +1 -0
@@ -9,6 +9,7 @@#include "quote.h" #include "parse-options.h" #include "exec_cmd.h" +#include "io-i18n.h" static void hash_fd (int fd,const char *type,int write_object,const char *path) {
help.c +1 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "levenshtein.h" #include "help.h" +#include "io-i18n.h" /* most GUI terminals set COLUMNS (although some don't export it) */ static int term_columns (void )
http.c +1 -0
@@ -1,5 +1,6 @@#include "http.h" #include "pack.h" +#include "io-i18n.h" int data_received;int active_requests;
index-pack.c +1 -0
@@ -9,6 +9,7 @@#include "progress.h" #include "fsck.h" #include "exec_cmd.h" +#include "io-i18n.h" static const char index_pack_usage[] ="git index-pack [-v] [-o <index-file>] [{ ---keep | --keep=<msg> }] [--strict] { <pack-file> | --stdin [--fix-thin] [<pack-file>] }" ;
ll-merge.c +1 -0
@@ -9,6 +9,7 @@#include "xdiff-interface.h" #include "run-command.h" #include "ll-merge.h" +#include "io-i18n.h" struct ll_merge_driver ;
lockfile.c +1 -0
@@ -3,6 +3,7 @@*/ #include "cache.h" #include "sigchain.h" +#include "io-i18n.h" static struct lock_file *lock_file_list;static const char *alternate_index_output;
mailmap.c +1 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "string-list.h" #include "mailmap.h" +#include "io-i18n.h" #define DEBUG_MAILMAP 0#if DEBUG_MAILMAP
merge-recursive.c +1 -0
@@ -19,6 +19,7 @@#include "attr.h" #include "merge-recursive.h" #include "dir.h" +#include "io-i18n.h" static struct tree *shift_tree_object (struct tree *one,struct tree *two) {
pack-write.c +1 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "pack.h" #include "csum-file.h" +#include "io-i18n.h" uint32_t pack_idx_default_version =2 ;uint32_t pack_idx_off32_limit =0x7fffffff ;
path.c +1 -0
@@ -11,6 +11,7 @@* which is what it's designed for. */ #include "cache.h" +#include "io-i18n.h" static char bad_path[] ="/bad-path/" ;
preload-index.c +1 -0
@@ -2,6 +2,7 @@* Copyright (C) 2008 Linus Torvalds */ #include "cache.h" +#include "io-i18n.h" #ifdef NO_PTHREADS static void preload_index (struct index_state *index,const char **pathspec)
read-cache.c +1 -0
@@ -14,6 +14,7 @@#include "diffcore.h" #include "revision.h" #include "blob.h" +#include "io-i18n.h" /* Index extensions. *
refs.c +1 -0
@@ -3,6 +3,7 @@#include "object.h" #include "tag.h" #include "dir.h" +#include "io-i18n.h" /* ISSYMREF=01 and ISPACKED=02 are public interfaces */ #define REF_KNOWS_PEELED 04
remote.c +1 -0
@@ -6,6 +6,7 @@#include "revision.h" #include "dir.h" #include "tag.h" +#include "io-i18n.h" static struct refspec s_tag_refspec = {0 ,
rerere.c +1 -0
@@ -3,6 +3,7 @@#include "rerere.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" +#include "io-i18n.h" /* if rerere_enabled == -1, fall back to detection of .git/rr-cache */ static int rerere_enabled =-1 ;
server-info.c +1 -0
@@ -3,6 +3,7 @@#include "object.h" #include "commit.h" #include "tag.h" +#include "io-i18n.h" /* refs */ static FILE *info_ref_fp;
setup.c +1 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "dir.h" +#include "io-i18n.h" static int inside_git_dir =-1 ;static int inside_work_tree =-1 ;
sha1_file.c +1 -0
@@ -16,6 +16,7 @@#include "refs.h" #include "pack-revindex.h" #include "sha1-lookup.h" +#include "io-i18n.h" #ifndef O_NOATIME #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
sha1_name.c +1 -0
@@ -5,6 +5,7 @@#include "blob.h" #include "tree-walk.h" #include "refs.h" +#include "io-i18n.h" static int find_short_object_filename (int len,const char *name,unsigned char *sha1) {
shallow.c +1 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "commit.h" #include "tag.h" +#include "io-i18n.h" static int is_shallow =-1 ;
strbuf.c +1 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "refs.h" +#include "io-i18n.h" int prefixcmp (const char *str,const char *prefix) {
symlinks.c +1 -0
@@ -1,4 +1,5 @@#include "cache.h" +#include "io-i18n.h" /* * Returns the length (on a path component basis) of the longest
test-chmtime.c +1 -0
@@ -29,6 +29,7 @@*/ #include "git-compat-util.h" #include <utime.h> +#include "io-i18n.h" static const char usage_str[] ="-v|--verbose (+|=|=+|=-|-)<seconds> <file>..." ;
test-delta.c +1 -0
@@ -11,6 +11,7 @@#include "git-compat-util.h" #include "delta.h" #include "cache.h" +#include "io-i18n.h" static const char usage_str[] ="test-delta (-d|-p) <from_file> <data_file> <out_file>" ;
trace.c +1 -0
@@ -24,6 +24,7 @@#include "cache.h" #include "quote.h" +#include "io-i18n.h" /* Get a trace file descriptor from GIT_TRACE env variable. */ static int get_trace_fd (int *need_close)
transport.c +1 -0
@@ -8,6 +8,7 @@#include "bundle.h" #include "dir.h" #include "refs.h" +#include "io-i18n.h" /* rsync support */
unpack-trees.c +1 -0
@@ -8,6 +8,7 @@#include "progress.h" #include "refs.h" #include "attr.h" +#include "io-i18n.h" /* * Error messages expected by scripts out of plumbing commands such as
wrapper.c +1 -0
@@ -2,6 +2,7 @@* Various trivial helper wrappers around standard functions */ #include "cache.h" +#include "io-i18n.h" char *xstrdup (const char *str) {
xdiff-interface.c +1 -0
@@ -4,6 +4,7 @@#include "xdiff/xdiffi.h" #include "xdiff/xemit.h" #include "xdiff/xmacros.h" +#include "io-i18n.h" struct xdiff_emit_state {xdiff_emit_consume_fn consume;
Signature · 1 line
1.6.5.1
PATCH v2 3/3 Provide compatibility with MinGW
--- compat/fopen.c | 5 +++-- compat/mingw.c | 37 ++++++++++++++++++++++++++++--------- compat/mingw.h | 6 +++++- compat/mkstemps.c | 3 ++- compat/win32.h | 13 +++++++++++-- io-i18n.c | 5 +++++ io-i18n.h | 7 +++++++ 7 files changed, 61 insertions(+), 15 deletions(-)
compat/fopen.c +3 -2
@@ -10,6 +10,7 @@*/ #undef FREAD_READS_DIRECTORIES#include "../git-compat-util.h" +#include "io-i18n.h" FILE *git_fopen (const char *path,const char *mode) {
@@ -17,9 +18,9 @@ FILE *git_fopen(const char *path, const char *mode)struct stat st;if (mode[0 ] =='w' || mode[0 ] =='a' ) -return fopen (path, mode); +return fopen_i18n (path, mode); -if (!(fp =fopen (path, mode))) +if (!(fp =fopen_i18n (path, mode)))return NULL ;if (fstat (fileno (fp), &st)) {
compat/mingw.c +28 -9
@@ -2,7 +2,7 @@#include "win32.h" #include <conio.h> #include "../strbuf.h" - +#include "../io-i18n.h" #include <shellapi.h> static int err_win_to_posix (DWORD winerr)
@@ -132,7 +132,7 @@ int mingw_open (const char *filename, int oflags, ...)if (!strcmp (filename,"/dev/null" )) filename ="nul" ; - fd =open (filename, oflags, mode); + fd =open_i18n (filename, oflags, mode);if (fd <0 && (oflags &O_CREAT ) && errno ==EACCES ) {DWORD attrs =GetFileAttributes (filename);
@@ -253,7 +253,7 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)int fh, rc;/* must have write permission */ -if ((fh =open (file_name,O_RDWR |O_BINARY )) <0 ) +if ((fh =open_i18n (file_name,O_RDWR |O_BINARY )) <0 )return -1 ;time_t_to_filetime (times->modtime, &mft);
@@ -278,7 +278,7 @@ int mkstemp(char *template)char *filename =mktemp (template);if (filename ==NULL )return -1 ; -return open (filename,O_RDWR |O_CREAT ,0600 ); +return open_i18n (filename,O_RDWR |O_CREAT ,0600 ); }int gettimeofday (struct timeval *tv,void *tz)
@@ -519,7 +519,7 @@ static const char *parse_interpreter(const char *cmd)if (n >=4 && !strcasecmp (cmd+n-4 ,".exe" ))return NULL ; - fd =open (cmd,O_RDONLY ); + fd =open_i18n (cmd,O_RDONLY );if (fd <0 )return NULL ; n =read (fd, buf,sizeof (buf)-1 );
@@ -1135,10 +1135,14 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)static const char *make_backslash_path (const char *path) {static char buf[PATH_MAX +1 ]; +char *out =filename_to_local (path);char *c; -if (strlcpy (buf, path,PATH_MAX ) >=PATH_MAX ) -die ("Too long path: %.*s" ,60 , path); +if (strlcpy (buf, out ? out : path,PATH_MAX ) >=PATH_MAX ) { +die ("Too long path: %.*s" ,60 , out ? out : path); +free (out); + } +free (out);for (c = buf; *c; c++) {if (*c =='/' )
@@ -1158,6 +1162,9 @@ int link(const char *oldpath, const char *newpath) { typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES);static T create_hard_link =NULL ; +char *old_out =filename_to_local (oldpath); +char *new_out =filename_to_local (newpath); +if (!create_hard_link) { create_hard_link = (T )GetProcAddress (GetModuleHandle ("kernel32.dll" ),"CreateHardLinkA" );
@@ -1168,10 +1175,15 @@ int link(const char *oldpath, const char *newpath) errno =ENOSYS ;return -1 ; } -if (!create_hard_link (newpath, oldpath,NULL )) { +if (!create_hard_link (new_out ? new_out : newpath, + old_out ? old_out : oldpath,NULL )) { +free (new_out); +free (old_out); errno =err_win_to_posix (GetLastError ());return -1 ; } +free (new_out); +free (old_out);return 0 ; }
@@ -1206,6 +1218,7 @@ struct dirent *mingw_readdir(DIR *dir)WIN32_FIND_DATAA buf;HANDLE handle;struct mingw_DIR *mdir = (struct mingw_DIR *)dir; +char *out;if (!dir->dd_handle) { errno =EBADF ;/* No set_errno for mingw */
@@ -1236,7 +1249,13 @@ struct dirent *mingw_readdir(DIR *dir) }/* We get here if `buf' contains valid data. */ -strcpy (dir->dd_dir.d_name, buf.cFileName); + out =filename_to_utf8 (buf.cFileName); +if (strlcpy (dir->dd_dir.d_name, + out ? out : buf.cFileName,FILENAME_MAX ) >=FILENAME_MAX ) { +die ("Too long dir entry name: %.*s" ,60 , + out ? out : buf.cFileName); +free (out); + } ++dir->dd_stat;/* Set file type, based on WIN32_FIND_DATA */
compat/mingw.h +5 -1
@@ -1,4 +1,7 @@ +#ifndef GIT_MINGW_H +#define GIT_MINGW_H #include <winsock2.h> +#include "../io-i18n.h" /* * things that are not available in header files
@@ -112,7 +115,7 @@ static inline int mingw_unlink(const char *pathname) {/* read-only files cannot be removed */ chmod (pathname,0666 ); -return unlink (pathname); +return unlink_i18n (pathname); }#define unlink mingw_unlink
@@ -273,3 +276,4 @@ struct mingw_dirent#define readdir (x) mingw_readdir(x)struct dirent *mingw_readdir (DIR *dir);#endif // !NO_MINGW_REPLACE_READDIR +#endif // GIT_MINGW_H
compat/mkstemps.c +2 -1
@@ -1,4 +1,5 @@#include "../git-compat-util.h" +#include "../io-i18n.h" /* Adapted from libiberty's mkstemp.c. */
@@ -47,7 +48,7 @@ int gitmkstemps(char *pattern, int suffix_len) template[4 ] = letters[v % num_letters]; v /= num_letters; template[5 ] = letters[v % num_letters]; v /= num_letters; - fd =open (pattern,O_CREAT |O_EXCL |O_RDWR ,0600 ); + fd =open_i18n (pattern,O_CREAT |O_EXCL |O_RDWR ,0600 );if (fd >0 )return fd;/*
compat/win32.h +11 -2
@@ -20,8 +20,17 @@ static inline int file_attr_to_st_mode (DWORD attr)static inline int get_file_attr (const char *fname,WIN32_FILE_ATTRIBUTE_DATA *fdata) { -if (GetFileAttributesExA (fname, GetFileExInfoStandard, fdata)) -return 0 ; +char *out =filename_to_local (fname); +int ret; + +if ( out !=NULL ) { + ret =GetFileAttributesExA (out, GetFileExInfoStandard, fdata); +free (out); + }else + ret =GetFileAttributesExA (fname, GetFileExInfoStandard, fdata); + +if ( ret ) +return 0 ;switch (GetLastError ()) {case ERROR_ACCESS_DENIED :
io-i18n.c +5 -0
@@ -84,6 +84,7 @@ char *filename_to_local(const char *filename)#endif } +#ifndef __USE_MINGW_ACCESS#undef statint stat_i18n (const char *filename,struct stat *buf) {
@@ -127,6 +128,7 @@ int link_i18n(const char *oldname, const char *newname)free (new_out); return ret; } +#endif // __USE_MINGW_ACCESS #undef openint open_i18n (const char *filename,int flags, ...)
@@ -165,6 +167,8 @@ int unlink_i18n(const char *filename)return ret; } +#if !defined(__USE_MINGW_ACCESS) || \ + (defined(__USE_MINGW_ACCESS) && defined(NO_MINGW_REPLACE_READDIR ))#undef readdirstruct dirent *readdir_i18n (DIR * dirstream) {
@@ -187,6 +191,7 @@ struct dirent *readdir_i18n(DIR * dirstream) } elsereturn NULL ; } +#endif #undef opendirDIR *opendir_i18n (const char *dirname)
io-i18n.h +7 -0
@@ -23,11 +23,18 @@ int unlink_i18n(const char *filename);#define opendir (a) opendir_i18n(a)#define fopen (a, b) fopen_i18n(a, b)#define chmod (a, b) chmod_i18n(a, b) + +#ifndef __USE_MINGW_ACCESS#define open open_i18n#define stat (a, b) stat_i18n(a, b)#define lstat (a, b) lstat_i18n(a, b)#define readdir (a) readdir_i18n(a)#define unlink (a) unlink_i18n(a)#define link (a, b) link_i18n(a, b) +#endif // __USE_MINGW_ACCESS + +#if defined(__USE_MINGW_ACCESS) && defined(NO_MINGW_REPLACE_READDIR ) +#define readdir (a) readdir_i18n(a) +#endif #endif /* GIT_IO_I18N_H */
Signature · 1 line
1.6.5.1
Re: [PATCH I18N filenames v2 3/3] Provide compatibility with MinGW
Hi!
Timur Sufiev:
Quoted 14 lines
compat/mingw.c +1
-1@@ -2,7 +2,7 @@#include "win32.h" #include <conio.h> #include "../strbuf.h" - +#include "../io-i18n.h" #include <shellapi.h> static int err_win_to_posix (DWORD winerr)
compat/mingw.c int mingw_open (const char *filename, int oflags, ...) · line 138
Quoted 8 lines
compat/mingw.c +1
-1@@ -132,7 +132,7 @@ int mingw_open (const char *filename, int oflags, ...)if (!strcmp (filename,"/dev/null" )) filename ="nul" ; - fd =open (filename, oflags, mode); + fd =open_i18n (filename, oflags, mode);if (fd <0 && (oflags &O_CREAT ) && errno ==EACCES ) {DWORD attrs =GetFileAttributes (filename);
Instead of calling the open_i18n() which converts from UTF-8 to a local 8-bit character set, this should probably call a version that converts from UTF-8 to UTF-16 and uses _wopen().
Same thing for fopen_i18n() and _wfopen().
I created a small RFC patch for that that changed parts of the system earlier this year - http://kerneltrap.org/mailarchive/git/2009/3/2/5350814
I did not address readdir() and friends, I'm not sure if they are available in UTF-16 form or if they need to be rewritten using findfirst()/findnext().
Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
Re: [PATCH I18N filenames v2 2/3] Use I18N-wrappers everywhere in Git
In reply to Timur SufievQuoted 5 lines · Timur Sufiev
Signed-off-by Timur Sufiev <[email protected]>---
abspath.c | 1 +
attr.c | 1 +
bisect.c | 1 +
Instead of modifying all these files you could just have put that darn header in compat/mingw.h
io-i18n.h line 31
Quoted 9 lines · Timur Sufiev
io-i18n.h new file +9
-0+#define opendir (a) opendir_i18n(a) +#define fopen (a, b) fopen_i18n(a, b) +#define chmod (a, b) chmod_i18n(a, b) +#define open open_i18n +#define stat (a, b) stat_i18n(a, b) +#define lstat (a, b) lstat_i18n(a, b) +#define readdir (a) readdir_i18n(a) +#define unlink (a) unlink_i18n(a) +#define link (a, b) link_i18n(a, b)
I doubt that such a whole-sale replacement is necessary. For example, names of object files (in .git/objects/XX) need not be translated, nor ref names.
Please review the infrastructure patch that Linus provided (as pointed out by Jeff) and see how you can build on it. IIRC, there are a handful of central places where path names must be massaged, and perhaps a few others as fall-out.
Moreover, once you know what to change, it would be worthwhile to check how the file name translation can be adjusted to use the UTF16 versions of the functions on Windows to avoid the UTF8<->UTF16 conversion (that happens on Windows behind the scenes). Perhaps MacOS can profit from this, too.
-- Hannes