Skip to content

Commit

Permalink
Merge branch 'maint' to sync with 1.6.5.7
Browse files Browse the repository at this point in the history
* maint:
  Git 1.6.5.7
  worktree: don't segfault with an absolute pathspec without a work tree
  ignore unknown color configuration
  help.autocorrect: do not run a command if the command given is junk
  Illustrate "filter" attribute with an example
  • Loading branch information
Junio C Hamano committed Dec 16, 2009
2 parents e25e2b4 + 527b9d7 commit a1bb8f4
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 8 deletions.
19 changes: 19 additions & 0 deletions Documentation/RelNotes-1.6.5.7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Git v1.6.5.7 Release Notes
==========================

Fixes since v1.6.5.6
--------------------

* If a user specifies a color for a <slot> (i.e. a class of things to show
in a particular color) that is known only by newer versions of git
(e.g. "color.diff.func" was recently added for upcoming 1.6.6 release),
an older version of git should just ignore them. Instead we diagnosed
it as an error.

* With help.autocorrect set to non-zero value, the logic to guess typoes
in the subcommand name misfired and ran a random nonsense command.

* If a command is run with an absolute path as a pathspec inside a bare
repository, e.g. "rev-list HEAD -- /home", the code tried to run
strlen() on NULL, which is the result of get_git_work_tree(), and
segfaulted.
3 changes: 2 additions & 1 deletion Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ unreleased) version of git, that is available from 'master'
branch of the `git.git` repository.
Documentation for older releases are available here:

* link:v1.6.5.6/git.html[documentation for release 1.6.5.6]
* link:v1.6.5.7/git.html[documentation for release 1.6.5.7]

* release notes for
link:RelNotes-1.6.5.7.txt[1.6.5.7],
link:RelNotes-1.6.5.6.txt[1.6.5.6],
link:RelNotes-1.6.5.5.txt[1.6.5.5],
link:RelNotes-1.6.5.4.txt[1.6.5.4],
Expand Down
19 changes: 19 additions & 0 deletions Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ intent is that if someone unsets the filter driver definition,
or does not have the appropriate filter program, the project
should still be usable.

For example, in .gitattributes, you would assign the `filter`
attribute for paths.

------------------------
*.c filter=indent
------------------------

Then you would define a "filter.indent.clean" and "filter.indent.smudge"
configuration in your .git/config to specify a pair of commands to
modify the contents of C programs when the source files are checked
in ("clean" is run) and checked out (no change is made because the
command is "cat").

------------------------
[filter "indent"]
clean = indent
smudge = cat
------------------------


Interaction between checkin/checkout attributes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
return BRANCH_COLOR_LOCAL;
if (!strcasecmp(var+ofs, "current"))
return BRANCH_COLOR_CURRENT;
die("bad config variable '%s'", var);
return -1;
}

static int git_branch_config(const char *var, const char *value, void *cb)
Expand All @@ -76,6 +76,8 @@ static int git_branch_config(const char *var, const char *value, void *cb)
}
if (!prefixcmp(var, "color.branch.")) {
int slot = parse_branch_color_slot(var, 13);
if (slot < 0)
return 0;
if (!value)
return config_error_nonbool(var);
color_parse(value, var, branch_colors[slot]);
Expand Down
4 changes: 3 additions & 1 deletion builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ static int parse_status_slot(const char *var, int offset)
return WT_STATUS_NOBRANCH;
if (!strcasecmp(var+offset, "unmerged"))
return WT_STATUS_UNMERGED;
die("bad config variable '%s'", var);
return -1;
}

static int git_status_config(const char *k, const char *v, void *cb)
Expand All @@ -910,6 +910,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
}
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
int slot = parse_status_slot(k, 13);
if (slot < 0)
return 0;
if (!v)
return config_error_nonbool(k);
color_parse(v, k, s->color_palette[slot]);
Expand Down
4 changes: 3 additions & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int parse_diff_color_slot(const char *var, int ofs)
return DIFF_WHITESPACE;
if (!strcasecmp(var+ofs, "func"))
return DIFF_FUNCINFO;
die("bad config variable '%s'", var);
return -1;
}

static int git_config_rename(const char *var, const char *value)
Expand Down Expand Up @@ -122,6 +122,8 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)

if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
int slot = parse_diff_color_slot(var, 11);
if (slot < 0)
return 0;
if (!value)
return config_error_nonbool(var);
color_parse(value, var, diff_colors[slot]);
Expand Down
7 changes: 5 additions & 2 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
old->names = NULL;
}

/* An empirically derived magic number */
#define SIMILAR_ENOUGH(x) ((x) < 6)

const char *help_unknown_cmd(const char *cmd)
{
int i, n, best_similarity = 0;
Expand Down Expand Up @@ -331,7 +334,7 @@ const char *help_unknown_cmd(const char *cmd)
n = 1;
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
++n;
if (autocorrect && n == 1) {
if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
const char *assumed = main_cmds.names[0]->name;
main_cmds.names[0] = NULL;
clean_cmdnames(&main_cmds);
Expand All @@ -349,7 +352,7 @@ const char *help_unknown_cmd(const char *cmd)

fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);

if (best_similarity < 6) {
if (SIMILAR_ENOUGH(best_similarity)) {
fprintf(stderr, "\nDid you mean %s?\n",
n < 2 ? "this": "one of these");

Expand Down
7 changes: 5 additions & 2 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const char *prefix_path(const char *prefix, int len, const char *path)
if (normalize_path_copy(sanitized, sanitized))
goto error_out;
if (is_absolute_path(orig)) {
size_t len, total;
const char *work_tree = get_git_work_tree();
size_t len = strlen(work_tree);
size_t total = strlen(sanitized) + 1;
if (!work_tree)
goto error_out;
len = strlen(work_tree);
total = strlen(sanitized) + 1;
if (strncmp(sanitized, work_tree, len) ||
(sanitized[len] != '\0' && sanitized[len] != '/')) {
error_out:
Expand Down
15 changes: 15 additions & 0 deletions t/t1501-worktree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@ test_expect_success 'git grep' '
GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)
'

test_expect_success 'git commit' '
(
cd repo.git &&
GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done
)
'

test_expect_success 'absolute pathspec should fail gracefully' '
(
cd repo.git || exit 1
git config --unset core.worktree
test_must_fail git log HEAD -- /home
)
'

test_done
17 changes: 17 additions & 0 deletions t/t4026-color.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ test_expect_success 'extra character after attribute' '
invalid_color "dimX"
'

test_expect_success 'unknown color slots are ignored (diff)' '
git config --unset diff.color.new
git config color.diff.nosuchslotwilleverbedefined white &&
git diff --color
'

test_expect_success 'unknown color slots are ignored (branch)' '
git config color.branch.nosuchslotwilleverbedefined white &&
git branch -a
'

test_expect_success 'unknown color slots are ignored (status)' '
git config color.status.nosuchslotwilleverbedefined white || exit
git status
case $? in 0|1) : ok ;; *) false ;; esac
'

test_done

0 comments on commit a1bb8f4

Please sign in to comment.