threads / discuss / 23167

What's cooking in git.git (Mar 2010, #06; Wed, 24)

Subject: What's cooking in git.git (Mar 2010, #06; Wed, 24)

## tl;dr

13 messages between Mar 25, 2010 and Mar 29, 2010.

replies: 12people: 7as markdown or json

Junio C Hamano· Mar 25, 2010, 00:41 UTC · lore

What's cooking in git.git (Mar 2010, #06; Wed, 24) --------------------------------------------------

Here are the topics that have been cooking. Commits prefixed with '-' are only in 'pu' while commits prefixed with '+' are in 'next'. The ones marked with '.' do not appear in any of the integration branches, but I am still holding onto them.

The tip of 'pu' is broken right now; it does not pass t7006.

-------------------------------------------------- [Graduated to "master"]

* jh/maint-submodule-status-in-void (2010-03-09) 2 commits
  (merged to 'next' on 2010-03-15 at 49af9de)
 + git submodule summary: Handle HEAD as argument when on an unborn branch
  (merged to 'next' on 2010-03-08 at 0697bf4)
 + submodule summary: do not fail before the first commit
* jc/maint-refs-dangling (2010-03-15) 1 commit
  (merged to 'next' on 2010-03-16 at 376027b)
 + refs: ref entry with NULL sha1 is can be a dangling symref
* pb/log-first-parent-p-m (2010-03-09) 5 commits
  (merged to 'next' on 2010-03-15 at 0ae494e)
 + show --first-parent/-m: do not default to --cc
 + show -c: show patch text
 + revision: introduce setup_revision_opt
 + t4013: add tests for log -p -m --first-parent
  (merged to 'next' on 2010-02-17 at 2f8e5ae)
 + git log -p -m: document -m and honor --first-parent
Ready for 'master'.
* jl/submodule-diff-dirtiness (2010-03-13) 5 commits
  (merged to 'next' on 2010-03-15 at 9601fd9)
 + git status: ignoring untracked files must apply to submodules too
  (merged to 'next' on 2010-03-13 at f9bfd8a)
 + git status: Fix false positive "new commits" output for dirty submodules
 + Refactor dirty submodule detection in diff-lib.c
  (merged to 'next' on 2010-03-08 at 33f7a57)
 + git status: Show detailed dirty status of submodules in long format
  (merged to 'next' on 2010-03-04 at 58b2645)
 + git diff --submodule: Show detailed dirty status of submodules
Ready for 'master'.
* tr/notes-display (2010-03-12) 13 commits
  (merged to 'next' on 2010-03-15 at 3329361)
 + git-notes(1): add a section about the meaning of history
 + notes: track whether notes_trees were changed at all
 + notes: add shorthand --ref to override GIT_NOTES_REF
 + commit --amend: copy notes to the new commit
 + rebase: support automatic notes copying
 + notes: implement helpers needed for note copying during rewrite
 + notes: implement 'git notes copy --stdin'
 + rebase -i: invoke post-rewrite hook
 + rebase: invoke post-rewrite hook
 + commit --amend: invoke post-rewrite hook
 + Documentation: document post-rewrite hook
 + Support showing notes from more than one notes tree
 + test-lib: unset GIT_NOTES_REF to stop it from influencing tests
 (this branch is used by sb/notes-parse-opt.)

-------------------------------------------------- [New Topics]

* bw/git-completion-rpmspec (2010-03-20) 1 commit
 - Add a git-completion rpm subpackage to the spec

Shipping bash-completion as part of RPM package; since Todd Zullinger who packages git for Fedora joined the thread, I am hoping that I can defer the direction of the final version to the discussion between Todd and Ben.

* ef/maint-empty-commit-log (2010-03-21) 1 commit
 - rev-list: fix --pretty=oneline with empty message
Looked reasonable.  Soon in 'next'.
* em/checkout-orphan (2010-03-21) 1 commit
 - git checkout: create unparented branch by --orphan

Looked reasonable, except that we might want to come up with a way to allow people with core.logallrefupdates set to false to still override it with "-l" when switching to this new branch. Or we may not care. I dunno.

Soon in 'next'.
* mg/mailmap-update (2010-03-19) 1 commit
 - .mailmap: Entries for Alex Benn辿e, Deskin Miller, Vitaly "_Vi" Shukela
Soon in 'next'.
* mg/maint-send-email-lazy-editor (2010-03-22) 1 commit
 - [reword?] send-email: lazily assign editor variable
* mg/use-default-abbrev-length-in-rev-list (2010-03-22) 1 commit
 - rev-list: use default abbrev length when abbrev-commit is in effect
* np/malloc-threading (2010-03-24) 1 commit
 - Make xmalloc and xrealloc thread-safe
* rb/maint-python-path (2010-03-21) 1 commit
 - Correct references to /usr/bin/python which does not exist on FreeBSD
