From: Junio C Hamano Date: Fri, 21 May 2010 11:02:14 +0000 (-0700) Subject: Merge branch 'ar/config-from-command-line' X-Git-Tag: v1.7.2-rc0~130 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7f3ed824a4ec15fc9725a4992b399ea4364c5adb?hp=-c Merge branch 'ar/config-from-command-line' * ar/config-from-command-line: Complete prototype of git_config_from_parameters() Use strbufs instead of open-coded string manipulation Allow passing of configuration parameters in the command line --- 7f3ed824a4ec15fc9725a4992b399ea4364c5adb diff --combined Documentation/git.txt index c4024d0edd,755fa4d472..1a6ba87823 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@@ -12,6 -12,7 +12,7 @@@ SYNOPSI 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] + [-c name=value] [--help] COMMAND [ARGS] DESCRIPTION @@@ -43,18 -44,9 +44,18 @@@ unreleased) version of git, that is ava branch of the `git.git` repository. Documentation for older releases are available here: -* link:v1.7.0.2/git.html[documentation for release 1.7.0.2] +* link:v1.7.1/git.html[documentation for release 1.7.1] * release notes for + link:RelNotes-1.7.1.txt[1.7.1]. + +* link:v1.7.0.6/git.html[documentation for release 1.7.0.6] + +* release notes for + link:RelNotes-1.7.0.6.txt[1.7.0.6], + link:RelNotes-1.7.0.5.txt[1.7.0.5], + link:RelNotes-1.7.0.4.txt[1.7.0.4], + link:RelNotes-1.7.0.3.txt[1.7.0.3], link:RelNotes-1.7.0.2.txt[1.7.0.2], link:RelNotes-1.7.0.1.txt[1.7.0.1], link:RelNotes-1.7.0.txt[1.7.0]. @@@ -228,6 -220,12 +229,12 @@@ displayed. See linkgit:git-help[1] for because `git --help ...` is converted internally into `git help ...`. + -c =:: + Pass a configuration parameter to the command. The value + given will override values from configuration files. + The is expected in the same format as listed by + 'git config' (subkeys separated by dots). + --exec-path:: Path to wherever your core git programs are installed. This can also be controlled by setting the GIT_EXEC_PATH diff --combined cache.h index 0f4263c09a,73f0f7b098..8270390c88 --- a/cache.h +++ b/cache.h @@@ -387,9 -387,6 +387,9 @@@ static inline enum object_type object_t #define ATTRIBUTE_MACRO_PREFIX "[attr]" #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" #define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE" /* * Repository-local GIT_* environment variables @@@ -701,7 -698,7 +701,7 @@@ static inline void *read_sha1_file(cons return read_sha1_file_repl(sha1, type, size, NULL); } extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1); -extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); +extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int force_object_loose(const unsigned char *sha1, time_t mtime); @@@ -718,8 -715,6 +718,8 @@@ extern int has_loose_object_nonlocal(co extern int has_pack_index(const unsigned char *sha1); +extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect); + extern const signed char hexval_table[256]; static inline unsigned int hexval(unsigned char c) { @@@ -896,7 -891,6 +896,7 @@@ struct ref extern struct ref *find_ref_by_name(const struct ref *list, const char *name); #define CONNECT_VERBOSE (1u << 0) +extern char *git_getpass(const char *prompt); extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); extern int finish_connect(struct child_process *conn); extern int path_match(const char *path, int nr, char **match); @@@ -938,13 -932,14 +938,15 @@@ extern int update_server_info(int) typedef int (*config_fn_t)(const char *, const char *, void *); extern int git_default_config(const char *, const char *, void *); extern int git_config_from_file(config_fn_t fn, const char *, void *); + extern int git_config_parse_parameter(const char *text); + extern int git_config_from_parameters(config_fn_t fn, void *data); extern int git_config(config_fn_t fn, void *); extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); extern unsigned long git_config_ulong(const char *, const char *); extern int git_config_bool_or_int(const char *, const char *, int *); extern int git_config_bool(const char *, const char *); +extern int git_config_maybe_bool(const char *, const char *); extern int git_config_string(const char **, const char *, const char *); extern int git_config_pathname(const char **, const char *, const char *); extern int git_config_set(const char *, const char *); @@@ -1043,7 -1038,6 +1045,7 @@@ void shift_tree_by(const unsigned char #define WS_INDENT_WITH_NON_TAB 04 #define WS_CR_AT_EOL 010 #define WS_BLANK_AT_EOF 020 +#define WS_TAB_IN_INDENT 040 #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB) extern unsigned whitespace_rule_cfg; @@@ -1052,7 -1046,7 +1054,7 @@@ extern unsigned parse_whitespace_rule(c extern unsigned ws_check(const char *line, int len, unsigned ws_rule); extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); extern char *whitespace_error_string(unsigned ws); -extern int ws_fix_copy(char *, const char *, int, unsigned, int *); +extern void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *); extern int ws_blank_line(const char *line, int len, unsigned ws_rule); /* ls-files */ @@@ -1062,7 -1056,4 +1064,7 @@@ void overlay_tree_on_cache(const char * char *alias_lookup(const char *alias); int split_cmdline(char *cmdline, const char ***argv); +/* builtin/merge.c */ +int checkout_fast_forward(const unsigned char *from, const unsigned char *to); + #endif /* CACHE_H */ diff --combined config.c index 64e41bea22,7df9664903..aab53298a1 --- a/config.c +++ b/config.c @@@ -7,6 -7,7 +7,7 @@@ */ #include "cache.h" #include "exec_cmd.h" + #include "strbuf.h" #define MAXNAME (256) @@@ -18,6 -19,48 +19,48 @@@ static int zlib_compression_seen const char *config_exclusive_filename = NULL; + struct config_item + { + struct config_item *next; + char *name; + char *value; + }; + static struct config_item *config_parameters; + static struct config_item **config_parameters_tail = &config_parameters; + + static void lowercase(char *p) + { + for (; *p; p++) + *p = tolower(*p); + } + + int git_config_parse_parameter(const char *text) + { + struct config_item *ct; + struct strbuf tmp = STRBUF_INIT; + struct strbuf **pair; + strbuf_addstr(&tmp, text); + pair = strbuf_split(&tmp, '='); + if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') + strbuf_setlen(pair[0], pair[0]->len - 1); + strbuf_trim(pair[0]); + if (!pair[0]->len) { + strbuf_list_free(pair); + return -1; + } + ct = xcalloc(1, sizeof(struct config_item)); + ct->name = strbuf_detach(pair[0], NULL); + if (pair[1]) { + strbuf_trim(pair[1]); + ct->value = strbuf_detach(pair[1], NULL); + } + strbuf_list_free(pair); + lowercase(ct->name); + *config_parameters_tail = ct; + config_parameters_tail = &ct->next; + return 0; + } + static int get_next_char(void) { int c; @@@ -322,30 -365,17 +365,30 @@@ unsigned long git_config_ulong(const ch return ret; } -int git_config_bool_or_int(const char *name, const char *value, int *is_bool) +int git_config_maybe_bool(const char *name, const char *value) { - *is_bool = 1; if (!value) return 1; if (!*value) return 0; - if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on")) + if (!strcasecmp(value, "true") + || !strcasecmp(value, "yes") + || !strcasecmp(value, "on")) return 1; - if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off")) + if (!strcasecmp(value, "false") + || !strcasecmp(value, "no") + || !strcasecmp(value, "off")) return 0; + return -1; +} + +int git_config_bool_or_int(const char *name, const char *value, int *is_bool) +{ + int v = git_config_maybe_bool(name, value); + if (0 <= v) { + *is_bool = 1; + return v; + } *is_bool = 0; return git_config_int(name, value); } @@@ -712,6 -742,15 +755,15 @@@ int git_config_global(void return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0); } + int git_config_from_parameters(config_fn_t fn, void *data) + { + const struct config_item *ct; + for (ct = config_parameters; ct; ct = ct->next) + if (fn(ct->name, ct->value, data) < 0) + return -1; + return 0; + } + int git_config(config_fn_t fn, void *data) { int ret = 0, found = 0; @@@ -743,6 -782,12 +795,12 @@@ found += 1; } free(repo_config); + + if (config_parameters) { + ret += git_config_from_parameters(fn, data); + found += 1; + } + if (found == 0) return -1; return ret;