[PATCHv3] rebase -i: respect core.abbrev for real
I have tried to fix this before: see 568950388be2, but it doesn't really work. I don't know how it happend, but that commit makes interactive rebase to respect core.abbrev only during --edit-todo, but not the initial todo list edit. For this time I've included a test-case to avoid this frustration again. The patch change code to use full 40-hex revision ids for todo actions everywhere and collapse them only to show to user. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- v3: - use full 40-hex revision ids for todo actions everywhere and collapse them only to show to user; v2: - fix -chain in the test-case --- git-rebase--interactive.sh| 17 - t/t3404-rebase-interactive.sh | 7 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index c6a4629cbc2b..c96b9847e9fc 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -961,14 +961,13 @@ else revisions=$onto...$orig_head shortrevisions=$shorthead fi -git rev-list $merges_option --pretty=oneline --abbrev-commit \ - --abbrev=7 --reverse --left-right --topo-order \ +git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \ $revisions ${restrict_revision+^$restrict_revision} | \ sed -n s/^//p | -while read -r shortsha1 rest +while read -r sha1 rest do - if test -z $keep_empty is_empty_commit $shortsha1 ! is_merge_commit $shortsha1 + if test -z $keep_empty is_empty_commit $sha1 ! is_merge_commit $sha1 then comment_out=$comment_char else @@ -977,9 +976,8 @@ do if test t != $preserve_merges then - printf '%s\n' ${comment_out}pick $shortsha1 $rest $todo + printf '%s\n' ${comment_out}pick $sha1 $rest $todo else - sha1=$(git rev-parse $shortsha1) if test -z $rebase_root then preserve=t @@ -996,7 +994,7 @@ do if test f = $preserve then touch $rewritten/$sha1 - printf '%s\n' ${comment_out}pick $shortsha1 $rest $todo + printf '%s\n' ${comment_out}pick $sha1 $rest $todo fi fi done @@ -1020,8 +1018,8 @@ then # just the history of its first-parent for others that will # be rebasing on top of it git rev-list --parents -1 $rev | cut -d' ' -s -f2 $dropped/$rev - short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev) - sane_grep -v ^[a-z][a-z]* $short $todo ${todo}2 ; mv ${todo}2 $todo + sha1=$(git rev-list -1 $rev) + sane_grep -v ^[a-z][a-z]* $sha1 $todo ${todo}2 ; mv ${todo}2 $todo rm $rewritten/$rev fi done @@ -1054,6 +1052,7 @@ has_action $todo || return 2 cp $todo $todo.backup +collapse_todo_ids git_sequence_editor $todo || die_abort Could not execute editor diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 8197ed29a9ec..a31f7e0430e1 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1039,4 +1039,11 @@ test_expect_success 'short SHA-1 collide' ' ) ' +test_expect_success 'respect core.abbrev' ' + git config core.abbrev 12 + set_cat_todo_editor + test_must_fail git rebase -i HEAD~4 todo-list + test 4 = $(grep -c pick [0-9a-f]\{12,\} todo-list) +' + test_done -- 2.1.4 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCHv2] rebase -i: respect core.abbrev for real
I have tried to fix this before: see 568950388be2, but it doesn't really work. I don't know how it happend, but that commit makes interactive rebase to respect core.abbrev only during --edit-todo, but not the initial todo list edit. For this time I've included a test-case to avoid this frustration again. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- v2: fix -chain in the test-case --- git-rebase--interactive.sh| 4 ++-- t/t3404-rebase-interactive.sh | 7 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index c6a4629cbc2b..1855e12f1ada 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -962,7 +962,7 @@ else shortrevisions=$shorthead fi git rev-list $merges_option --pretty=oneline --abbrev-commit \ - --abbrev=7 --reverse --left-right --topo-order \ + --reverse --left-right --topo-order \ $revisions ${restrict_revision+^$restrict_revision} | \ sed -n s/^//p | while read -r shortsha1 rest @@ -1020,7 +1020,7 @@ then # just the history of its first-parent for others that will # be rebasing on top of it git rev-list --parents -1 $rev | cut -d' ' -s -f2 $dropped/$rev - short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev) + short=$(git rev-list -1 --abbrev-commit $rev) sane_grep -v ^[a-z][a-z]* $short $todo ${todo}2 ; mv ${todo}2 $todo rm $rewritten/$rev fi diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 8197ed29a9ec..a31f7e0430e1 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1039,4 +1039,11 @@ test_expect_success 'short SHA-1 collide' ' ) ' +test_expect_success 'respect core.abbrev' ' + git config core.abbrev 12 + set_cat_todo_editor + test_must_fail git rebase -i HEAD~4 todo-list + test 4 = $(grep -c pick [0-9a-f]\{12,\} todo-list) +' + test_done -- 2.1.4 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] rebase -i: respect core.abbrev for real
I have tried to fix this before: see 568950388be2, but it doesn't really work. I don't know how it happend, but that commit makes interactive rebase to respect core.abbrev only during --edit-todo, but not the initial todo list edit. For this time I've included a test-case to avoid this frustration again. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- git-rebase--interactive.sh| 4 ++-- t/t3404-rebase-interactive.sh | 7 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index c6a4629cbc2b..1855e12f1ada 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -962,7 +962,7 @@ else shortrevisions=$shorthead fi git rev-list $merges_option --pretty=oneline --abbrev-commit \ - --abbrev=7 --reverse --left-right --topo-order \ + --reverse --left-right --topo-order \ $revisions ${restrict_revision+^$restrict_revision} | \ sed -n s/^//p | while read -r shortsha1 rest @@ -1020,7 +1020,7 @@ then # just the history of its first-parent for others that will # be rebasing on top of it git rev-list --parents -1 $rev | cut -d' ' -s -f2 $dropped/$rev - short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev) + short=$(git rev-list -1 --abbrev-commit $rev) sane_grep -v ^[a-z][a-z]* $short $todo ${todo}2 ; mv ${todo}2 $todo rm $rewritten/$rev fi diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 8197ed29a9ec..a8ffc24ce46b 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1039,4 +1039,11 @@ test_expect_success 'short SHA-1 collide' ' ) ' +test_expect_success 'respect core.abbrev' ' + git config core.abbrev 12 + set_cat_todo_editor + test_must_fail git rebase -i HEAD~4 todo-list 21 + test 4 = $(grep -c pick [0-9a-f]\{12,\} todo-list) +' + test_done -- 2.1.4 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/4] config: teach git config --file - to read from the standard input
The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Include by absolute path is allowed in stdin config, but not by relative path. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 11 +++ cache.h | 1 + config.c | 41 +++-- t/t1300-repo-config.sh| 17 +++-- t/t1305-config-include.sh | 16 +++- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index de41ba50e9ca..5677c942b693 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -360,6 +360,9 @@ static int get_colorbool(int print) static void check_write(void) { + if (given_config_source.use_stdin) + die(writing to stdin is not supported); + if (given_config_source.blob) die(writing config blobs is not supported); } @@ -472,6 +475,12 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_with_options(builtin_config_usage, builtin_config_options); } + if (given_config_source.file + !strcmp(given_config_source.file, -)) { + given_config_source.file = NULL; + given_config_source.use_stdin = 1; + } + if (use_global_config) { char *user_config = NULL; char *xdg_config = NULL; @@ -558,6 +567,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 0, 0); if (!given_config_source.file nongit) die(not in a git directory); + if (given_config_source.use_stdin) + die(editing stdin is not supported); if (given_config_source.blob) die(editing blobs is not supported); git_config(git_default_config, NULL); diff --git a/cache.h b/cache.h index 9d94bd69f7db..4db19b537059 100644 --- a/cache.h +++ b/cache.h @@ -1147,6 +1147,7 @@ extern int update_server_info(int); #define CONFIG_GENERIC_ERROR 7 struct git_config_source { + unsigned int use_stdin:1; const char *file; const char *blob; }; diff --git a/config.c b/config.c index a21b0ddadecc..7b1febdf4af0 100644 --- a/config.c +++ b/config.c @@ -1031,24 +1031,35 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data) return ret; } -int git_config_from_file(config_fn_t fn, const char *filename, void *data) +static int do_config_from_file(config_fn_t fn, + const char *name, const char *path, FILE *f, void *data) { - int ret; - FILE *f = fopen(filename, r); + struct config_source top; - ret = -1; - if (f) { - struct config_source top; + top.u.file = f; + top.name = name; + top.path = path; + top.die_on_error = 1; + top.do_fgetc = config_file_fgetc; + top.do_ungetc = config_file_ungetc; + top.do_ftell = config_file_ftell; - top.u.file = f; - top.name = top.path = filename; - top.die_on_error = 1; - top.do_fgetc = config_file_fgetc; - top.do_ungetc = config_file_ungetc; - top.do_ftell = config_file_ftell; + return do_config_from(top, fn, data); +} - ret = do_config_from(top, fn, data); +static int git_config_from_stdin(config_fn_t fn, void *data) +{ + return do_config_from_file(fn, stdin, NULL, stdin, data); +} + +int git_config_from_file(config_fn_t fn, const char *filename, void *data) +{ + int ret = -1; + FILE *f; + f = fopen(filename, r); + if (f) { + ret = do_config_from_file(fn, filename, filename, f, data); fclose(f); } return ret; @@ -1190,7 +1201,9 @@ int git_config_with_options(config_fn_t fn, void *data, * If we have a specific filename, use it. Otherwise, follow the * regular lookup sequence. */ - if (config_source config_source-file) + if (config_source config_source-use_stdin) + return git_config_from_stdin(fn, data); + else if (config_source config_source-file) return git_config_from_file(fn, config_source-file, data); else if (config_source config_source-blob) return git_config_from_blob_ref(fn, config_source-blob, data); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 967359344dab..c9c426c273e5 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -475,15 +475,28 @@ ein.bahn=strasse EOF test_expect_success 'alternative GIT_CONFIG' ' - GIT_CONFIG=other-config git config -l output + GIT_CONFIG=other-config git config --list output test_cmp expect output
[PATCH 2/4] builtin/config.c: rename check_blob_write() - check_write()
The function will be reused to check for other conditions which prevent write. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 92ebf23f0a9a..a7c55e68883c 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -362,7 +362,7 @@ static int get_colorbool(int print) return get_colorbool_found ? 0 : 1; } -static void check_blob_write(void) +static void check_write(void) { if (given_config_blob) die(writing config blobs is not supported); @@ -572,7 +572,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_SET) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); ret = git_config_set_in_file(given_config_file, argv[0], value); @@ -582,21 +582,21 @@ int cmd_config(int argc, const char **argv, const char *prefix) return ret; } else if (actions == ACTION_SET_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, argv[2], 0); } else if (actions == ACTION_ADD) { - check_blob_write(); + check_write(); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, ^$, 0); } else if (actions == ACTION_REPLACE_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, @@ -623,7 +623,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) return get_urlmatch(argv[0], argv[1]); } else if (actions == ACTION_UNSET) { - check_blob_write(); + check_write(); check_argc(argc, 1, 2); if (argc == 2) return git_config_set_multivar_in_file(given_config_file, @@ -633,14 +633,14 @@ int cmd_config(int argc, const char **argv, const char *prefix) argv[0], NULL); } else if (actions == ACTION_UNSET_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 1, 2); return git_config_set_multivar_in_file(given_config_file, argv[0], NULL, argv[1], 1); } else if (actions == ACTION_RENAME_SECTION) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 2, 2); ret = git_config_rename_section_in_file(given_config_file, argv[0], argv[1]); @@ -651,7 +651,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_REMOVE_SECTION) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 1, 1); ret = git_config_rename_section_in_file(given_config_file, argv[0], NULL); -- 1.9.0.rc3 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/4] config: disallow relative include paths from blobs
From: Jeff King p...@peff.net When we see a relative config include like: [include] path = foo we make it relative to the containing directory of the file that contains the snippet. This makes no sense for config read from a blob, as it is not on the filesystem. Something like HEAD:some/path could have a relative path within the tree, but: 1. It would not be part of include.path, which explicitly refers to the filesystem. 2. It would need different parsing rules anyway to determine that it is a tree path. The current code just uses the name field, which is wrong. Let's split that into name and path fields, use the latter for relative includes, and fill in only the former for blobs. Signed-off-by: Jeff King p...@peff.net Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- config.c | 10 ++ t/t1305-config-include.sh | 16 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index d969a5aefc2b..b295310d3c22 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,7 @@ struct config_source { } buf; } u; const char *name; + const char *path; int die_on_error; int linenr; int eof; @@ -97,12 +98,12 @@ static int handle_path_include(const char *path, struct config_include_data *inc if (!is_absolute_path(path)) { char *slash; - if (!cf || !cf-name) + if (!cf || !cf-path) return error(relative config includes must come from files); - slash = find_last_dir_sep(cf-name); + slash = find_last_dir_sep(cf-path); if (slash) - strbuf_add(buf, cf-name, slash - cf-name + 1); + strbuf_add(buf, cf-path, slash - cf-path + 1); strbuf_addstr(buf, path); path = buf.buf; } @@ -1040,7 +1041,7 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data) struct config_source top; top.u.file = f; - top.name = filename; + top.name = top.path = filename; top.die_on_error = 1; top.do_fgetc = config_file_fgetc; top.do_ungetc = config_file_ungetc; @@ -1062,6 +1063,7 @@ int git_config_from_buf(config_fn_t fn, const char *name, const char *buf, top.u.buf.len = len; top.u.buf.pos = 0; top.name = name; + top.path = NULL; top.die_on_error = 0; top.do_fgetc = config_buf_fgetc; top.do_ungetc = config_buf_ungetc; diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index a70707620f14..6edd38b39a0b 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -122,6 +122,22 @@ test_expect_success 'relative includes from command line fail' ' test_must_fail git -c include.path=one config test.one ' +test_expect_success 'absolute includes from blobs work' ' + echo [test]one = 1 one + echo [include]path=$(pwd)/one blob + blob=$(git hash-object -w blob) + echo 1 expect + git config --blob=$blob test.one actual + test_cmp expect actual +' + +test_expect_success 'relative includes from blobs fail' ' + echo [test]one = 1 one + echo [include]path=one blob + blob=$(git hash-object -w blob) + test_must_fail git config --blob=$blob test.one +' + test_expect_success 'include cycles are detected' ' cat .gitconfig -\EOF [test]value = gitconfig -- 1.9.0.rc3 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/4] config: change git_config_with_options() interface
We're going to have more options for config source. Let's alter git_config_with_options() interface to accept struct with all source options. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 75 ++-- cache.h | 8 -- config.c | 13 +- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index a7c55e68883c..de41ba50e9ca 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -21,8 +21,7 @@ static char key_delim = ' '; static char term = '\n'; static int use_global_config, use_system_config, use_local_config; -static const char *given_config_file; -static const char *given_config_blob; +static struct git_config_source given_config_source; static int actions, types; static const char *get_color_slot, *get_colorbool_slot; static int end_null; @@ -55,8 +54,8 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, global, use_global_config, N_(use global config file)), OPT_BOOL(0, system, use_system_config, N_(use system config file)), OPT_BOOL(0, local, use_local_config, N_(use repository config file)), - OPT_STRING('f', file, given_config_file, N_(file), N_(use given config file)), - OPT_STRING(0, blob, given_config_blob, N_(blob-id), N_(read config from given blob object)), + OPT_STRING('f', file, given_config_source.file, N_(file), N_(use given config file)), + OPT_STRING(0, blob, given_config_source.blob, N_(blob-id), N_(read config from given blob object)), OPT_GROUP(N_(Action)), OPT_BIT(0, get, actions, N_(get value: name [value-regex]), ACTION_GET), OPT_BIT(0, get-all, actions, N_(get all values: key [value-regex]), ACTION_GET_ALL), @@ -224,8 +223,7 @@ static int get_value(const char *key_, const char *regex_) } git_config_with_options(collect_config, values, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); ret = !values.nr; @@ -309,8 +307,7 @@ static void get_color(const char *def_color) get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); if (!get_color_found def_color) color_parse(def_color, command line, parsed_color); @@ -339,8 +336,7 @@ static int get_colorbool(int print) get_diff_color_found = -1; get_color_ui_found = -1; git_config_with_options(git_get_colorbool_config, NULL, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); if (get_colorbool_found 0) { if (!strcmp(get_colorbool_slot, color.diff)) @@ -364,7 +360,7 @@ static int get_colorbool(int print) static void check_write(void) { - if (given_config_blob) + if (given_config_source.blob) die(writing config blobs is not supported); } @@ -435,7 +431,7 @@ static int get_urlmatch(const char *var, const char *url) } git_config_with_options(urlmatch_config_entry, config, - given_config_file, NULL, respect_includes); + given_config_source, respect_includes); for_each_string_list_item(item, values) { struct urlmatch_current_candidate_value *matched = item-util; @@ -464,14 +460,14 @@ int cmd_config(int argc, const char **argv, const char *prefix) int nongit = !startup_info-have_repository; char *value; - given_config_file = getenv(CONFIG_ENVIRONMENT); + given_config_source.file = getenv(CONFIG_ENVIRONMENT); argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (use_global_config + use_system_config + use_local_config + - !!given_config_file + !!given_config_blob 1) { + !!given_config_source.file + !!given_config_source.blob 1) { error(only one config file at a time.); usage_with_options(builtin_config_usage, builtin_config_options); } @@ -493,24 +489,24 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (access_or_warn(user_config, R_OK, 0) xdg_config !access_or_warn(xdg_config, R_OK, 0)) - given_config_file = xdg_config; + given_config_source.file = xdg_config; else
[PATCH] config: teach git config --file - to read from the standard input
The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Include by absolute path is allowed in stdin config, but not by relative path. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 11 + cache.h | 1 + config.c | 58 --- t/t1300-repo-config.sh| 17 -- t/t1305-config-include.sh | 16 - 5 files changed, 82 insertions(+), 21 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index de41ba50e9ca..5677c942b693 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -360,6 +360,9 @@ static int get_colorbool(int print) static void check_write(void) { + if (given_config_source.use_stdin) + die(writing to stdin is not supported); + if (given_config_source.blob) die(writing config blobs is not supported); } @@ -472,6 +475,12 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_with_options(builtin_config_usage, builtin_config_options); } + if (given_config_source.file + !strcmp(given_config_source.file, -)) { + given_config_source.file = NULL; + given_config_source.use_stdin = 1; + } + if (use_global_config) { char *user_config = NULL; char *xdg_config = NULL; @@ -558,6 +567,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 0, 0); if (!given_config_source.file nongit) die(not in a git directory); + if (given_config_source.use_stdin) + die(editing stdin is not supported); if (given_config_source.blob) die(editing blobs is not supported); git_config(git_default_config, NULL); diff --git a/cache.h b/cache.h index 9d94bd69f7db..4db19b537059 100644 --- a/cache.h +++ b/cache.h @@ -1147,6 +1147,7 @@ extern int update_server_info(int); #define CONFIG_GENERIC_ERROR 7 struct git_config_source { + unsigned int use_stdin:1; const char *file; const char *blob; }; diff --git a/config.c b/config.c index 6269da907964..7b42608f5c89 100644 --- a/config.c +++ b/config.c @@ -443,10 +443,20 @@ static int git_parse_source(config_fn_t fn, void *data) if (get_value(fn, data, var) 0) break; } - if (cf-die_on_error) - die(bad config file line %d in %s, cf-linenr, cf-name); - else - return error(bad config file line %d in %s, cf-linenr, cf-name); + if (cf-die_on_error) { + if (cf-name) + die(bad config file line %d in %s, + cf-linenr, cf-name); + else + die(bad config file line %d, cf-linenr); + + } else { + if (cf-name) + return error(bad config file line %d in %s, + cf-linenr, cf-name); + else + return error(bad config file line %d, cf-linenr); + } } static int parse_unit_factor(const char *end, uintmax_t *val) @@ -1030,24 +1040,34 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data) return ret; } -int git_config_from_file(config_fn_t fn, const char *filename, void *data) +static int do_config_from_file(config_fn_t fn, const char *filename, FILE *f, + void *data) { - int ret; - FILE *f = fopen(filename, r); + struct config_source top; - ret = -1; - if (f) { - struct config_source top; + top.u.file = f; + top.name = filename; + top.die_on_error = 1; + top.do_fgetc = config_file_fgetc; + top.do_ungetc = config_file_ungetc; + top.do_ftell = config_file_ftell; - top.u.file = f; - top.name = filename; - top.die_on_error = 1; - top.do_fgetc = config_file_fgetc; - top.do_ungetc = config_file_ungetc; - top.do_ftell = config_file_ftell; + return do_config_from(top, fn, data); +} + +static int git_config_from_stdin(config_fn_t fn, void *data) +{ + return do_config_from_file(fn, NULL, stdin, data); +} - ret = do_config_from(top, fn, data); +int git_config_from_file(config_fn_t fn, const char *filename, void *data) +{ + int ret = -1; + FILE *f; + f = fopen(filename, r); + if (f) { + ret = do_config_from_file(fn, filename, f, data); fclose(f); } return ret; @@ -1188,7 +1208,9 @@ int git_config_with_options(config_fn_t fn, void *data
[PATCH] config: git_config_from_file(): handle - filename as stdin
The patch extends git config --file interface to allow read config from stdin. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- config.c | 10 ++ t/t1300-repo-config.sh | 4 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index d969a5aefc2b..f80cc7e657e8 100644 --- a/config.c +++ b/config.c @@ -1032,10 +1032,11 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data) int git_config_from_file(config_fn_t fn, const char *filename, void *data) { - int ret; - FILE *f = fopen(filename, r); + int from_stdin = !strcmp(filename, -); + int ret = -1; + FILE *f; - ret = -1; + f = from_stdin ? stdin : fopen(filename, r); if (f) { struct config_source top; @@ -1048,7 +1049,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data) ret = do_config_from(top, fn, data); - fclose(f); + if (!from_stdin) + fclose(f); } return ret; } diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 967359344dab..f1a63075e34f 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -484,6 +484,10 @@ test_expect_success 'alternative GIT_CONFIG (--file)' ' test_cmp expect output ' +test_expect_success 'alternative GIT_CONFIG (--file=-)' ' + git config --file - -l other-config output + test_cmp expect output +' test_expect_success 'refer config from subdirectory' ' mkdir x ( -- 1.8.5.2 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] config: git_config_from_file(): handle - filename as stdin
On Fri, Feb 14, 2014 at 10:27:11AM -0800, Junio C Hamano wrote: Kirill A. Shutemov kir...@shutemov.name writes: The patch extends git config --file interface to allow read config from stdin. Thanks. The external interface proposed by this change that behaves the way your new test expects is a good addition to the system. I would describe it as: Subject: config: teach git config --file - to read from the standard input I however think the patch implements it at the level that is too low in the callchain. It will affect a lot more than the dash given to git config --file -. Fortunately, it does not make it possible for users to make this mistake [include] path = - and scratch their heads, wondering why git config is not answering until they hit ^D. But that is _only_ because we check if a file whose name is - actually exists in the current directory before falling into this codepath (and usually no such file exists). If such a funnily-named file does exist, we read from that file, not the standard input. So that include codepath happens to be safe, but who knows what dragons lie in other codepaths that call this function. I recall that an earlier implementation of git diff --no-index that made - read one side to be compared from the standard input had exactly the same issue of comparing filename with -, which we had to fix with code reorganization recently. I'd prefer to see this update to git config --file - done the right way from the start. Okay, reworked version is below. It's slightly more invasive then the original. From 199e6a995bb5228578e66189ef586421a4d8d9ba Mon Sep 17 00:00:00 2001 From: Kirill A. Shutemov kir...@shutemov.name Date: Fri, 14 Feb 2014 21:59:39 +0200 Subject: [PATCH] config: teach git config --file - to read from the standard input The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 39 ++- cache.h| 1 + config.c | 41 +++-- t/t1300-repo-config.sh | 17 +++-- 4 files changed, 69 insertions(+), 29 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 92ebf23f0a9a..625f914c44a0 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -21,6 +21,7 @@ static char key_delim = ' '; static char term = '\n'; static int use_global_config, use_system_config, use_local_config; +static int use_stdin; static const char *given_config_file; static const char *given_config_blob; static int actions, types; @@ -224,7 +225,7 @@ static int get_value(const char *key_, const char *regex_) } git_config_with_options(collect_config, values, - given_config_file, given_config_blob, + use_stdin, given_config_file, given_config_blob, respect_includes); ret = !values.nr; @@ -309,7 +310,7 @@ static void get_color(const char *def_color) get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, - given_config_file, given_config_blob, + use_stdin, given_config_file, given_config_blob, respect_includes); if (!get_color_found def_color) @@ -339,7 +340,7 @@ static int get_colorbool(int print) get_diff_color_found = -1; get_color_ui_found = -1; git_config_with_options(git_get_colorbool_config, NULL, - given_config_file, given_config_blob, + use_stdin, given_config_file, given_config_blob, respect_includes); if (get_colorbool_found 0) { @@ -362,8 +363,11 @@ static int get_colorbool(int print) return get_colorbool_found ? 0 : 1; } -static void check_blob_write(void) +static void check_write(void) { + if (use_stdin) + die(writing to stdin is not supported); + if (given_config_blob) die(writing config blobs is not supported); } @@ -435,7 +439,8 @@ static int get_urlmatch(const char *var, const char *url) } git_config_with_options(urlmatch_config_entry, config, - given_config_file, NULL, respect_includes); + use_stdin, given_config_file, NULL, + respect_includes); for_each_string_list_item(item, values) { struct urlmatch_current_candidate_value *matched = item-util; @@ -476,6 +481,11 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_with_options(builtin_config_usage, builtin_config_options
[PATCH 3/3] config: teach git config --file - to read from the standard input
The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Include by absolute path is allowed in stdin config, but not by relative path. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 11 + cache.h | 1 + config.c | 58 --- t/t1300-repo-config.sh| 17 -- t/t1305-config-include.sh | 14 5 files changed, 81 insertions(+), 20 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index de41ba50e9ca..5677c942b693 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -360,6 +360,9 @@ static int get_colorbool(int print) static void check_write(void) { + if (given_config_source.use_stdin) + die(writing to stdin is not supported); + if (given_config_source.blob) die(writing config blobs is not supported); } @@ -472,6 +475,12 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_with_options(builtin_config_usage, builtin_config_options); } + if (given_config_source.file + !strcmp(given_config_source.file, -)) { + given_config_source.file = NULL; + given_config_source.use_stdin = 1; + } + if (use_global_config) { char *user_config = NULL; char *xdg_config = NULL; @@ -558,6 +567,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 0, 0); if (!given_config_source.file nongit) die(not in a git directory); + if (given_config_source.use_stdin) + die(editing stdin is not supported); if (given_config_source.blob) die(editing blobs is not supported); git_config(git_default_config, NULL); diff --git a/cache.h b/cache.h index 9d94bd69f7db..4db19b537059 100644 --- a/cache.h +++ b/cache.h @@ -1147,6 +1147,7 @@ extern int update_server_info(int); #define CONFIG_GENERIC_ERROR 7 struct git_config_source { + unsigned int use_stdin:1; const char *file; const char *blob; }; diff --git a/config.c b/config.c index 6269da907964..7b42608f5c89 100644 --- a/config.c +++ b/config.c @@ -443,10 +443,20 @@ static int git_parse_source(config_fn_t fn, void *data) if (get_value(fn, data, var) 0) break; } - if (cf-die_on_error) - die(bad config file line %d in %s, cf-linenr, cf-name); - else - return error(bad config file line %d in %s, cf-linenr, cf-name); + if (cf-die_on_error) { + if (cf-name) + die(bad config file line %d in %s, + cf-linenr, cf-name); + else + die(bad config file line %d, cf-linenr); + + } else { + if (cf-name) + return error(bad config file line %d in %s, + cf-linenr, cf-name); + else + return error(bad config file line %d, cf-linenr); + } } static int parse_unit_factor(const char *end, uintmax_t *val) @@ -1030,24 +1040,34 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data) return ret; } -int git_config_from_file(config_fn_t fn, const char *filename, void *data) +static int do_config_from_file(config_fn_t fn, const char *filename, FILE *f, + void *data) { - int ret; - FILE *f = fopen(filename, r); + struct config_source top; - ret = -1; - if (f) { - struct config_source top; + top.u.file = f; + top.name = filename; + top.die_on_error = 1; + top.do_fgetc = config_file_fgetc; + top.do_ungetc = config_file_ungetc; + top.do_ftell = config_file_ftell; - top.u.file = f; - top.name = filename; - top.die_on_error = 1; - top.do_fgetc = config_file_fgetc; - top.do_ungetc = config_file_ungetc; - top.do_ftell = config_file_ftell; + return do_config_from(top, fn, data); +} + +static int git_config_from_stdin(config_fn_t fn, void *data) +{ + return do_config_from_file(fn, NULL, stdin, data); +} - ret = do_config_from(top, fn, data); +int git_config_from_file(config_fn_t fn, const char *filename, void *data) +{ + int ret = -1; + FILE *f; + f = fopen(filename, r); + if (f) { + ret = do_config_from_file(fn, filename, f, data); fclose(f); } return ret; @@ -1188,7 +1208,9 @@ int git_config_with_options(config_fn_t fn, void *data
[PATCH 1/3] builtin/config.c: rename check_blob_write() - check_write()
The function will be reused to check for other conditions which prevent write. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 92ebf23f0a9a..a7c55e68883c 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -362,7 +362,7 @@ static int get_colorbool(int print) return get_colorbool_found ? 0 : 1; } -static void check_blob_write(void) +static void check_write(void) { if (given_config_blob) die(writing config blobs is not supported); @@ -572,7 +572,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_SET) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); ret = git_config_set_in_file(given_config_file, argv[0], value); @@ -582,21 +582,21 @@ int cmd_config(int argc, const char **argv, const char *prefix) return ret; } else if (actions == ACTION_SET_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, argv[2], 0); } else if (actions == ACTION_ADD) { - check_blob_write(); + check_write(); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, ^$, 0); } else if (actions == ACTION_REPLACE_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, @@ -623,7 +623,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) return get_urlmatch(argv[0], argv[1]); } else if (actions == ACTION_UNSET) { - check_blob_write(); + check_write(); check_argc(argc, 1, 2); if (argc == 2) return git_config_set_multivar_in_file(given_config_file, @@ -633,14 +633,14 @@ int cmd_config(int argc, const char **argv, const char *prefix) argv[0], NULL); } else if (actions == ACTION_UNSET_ALL) { - check_blob_write(); + check_write(); check_argc(argc, 1, 2); return git_config_set_multivar_in_file(given_config_file, argv[0], NULL, argv[1], 1); } else if (actions == ACTION_RENAME_SECTION) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 2, 2); ret = git_config_rename_section_in_file(given_config_file, argv[0], argv[1]); @@ -651,7 +651,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_REMOVE_SECTION) { int ret; - check_blob_write(); + check_write(); check_argc(argc, 1, 1); ret = git_config_rename_section_in_file(given_config_file, argv[0], NULL); -- 1.8.5.2 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/3] config: change git_config_with_options() interface
We're going to have more options for config source. Let's alter git_config_with_options() interface to accept struct with all source options. Signed-off-by: Kirill A. Shutemov kir...@shutemov.name --- builtin/config.c | 75 ++-- cache.h | 8 -- config.c | 13 +- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index a7c55e68883c..de41ba50e9ca 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -21,8 +21,7 @@ static char key_delim = ' '; static char term = '\n'; static int use_global_config, use_system_config, use_local_config; -static const char *given_config_file; -static const char *given_config_blob; +static struct git_config_source given_config_source; static int actions, types; static const char *get_color_slot, *get_colorbool_slot; static int end_null; @@ -55,8 +54,8 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, global, use_global_config, N_(use global config file)), OPT_BOOL(0, system, use_system_config, N_(use system config file)), OPT_BOOL(0, local, use_local_config, N_(use repository config file)), - OPT_STRING('f', file, given_config_file, N_(file), N_(use given config file)), - OPT_STRING(0, blob, given_config_blob, N_(blob-id), N_(read config from given blob object)), + OPT_STRING('f', file, given_config_source.file, N_(file), N_(use given config file)), + OPT_STRING(0, blob, given_config_source.blob, N_(blob-id), N_(read config from given blob object)), OPT_GROUP(N_(Action)), OPT_BIT(0, get, actions, N_(get value: name [value-regex]), ACTION_GET), OPT_BIT(0, get-all, actions, N_(get all values: key [value-regex]), ACTION_GET_ALL), @@ -224,8 +223,7 @@ static int get_value(const char *key_, const char *regex_) } git_config_with_options(collect_config, values, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); ret = !values.nr; @@ -309,8 +307,7 @@ static void get_color(const char *def_color) get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); if (!get_color_found def_color) color_parse(def_color, command line, parsed_color); @@ -339,8 +336,7 @@ static int get_colorbool(int print) get_diff_color_found = -1; get_color_ui_found = -1; git_config_with_options(git_get_colorbool_config, NULL, - given_config_file, given_config_blob, - respect_includes); + given_config_source, respect_includes); if (get_colorbool_found 0) { if (!strcmp(get_colorbool_slot, color.diff)) @@ -364,7 +360,7 @@ static int get_colorbool(int print) static void check_write(void) { - if (given_config_blob) + if (given_config_source.blob) die(writing config blobs is not supported); } @@ -435,7 +431,7 @@ static int get_urlmatch(const char *var, const char *url) } git_config_with_options(urlmatch_config_entry, config, - given_config_file, NULL, respect_includes); + given_config_source, respect_includes); for_each_string_list_item(item, values) { struct urlmatch_current_candidate_value *matched = item-util; @@ -464,14 +460,14 @@ int cmd_config(int argc, const char **argv, const char *prefix) int nongit = !startup_info-have_repository; char *value; - given_config_file = getenv(CONFIG_ENVIRONMENT); + given_config_source.file = getenv(CONFIG_ENVIRONMENT); argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (use_global_config + use_system_config + use_local_config + - !!given_config_file + !!given_config_blob 1) { + !!given_config_source.file + !!given_config_source.blob 1) { error(only one config file at a time.); usage_with_options(builtin_config_usage, builtin_config_options); } @@ -493,24 +489,24 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (access_or_warn(user_config, R_OK, 0) xdg_config !access_or_warn(xdg_config, R_OK, 0)) - given_config_file = xdg_config; + given_config_source.file = xdg_config; else
[PATCH] rebase -i: respect to core.abbrev
git rebase -i collapses ids on todo list to 7 hexdigits. Let's use core.abbrev config option instead, if it's set. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- git-rebase--interactive.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 10bf318d0d..078c28ff1b 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -713,7 +713,8 @@ expand_todo_ids() { } collapse_todo_ids() { - transform_todo_ids --short=7 + abbrev=$(git config --get 'core.abbrev') + transform_todo_ids --short=${abbrev:-7} } # Rearrange the todo list that has both pick sha1 msg and -- 1.8.4.rc3 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH] rebase -i: respect to core.abbrev
Kirill A. Shutemov wrote: git rebase -i collapses ids on todo list to 7 hexdigits. Let's use core.abbrev config option instead, if it's set. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- git-rebase--interactive.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 10bf318d0d..078c28ff1b 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -713,7 +713,8 @@ expand_todo_ids() { } collapse_todo_ids() { - transform_todo_ids --short=7 + abbrev=$(git config --get 'core.abbrev') + transform_todo_ids --short=${abbrev:-7} Simpler version is below. From 933a4159f0c037a37f3b251a4f13deea7f17b6c3 Mon Sep 17 00:00:00 2001 From: Kirill A. Shutemov kirill.shute...@linux.intel.com Date: Sat, 28 Sep 2013 18:53:05 +0300 Subject: [PATCH] rebase -i: respect to core.abbrev collapse_todo_ids() uses `git rev-parse --short=7' to abbrev commit ids. Let's drop argument from --short to use default (7) or config value instead. Signed-off-by: Kirill A. Shutemov kirill.shute...@linux.intel.com --- git-rebase--interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 10bf318d0d..3c6bed9a28 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -713,7 +713,7 @@ expand_todo_ids() { } collapse_todo_ids() { - transform_todo_ids --short=7 + transform_todo_ids --short } # Rearrange the todo list that has both pick sha1 msg and -- Kirill A. Shutemov -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html