Soon in 'next'.
* rr/imap-send-unconfuse-from-line (2010-03-22) 1 commit
 - imap-send: Remove limitation on message body
Soon in 'next'.
* sp/maint-http-backend-die-triggers-die-recursively (2010-03-22) 1 commit
 - http-backend: Don't infinite loop during die()
Soon in 'next'.

-------------------------------------------------- [Stalled]

* cw/test-lib-relicense (2010-02-22) 1 commit
 . test-lib.sh: Add explicit license detail, with change from GPLv2 to GPLv2+.

Ack-collection stopped at the last three names. I am hoping Carl can take it from there without my keeping an eye on it.

* js/rebase-origin-x (2010-02-05) 1 commit
 - [RFC w/o test and incomplete] rebase: add -x option to record original commit name

I retract my objection against the idea of -x; needs polishing before moving forward.

* sg/bash-completion (2010-02-23) 4 commits
  (merged to 'next' on 2010-03-08 at bc59860)
 + bash: completion for gitk aliases
 + bash: support user-supplied completion scripts for aliases
 + bash: support user-supplied completion scripts for user's git commands
 + bash: improve aliased command recognition
Perhaps rename _git_frotz -> _git_complete_frotz?  I dunno.
* sd/log-decorate (2010-02-17) 3 commits
  (merged to 'next' on 2010-03-08 at 58a6fba)
 + log.decorate: usability fixes
 + Add `log.decorate' configuration variable.
 + git_config_maybe_bool()

Needs squelching the configuration setting when "--pretty=raw" is given, at least, or possibly when any "--pretty" is explicitly given.

-------------------------------------------------- [Cooking]

* ar/config-from-command-line (2010-03-19) 1 commit
 - Allow passing of configuration parameters in the command line
* bc/t5505-fix (2010-03-19) 3 commits
 - t/t5505-remote.sh: escape * to prevent interpretation by shell as glob
 - t5505: add missing &&
 - t5505: remove unnecessary subshell invocations
Looked reasonable.  Soon in 'next'.
* bw/template-tool-buildconfig (2010-03-20) 2 commits
 - Modernize git calling conventions in hook templates
 - Make templates honour SHELL_PATH and PERL_PATH
Looked reasonable.  Soon in 'next'.
* mb/rebase-i-no-ff (2010-03-24) 1 commit
 - Teach rebase the --no-ff option.
Looked reasonable.  Soon in 'next'.
* jn/merge-diff3-label (2010-03-20) 14 commits
  (merged to 'next' on 2010-03-20 at 26f1805)
 + merge-recursive: add a label for ancestor
 + cherry-pick, revert: add a label for ancestor
 + revert: clarify label on conflict hunks
 + compat: add mempcpy()
 + checkout -m --conflict=diff3: add a label for ancestor
 + merge_trees(): add ancestor label parameter for diff3-style output
 + merge_file(): add comment explaining behavior wrt conflict style
 + checkout --conflict=diff3: add a label for ancestor
 + ll_merge(): add ancestor label parameter for diff3-style output
 + merge-file --diff3: add a label for ancestor
 + xdl_merge(): move file1 and file2 labels to xmparam structure
 + xdl_merge(): add optional ancestor label to diff3-style output
 + tests: document cherry-pick behavior in face of conflicts
 + tests: document format of conflicts from checkout -m
* do/rebase-i-arbitrary (2010-03-14) 1 commit
 - rebase--interactive: don't require what's rebased to be a branch
Looked reasonable.  Soon in 'next'.
* ja/send-email-ehlo (2010-03-14) 3 commits
 - git-send-email.perl - try to give real name of the calling host to HELO/EHLO
 - git-send-email.perl: add option --smtp-debug
 - git-send-email.perl: improve error message in send_message()
Looked reasonable.  Soon in 'next'.
* ak/everyday-git (2009-10-21) 1 commit
 - everyday: fsck and gc are not everyday operations
Looked reasonable.  Soon in 'next'.
* bc/acl-test (2010-03-15) 5 commits
 - t/t1304: make a second colon optional in the mask ACL check
 - t/t1304: set the ACL effective rights mask
 - t/t1304: use 'test -r' to test readability rather than looking at mode bits
 - t/t1304: set the Default ACL base entries
 - t/t1304: avoid -d option to setfacl
Looked reasonable.  Soon in 'next'.
* bc/maint-daemon-sans-ss-family (2010-03-15) 1 commit
 - daemon.c: avoid accessing ss_family member of struct sockaddr_storage
Looked reasonable.  Soon in 'next'.
* ef/cherry-abbrev (2010-03-20) 2 commits
 - ls: remove redundant logic
 - cherry: support --abbrev option
Looked reasonable.  Soon in 'next'.
* gh/maint-stash-show-error-message (2010-03-16) 1 commit
 - Improve error messages from 'git stash show'
Looked reasonable.  Soon in 'next'.
* rs/threaded-grep-context (2010-03-15) 1 commit
 - grep: enable threading for context line printing
Looked reasonable.  Soon in 'next'.
* cc/cherry-pick-ff (2010-03-20) 7 commits
  (merged to 'next' on 2010-03-20 at a1ae16b)
 + revert: fix tiny memory leak in cherry-pick --ff
 + rebase -i: use new --ff cherry-pick option
  (merged to 'next' on 2010-03-07 at 5589b26)
 + Documentation: describe new cherry-pick --ff option
 + cherry-pick: add tests for new --ff option
 + revert: add --ff option to allow fast forward when cherry-picking
 + builtin/merge: make checkout_fast_forward() non static
 + parse-options: add parse_options_concat() to concat options
Ready for 'master'.
* js/async-thread (2010-03-09) 7 commits
 - Enable threaded async procedures whenever pthreads is available
  (merged to 'next' on 2010-03-20 at 9939243)
 + Dying in an async procedure should only exit the thread, not the process.
 + Reimplement async procedures using pthreads
 + Windows: more pthreads functions
 + Fix signature of fcntl() compatibility dummy
 + Make report() from usage.c public as vreportf() and use it.
 + Modernize t5530-upload-pack-error.
The tip one will be soon in 'next', but one step at a time.
* nd/setup (2010-03-21) 40 commits
 - Guard unallowed access to repository when it's not set up
 - alias: keep repository found while collecting aliases as long as possible
 - Allow to undo setup_git_directory_gently() gracefully (and fix alias code)
 - builtins: check for startup_info->help, print and exit early
 - builtins: utilize startup_info->help where possible
 - run_builtin(): save "-h" detection result for later use
 - config: do not read .git/config if there is no repository
 - apply: do not check sha1 when repository has not been found
 - Do not read .git/info/attributes if there is no repository
 - Do not read .git/info/exclude if there is no repository
 - git_config(): do not read .git/config if there is no repository
 - init/clone: turn on startup->have_repository properly
 - worktree setup: restore original state when things go wrong
 - Use git_config_early() instead of git_config() during repo setup
 - Add git_config_early()
 - worktree setup: call set_git_dir explicitly
 - rev-parse --git-dir: print relative gitdir correctly
 - enter_repo(): initialize other variables as setup_git_directory_gently() does
 - Move enter_repo() to setup.c
 - index-pack: use RUN_SETUP_GENTLY
 - index-pack: trust the prefix returned by setup_git_directory_gently()
 - worktree setup: calculate prefix even if no worktree is found
 - merge-file: use RUN_SETUP_GENTLY
 - var: use RUN_SETUP_GENTLY
 - ls-remote: use RUN_SETUP_GENTLY
 - help: use RUN_SETUP_GENTLY
 - diff: use RUN_SETUP_GENTLY
 - bundle: use RUN_SETUP_GENTLY
 - apply: use RUN_SETUP_GENTLY
 - verify-pack: use RUN_SETUP_GENTLY
 - check-ref-format: use RUN_SETUP_GENTLY
 - mailinfo: use RUN_SETUP_GENTLY
 - archive: use RUN_SETUP_GENTLY
 - builtin: USE_PAGER should not be used without RUN_SETUP*
 - grep: use RUN_SETUP_GENTLY
 - shortlog: use RUN_SETUP_GENTLY
 - hash-object: use RUN_SETUP_GENTLY
 - config: use RUN_SETUP_GENTLY
 - builtin: Support RUN_SETUP_GENTLY to set up repository early if found
 - builtin: introduce startup_info struct
This seems to break t7006 when merged to 'pu'.
* sb/notes-parse-opt (2010-02-27) 1 commit
  (merged to 'next' on 2010-03-24 at 82eebc1)
 + notes: rework subcommands and parse options
Nguyen Thai Ngoc Duy· Mar 25, 2010, 15:11 UTC · re: Junio C Hamano · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

2010/3/25 Junio C Hamano <gitster@pobox.com>:
Show 7 quoted lines
> * ar/config-from-command-line (2010-03-19) 1 commit
>  - Allow passing of configuration parameters in the command line
>
> * bc/t5505-fix (2010-03-19) 3 commits
>  - t/t5505-remote.sh: escape * to prevent interpretation by shell as glob
>  - t5505: add missing &&
>  - t5505: remove unnecessary subshell invocations
This breaks my build on Solaris because it uses strndup, which is not available.
-- 
Duy
Brandon Casey· Mar 25, 2010, 16:27 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

On 03/25/2010 10:11 AM, Nguyen Thai Ngoc Duy wrote:
Show 8 quoted lines
> 2010/3/25 Junio C Hamano <gitster@pobox.com>:
>> * ar/config-from-command-line (2010-03-19) 1 commit
>>  - Allow passing of configuration parameters in the command line
>>
>> * bc/t5505-fix (2010-03-19) 3 commits
>>  - t/t5505-remote.sh: escape * to prevent interpretation by shell as glob
>>  - t5505: add missing &&
>>  - t5505: remove unnecessary subshell invocations

methinks you were over-aggressive with your cut/paste? I don't think bc/t5505-fix contains a strndup. Hopefully, it does not break your build on Solaris.

> This breaks my build on Solaris because it uses strndup, which is not available.
A quick glance at ar/config-from.. also detected an unchecked calloc().
Alex, any reason xcalloc wasn't used?

btw, me also thinks the code is a little hard to read. For example, I initially thought your calloc was not allocating enough space for the nul terminator.

   ct = calloc(1, sizeof(struct config_item) + (text - name));
   memcpy(ct->name, name, text - name);

I traced the code, but it wasn't until I noticed that your data structure looks like this:

   struct config_item
   {
          struct config_item *next;
          char *value;
          char name[1];
   };

that I realized that room for the nul terminator in the 'name' array was allocated by the structure itself, since the name declaration looks like name[1] and not name[FLEX_ARRAY].

Would the code be simpler if strbufs were used? Then you wouldn't need to duplicate the skip_space and trailing_space functionality provided in the strbuf library, and would just need a new function named strbuf_tolower.

Also, should config_parametes_tail be spelled config_parameters_tail?
-brandon
Alex Riesen· Mar 25, 2010, 23:11 UTC · re: Brandon Casey · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

On Thu, Mar 25, 2010 at 17:27, Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil> wrote:

Show 9 quoted lines
> On 03/25/2010 10:11 AM, Nguyen Thai Ngoc Duy wrote:
>> 2010/3/25 Junio C Hamano <gitster@pobox.com>:
>>> * ar/config-from-command-line (2010-03-19) 1 commit
>>>  - Allow passing of configuration parameters in the command line
>> This breaks my build on Solaris because it uses strndup, which is not available.
>
> A quick glance at ar/config-from.. also detected an unchecked calloc().
>
> Alex, any reason xcalloc wasn't used?
Just missed it. Long time away from Git sources.
Show 19 quoted lines
> btw, me also thinks the code is a little hard to read.  For example, I initially
> thought your calloc was not allocating enough space for the nul terminator.
>
>   ct = calloc(1, sizeof(struct config_item) + (text - name));
>   memcpy(ct->name, name, text - name);
>
> I traced the code, but it wasn't until I noticed that your data structure looks
> like this:
>
>   struct config_item
>   {
>          struct config_item *next;
>          char *value;
>          char name[1];
>   };
>
> that I realized that room for the nul terminator in the 'name' array was allocated
> by the structure itself, since the name declaration looks like name[1] and not
> name[FLEX_ARRAY].

Hmm, I kinda liked how the space for the terminator was reserved and all the flex array incompatibilities were worked around.

> Would the code be simpler if strbufs were used?  Then you wouldn't need to duplicate
> the skip_space and trailing_space functionality provided in the strbuf library, and
> would just need a new function named strbuf_tolower.
But this indeed makes sense. Promise to take a look at it after some sleep.
> Also, should config_parametes_tail be spelled config_parameters_tail?
Yep.
Thanks!
Alex Riesen· Mar 26, 2010, 22:53 UTC · re: Alex Riesen · lore

[PATCH 1/2] Allow passing of configuration parameters in the command line

The values passed this way will override whatever is defined in the config files.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

I replaced strndup with xstrndup, and calloc with xcalloc. A common workaround for broken flexarray support has got a small hint, and that typo got fixed too. A test for CamelCase config key added.

This patch replaces the one I sent earlier.
Alex Riesen, Fri, Mar 26, 2010 00:11:51 +0100:
Show 14 quoted lines
> On Thu, Mar 25, 2010 at 17:27, Brandon Casey
> <brandon.casey.ctr@nrlssc.navy.mil> wrote:
> > On 03/25/2010 10:11 AM, Nguyen Thai Ngoc Duy wrote:
> >> 2010/3/25 Junio C Hamano <gitster@pobox.com>:
> >>> * ar/config-from-command-line (2010-03-19) 1 commit
> >>>  - Allow passing of configuration parameters in the command line
> >> This breaks my build on Solaris because it uses strndup, which is not available.
> >
> > A quick glance at ar/config-from.. also detected an unchecked calloc().
> >
> > Alex, any reason xcalloc wasn't used?
> 
> Just missed it. Long time away from Git sources.
> 
Done.
Show 5 quoted lines
> > Would the code be simpler if strbufs were used?  Then you wouldn't need to duplicate
> > the skip_space and trailing_space functionality provided in the strbuf library, and
> > would just need a new function named strbuf_tolower.
> 
> But this indeed makes sense. Promise to take a look at it after some sleep.

Done, but... It does make the code more readable, but I don't like strbuf anymore. It has grown ugly. A lot of allocations, reallocations and copying around. It may be efficient, but I found it hard to convince myself that it is. And it should fragment heap a lot (doesn't matter much in this particular case but it may be an issue somewhere. Not all heaps are as robust as glibc's one).

This patch is separate, and I didn't strbuf_tolower thing: the only other place in whole project which lowcases a string is in mailmap, and doesn't look like it can profit from conversion to strbuf (just look for tolower in mailmap.c).

> > Also, should config_parametes_tail be spelled config_parameters_tail?
> 
Done
 Documentation/git.txt  |    7 +++++
 builtin/config.c       |    6 +++-
 cache.h                |    2 +
 config.c               |   71 ++++++++++++++++++++++++++++++++++++++++++++++++
 git.c                  |    9 ++++++
 t/t1300-repo-config.sh |    8 +++++
 6 files changed, 102 insertions(+), 1 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 4e00b31..0fc5cfe 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -12,6 +12,7 @@ SYNOPSIS
 '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
@@ -220,6 +221,12 @@ displayed. See linkgit:git-help[1] for more information,
 because `git --help ...` is converted internally into `git
 help ...`.
 
+-c <name>=<value>::
+	Pass a configuration parameter to the command. The value
+	given will override values from configuration files.
+	The <name> 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 --git a/builtin/config.c b/builtin/config.c
index 4bc46b1..f3d1660 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -197,7 +197,11 @@ static int get_value(const char *key_, const char *regex_)
 		git_config_from_file(show_config, system_wide, NULL);
 	if (do_all && global)
 		git_config_from_file(show_config, global, NULL);
-	git_config_from_file(show_config, local, NULL);
+	if (do_all)
+		git_config_from_file(show_config, local, NULL);
+	git_config_from_parameters(show_config, NULL);
+	if (!do_all && !seen)
+		git_config_from_file(show_config, local, NULL);
 	if (!do_all && !seen && global)
 		git_config_from_file(show_config, global, NULL);
 	if (!do_all && !seen && system_wide)
diff --git a/cache.h b/cache.h
index 2928107..f5fa79e 100644
--- a/cache.h
+++ b/cache.h
@@ -936,6 +936,8 @@ 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();
 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 *);
diff --git a/config.c b/config.c
index 6963fbe..83ebe0c 100644
--- a/config.c
+++ b/config.c
@@ -18,6 +18,62 @@ static int zlib_compression_seen;
 
 const char *config_exclusive_filename = NULL;
 
+struct config_item
+{
+	struct config_item *next;
+	char *value;
+	char name[1 /* NUL */];
+};
+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);
+}
+static char *skip_space(const char *p)
+{
+	for (; *p; ++p)
+		if (!isspace(*p))
+			break;
+	return (char *)p;
+}
+static char *trailing_space(const char *begin, const char *p)
+{
+	while (p-- > begin)
+		if (!isspace(*p))
+			break;
+	return (char *)p + 1;
+}
+
+int git_config_parse_parameter(const char *text)
+{
+	struct config_item *ct;
+	const char *name;
+	const char *val;
+	name = skip_space(text);
+	text = val = strchr(name, '=');
+	if (!text)
+		text = name + strlen(name);
+	text = trailing_space(name, text);
+	if (text <= name)
+		return -1;
+	ct = xcalloc(1, sizeof(struct config_item) + (text - name));
+	memcpy(ct->name, name, text - name);
+	lowercase(ct->name);
+	if (!val)
+		ct->value = NULL;
+	else {
+		val = skip_space(++val /* skip "=" */);
+		text = trailing_space(val, val + strlen(val));
+		ct->value = xstrndup(val, text - val);
+	}
+	*config_parameters_tail = ct;
+	config_parameters_tail = &ct->next;
+	return 0;
+}
+
 static int get_next_char(void)
 {
 	int c;
@@ -699,6 +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;
@@ -730,6 +795,12 @@ int git_config(config_fn_t fn, void *data)
 		found += 1;
 	}
 	free(repo_config);
+
+	if (config_parameters) {
+		ret += git_config_from_parameters(fn, data);
+		found += 1;
+	}
+
 	if (found == 0)
 		return -1;
 	return ret;
diff --git a/git.c b/git.c
index 6bae305..99f0363 100644
--- a/git.c
+++ b/git.c
@@ -8,6 +8,7 @@ const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
 	"           [-p|--paginate|--no-pager] [--no-replace-objects]\n"
 	"           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n"
+	"           [-c name=value\n"
 	"           [--help] COMMAND [ARGS]";
 
 const char git_more_info_string[] =
@@ -130,6 +131,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
 			if (envchanged)
 				*envchanged = 1;
+		} else if (!strcmp(cmd, "-c")) {
+			if (*argc < 2) {
+				fprintf(stderr, "-c expects a configuration string\n" );
+				usage(git_usage_string);
+			}
+			git_config_parse_parameter((*argv)[1]);
+			(*argv)++;
+			(*argc)--;
 		} else {
 			fprintf(stderr, "Unknown option: %s\n", cmd);
 			usage(git_usage_string);
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index f11f98c..64f0508 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -824,4 +824,12 @@ test_expect_success 'check split_cmdline return' "
 	test_must_fail git merge master
 	"
 
+test_expect_success 'git -c "key=value" support' '
+	test "z$(git -c name=value config name)" = zvalue &&
+	test "z$(git -c core.name=value config core.name)" = zvalue &&
+	test "z$(git -c CamelCase=value config camelcase)" = zvalue &&
+	test "z$(git -c flag config --bool flag)" = ztrue &&
+	test_must_fail git -c core.name=value config name
+'
+
 test_done
-- 
1.7.0.3.309.g532f0
Alex Riesen· Mar 26, 2010, 22:56 UTC · re: Alex Riesen · lore

[PATCH 2/2] Use strbufs instead of open-coded string manipulation

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 config.c |   51 +++++++++++++++++++--------------------------------
 1 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/config.c b/config.c
index 83ebe0c..7a514fa 100644
--- a/config.c
+++ b/config.c
@@ -7,6 +7,7 @@
  */
 #include "cache.h"
 #include "exec_cmd.h"
+#include "strbuf.h"
 
 #define MAXNAME (256)
 
@@ -21,8 +22,8 @@ const char *config_exclusive_filename = NULL;
 struct config_item
 {
 	struct config_item *next;
+	char *name;
 	char *value;
-	char name[1 /* NUL */];
 };
 static struct config_item *config_parameters;
 static struct config_item **config_parameters_tail = &config_parameters;
@@ -32,43 +33,29 @@ static void lowercase(char *p)
 	for (; *p; ++p)
 		*p = tolower(*p);
 }
-static char *skip_space(const char *p)
-{
-	for (; *p; ++p)
-		if (!isspace(*p))
-			break;
-	return (char *)p;
-}
-static char *trailing_space(const char *begin, const char *p)
-{
-	while (p-- > begin)
-		if (!isspace(*p))
-			break;
-	return (char *)p + 1;
-}
 
 int git_config_parse_parameter(const char *text)
 {
 	struct config_item *ct;
-	const char *name;
-	const char *val;
-	name = skip_space(text);
-	text = val = strchr(name, '=');
-	if (!text)
-		text = name + strlen(name);
-	text = trailing_space(name, text);
-	if (text <= name)
+	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) + (text - name));
-	memcpy(ct->name, name, text - name);
-	lowercase(ct->name);
-	if (!val)
-		ct->value = NULL;
-	else {
-		val = skip_space(++val /* skip "=" */);
-		text = trailing_space(val, val + strlen(val));
-		ct->value = xstrndup(val, text - val);
 	}
+	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;
-- 
1.7.0.3.309.g532f0
Nguyen Thai Ngoc Duy· Mar 26, 2010, 05:47 UTC · re: Brandon Casey · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

On Thu, Mar 25, 2010 at 5:27 PM, Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil> wrote:

Show 12 quoted lines
> On 03/25/2010 10:11 AM, Nguyen Thai Ngoc Duy wrote:
>> 2010/3/25 Junio C Hamano <gitster@pobox.com>:
>>> * ar/config-from-command-line (2010-03-19) 1 commit
>>>  - Allow passing of configuration parameters in the command line
>>>
>>> * bc/t5505-fix (2010-03-19) 3 commits
>>>  - t/t5505-remote.sh: escape * to prevent interpretation by shell as glob
>>>  - t5505: add missing &&
>>>  - t5505: remove unnecessary subshell invocations
>
> methinks you were over-aggressive with your cut/paste?  I don't think bc/t5505-fix
> contains a strndup.  Hopefully, it does not break your build on Solaris.

Yeah. It should have been after ar/config-from-command-line. Made me wonder why this topic had test fixes..

-- 
Duy
Nguyen Thai Ngoc Duy· Mar 25, 2010, 15:16 UTC · re: Junio C Hamano · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

2010/3/25 Junio C Hamano <gitster@pobox.com>:
Show 43 quoted lines
> * nd/setup (2010-03-21) 40 commits
>  - Guard unallowed access to repository when it's not set up
>  - alias: keep repository found while collecting aliases as long as possible
>  - Allow to undo setup_git_directory_gently() gracefully (and fix alias code)
>  - builtins: check for startup_info->help, print and exit early
>  - builtins: utilize startup_info->help where possible
>  - run_builtin(): save "-h" detection result for later use
>  - config: do not read .git/config if there is no repository
>  - apply: do not check sha1 when repository has not been found
>  - Do not read .git/info/attributes if there is no repository
>  - Do not read .git/info/exclude if there is no repository
>  - git_config(): do not read .git/config if there is no repository
>  - init/clone: turn on startup->have_repository properly
>  - worktree setup: restore original state when things go wrong
>  - Use git_config_early() instead of git_config() during repo setup
>  - Add git_config_early()
>  - worktree setup: call set_git_dir explicitly
>  - rev-parse --git-dir: print relative gitdir correctly
>  - enter_repo(): initialize other variables as setup_git_directory_gently() does
>  - Move enter_repo() to setup.c
>  - index-pack: use RUN_SETUP_GENTLY
>  - index-pack: trust the prefix returned by setup_git_directory_gently()
>  - worktree setup: calculate prefix even if no worktree is found
>  - merge-file: use RUN_SETUP_GENTLY
>  - var: use RUN_SETUP_GENTLY
>  - ls-remote: use RUN_SETUP_GENTLY
>  - help: use RUN_SETUP_GENTLY
>  - diff: use RUN_SETUP_GENTLY
>  - bundle: use RUN_SETUP_GENTLY
>  - apply: use RUN_SETUP_GENTLY
>  - verify-pack: use RUN_SETUP_GENTLY
>  - check-ref-format: use RUN_SETUP_GENTLY
>  - mailinfo: use RUN_SETUP_GENTLY
>  - archive: use RUN_SETUP_GENTLY
>  - builtin: USE_PAGER should not be used without RUN_SETUP*
>  - grep: use RUN_SETUP_GENTLY
>  - shortlog: use RUN_SETUP_GENTLY
>  - hash-object: use RUN_SETUP_GENTLY
>  - config: use RUN_SETUP_GENTLY
>  - builtin: Support RUN_SETUP_GENTLY to set up repository early if found
>  - builtin: introduce startup_info struct
>
> This seems to break t7006 when merged to 'pu'.

Unfortunately that test does not break on my machine (b745e293f). t9100 breaks though. I´m looking into it.

Can you send me ¨./t7006-* -v¨ output? If you have free time (unlikely), and the output says ¨internal error: access to .git/config without repo setup¨ or ¨internal error: setup_git_env can´t be called twice¨, can you run gdb and give me the stack trace when it die()? I could have missed some code path.

-- 
Duy
Ben Walton· Mar 26, 2010, 02:19 UTC · re: Junio C Hamano · lore

Re: What's cooking in git.git (Mar 2010, #06; Wed, 24)

Excerpts from Junio C Hamano's message of Wed Mar 24 20:41:16 -0400 2010:
Show 7 quoted lines
> * bw/git-completion-rpmspec (2010-03-20) 1 commit
>  - Add a git-completion rpm subpackage to the spec
> 
> Shipping bash-completion as part of RPM package; since Todd
> Zullinger who packages git for Fedora joined the thread, I am hoping
> that I can defer the direction of the final version to the
> discussion between Todd and Ben.

I think Todd made a good case for making this part of the core git rpm. Ian's patch would be more suited for inclusion in this case. The remaining question is whether to stick it in /etc/bash_completion.d or in /usr/share/bash_completion.d (the triggers vs direct bit).

The closer the core spec file is to the one that distro's use, the better. This is a reciprocal benefit, I think.

I'm still interested in Todd's (and anyone else') thoughts about adding the git-daemon, etc, sub-packages as part of the stock spec file. Are they too distro specific for inclusion? (eg: which user should run git-daemon[1]? default repo/cgi location for gitweb?)

Thanks -Ben

[1] The fedora spec sees git-daemon run as 'nobody' but imho, this isn't
    a good choice.  A separate 'git' user would be my preference.
-- 
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Ian Ward Comfort· Mar 26, 2010, 08:39 UTC · re: Ben Walton · lore

[PATCH] RPM spec: include bash completion support

Include the bash completion routines from the contrib/ directory in our core RPM, in the de facto standard location.

Signed-off-by: Ian Ward Comfort <icomfort@stanford.edu>
---
On 25 Mar 2010, at 7:19 PM, Ben Walton wrote:
Show 13 quoted lines
> Excerpts from Junio C Hamano's message of Wed Mar 24 20:41:16 -0400 2010:
> 
> > * bw/git-completion-rpmspec (2010-03-20) 1 commit
> > - Add a git-completion rpm subpackage to the spec
> > 
> > Shipping bash-completion as part of RPM package; since Todd Zullinger who
> > packages git for Fedora joined the thread, I am hoping that I can defer
> > the direction of the final version to the discussion between Todd and Ben.
> 
> I think Todd made a good case for making this part of the core git rpm.
> Ian's patch would be more suited for inclusion in this case. The remaining
> question is whether to stick it in /etc/bash_completion.d or in
> /usr/share/bash_completion.d (the triggers vs direct bit).
/usr/share/bash-completion was the alternative, I believe.
> The closer the core spec file is to the one that distro's use, the better.
> This is a reciprocal benefit, I think.

I agree. After more diligent research (following Todd's tip about the new upstream), I gather that bash completion works as follows on all of Fedora, EPEL, Mandriva and Gentoo. The bash-completion package itself:

* Installs a (mostly-)empty /etc/bash_completion.d directory.
* Installs numerous completion modules into /usr/share/bash-completion.
* Defines %triggers for other packages, to symlink its own completion modules
  for their binaries from /usr/share/bash-completion to /etc/bash_completion.d
  when those packages are installed.
* Induces interactive shells (via one mechanism or another) to source the
  contents of /etc/bash_completion.d.

Debian (FWIW) currently installs all completion modules directly into /etc/bash_completion.d. A promising thread from January 2009 on the upstream mailing list seemed poised to unify all these distros' treatment, but stalled after a dozen messages [1].

Unfortunately, nothing in the above clarifies how other packages are expected to ship their own completion support. Currently, however, the Git packages (and what other packages I've found with completions) in all these distros -- with the possible exception of Gentoo, which I haven't been able to verify -- install completions directly into /etc/bash_completion.d. This seems natural, given that the symlink mechanism's current function is to have completions for all and only installed packages in /etc/bash_completion.d.

I also think Todd's argument is sound, and propose that we ship bash completions in the core package in /etc/bash_completion.d/git. I don't see any reason to provide a "--without completion" option, since downstream packagers will continue to either patch or replace our spec if it doesn't meet their needs.

[1] http://lists.alioth.debian.org/pipermail/bash-completion-devel/2009-January/000670.html
-- 
Ian Ward Comfort <icomfort@stanford.edu>
Systems Team Lead, Academic Computing Services, Stanford University

 git.spec.in |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/git.spec.in b/git.spec.in
index ee74a5e..9533147 100644
--- a/git.spec.in
+++ b/git.spec.in
@@ -127,6 +127,9 @@ find $RPM_BUILD_ROOT -type f -name perllocal.pod -exec rm -f {} ';'
 rm -rf $RPM_BUILD_ROOT%{_mandir}
 %endif
 
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
+install -m 644 -T contrib/completion/git-completion.bash $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d/git
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 
@@ -136,6 +139,7 @@ rm -rf $RPM_BUILD_ROOT
 %doc README COPYING Documentation/*.txt
 %{!?_without_docs: %doc Documentation/*.html Documentation/howto}
 %{!?_without_docs: %doc Documentation/technical}
+%{_sysconfdir}/bash_completion.d
 
 %files svn
 %defattr(-,root,root)
@@ -192,6 +196,9 @@ rm -rf $RPM_BUILD_ROOT
 # No files for you!
 
 %changelog
+* Fri Mar 26 2010 Ian Ward Comfort <icomfort@stanford.edu>
+- Ship bash completion support from contrib/ in the core package.
+
 * Sun Jan 31 2010 Junio C Hamano <gitster@pobox.com>
 - Do not use %define inside %{!?...} construct.
 
-- 
1.7.0.2
Ben Walton· Mar 26, 2010, 12:10 UTC · re: Ian Ward Comfort · lore

Re: [PATCH] RPM spec: include bash completion support

Excerpts from Ian Ward Comfort's message of Fri Mar 26 04:39:57 -0400 2010:
> Include the bash completion routines from the contrib/ directory in our core
> RPM, in the de facto standard location.
> 
> Signed-off-by: Ian Ward Comfort <icomfort@stanford.edu>
Acked-by: Ben Walton <bwalton@artsci.utoronto.ca>
-- 
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Junio C Hamano· Mar 29, 2010, 18:17 UTC · re: Ben Walton · lore

Re: [PATCH] RPM spec: include bash completion support

Ben Walton <bwalton@artsci.utoronto.ca> writes:
Show 7 quoted lines
> Excerpts from Ian Ward Comfort's message of Fri Mar 26 04:39:57 -0400 2010:
>> Include the bash completion routines from the contrib/ directory in our core
>> RPM, in the de facto standard location.
>> 
>> Signed-off-by: Ian Ward Comfort <icomfort@stanford.edu>
>
> Acked-by: Ben Walton <bwalton@artsci.utoronto.ca>

Thanks all; I'll queue this and expect any further tweaks to happen in-tree if necessary before the current 1.7.1 cycle goes to feature freeze in a few days.

Julian Phillips· Mar 26, 2010, 13:07 UTC · re: Ian Ward Comfort · lore

Re: [PATCH] RPM spec: include bash completion support

On Fri, 26 Mar 2010 01:39:57 -0700, Ian Ward Comfort <icomfort@stanford.edu> wrote:

Show 8 quoted lines
> Unfortunately, nothing in the above clarifies how other packages are
> expected to ship their own completion support.  Currently, however,
> the Git packages (and what other packages I've found with completions)
> in all these distros -- with the possible exception of Gentoo, which
> I haven't been able to verify -- install completions directly into
> /etc/bash_completion.d.  This seems natural, given that the symlink
> mechanism's current function is to have completions for all and only
> installed packages in /etc/bash_completion.d.

FWIW, Gentoo installs the completion script as /usr/share/bash-completion/git - since installing a package isn't supposed to enable completion but only to make it available. Since Gentoo doesn't use RPMs this isn't actually relevant though ;).

-- 
Julian

← back to recent threads