Skip to content

Commit a1bb8f4

Browse files
committed
Merge branch 'maint' to sync with 1.6.5.7
* 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
2 parents e25e2b4 + 527b9d7 commit a1bb8f4

File tree

10 files changed

+91
-8
lines changed

10 files changed

+91
-8
lines changed

Documentation/RelNotes-1.6.5.7.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Git v1.6.5.7 Release Notes
2+
==========================
3+
4+
Fixes since v1.6.5.6
5+
--------------------
6+
7+
* If a user specifies a color for a <slot> (i.e. a class of things to show
8+
in a particular color) that is known only by newer versions of git
9+
(e.g. "color.diff.func" was recently added for upcoming 1.6.6 release),
10+
an older version of git should just ignore them. Instead we diagnosed
11+
it as an error.
12+
13+
* With help.autocorrect set to non-zero value, the logic to guess typoes
14+
in the subcommand name misfired and ran a random nonsense command.
15+
16+
* If a command is run with an absolute path as a pathspec inside a bare
17+
repository, e.g. "rev-list HEAD -- /home", the code tried to run
18+
strlen() on NULL, which is the result of get_git_work_tree(), and
19+
segfaulted.

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ unreleased) version of git, that is available from 'master'
4343
branch of the `git.git` repository.
4444
Documentation for older releases are available here:
4545

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

4848
* release notes for
49+
link:RelNotes-1.6.5.7.txt[1.6.5.7],
4950
link:RelNotes-1.6.5.6.txt[1.6.5.6],
5051
link:RelNotes-1.6.5.5.txt[1.6.5.5],
5152
link:RelNotes-1.6.5.4.txt[1.6.5.4],

Documentation/gitattributes.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ intent is that if someone unsets the filter driver definition,
197197
or does not have the appropriate filter program, the project
198198
should still be usable.
199199

200+
For example, in .gitattributes, you would assign the `filter`
201+
attribute for paths.
202+
203+
------------------------
204+
*.c filter=indent
205+
------------------------
206+
207+
Then you would define a "filter.indent.clean" and "filter.indent.smudge"
208+
configuration in your .git/config to specify a pair of commands to
209+
modify the contents of C programs when the source files are checked
210+
in ("clean" is run) and checked out (no change is made because the
211+
command is "cat").
212+
213+
------------------------
214+
[filter "indent"]
215+
clean = indent
216+
smudge = cat
217+
------------------------
218+
200219

201220
Interaction between checkin/checkout attributes
202221
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

builtin-branch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int parse_branch_color_slot(const char *var, int ofs)
6565
return BRANCH_COLOR_LOCAL;
6666
if (!strcasecmp(var+ofs, "current"))
6767
return BRANCH_COLOR_CURRENT;
68-
die("bad config variable '%s'", var);
68+
return -1;
6969
}
7070

7171
static int git_branch_config(const char *var, const char *value, void *cb)
@@ -76,6 +76,8 @@ static int git_branch_config(const char *var, const char *value, void *cb)
7676
}
7777
if (!prefixcmp(var, "color.branch.")) {
7878
int slot = parse_branch_color_slot(var, 13);
79+
if (slot < 0)
80+
return 0;
7981
if (!value)
8082
return config_error_nonbool(var);
8183
color_parse(value, var, branch_colors[slot]);

builtin-commit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static int parse_status_slot(const char *var, int offset)
890890
return WT_STATUS_NOBRANCH;
891891
if (!strcasecmp(var+offset, "unmerged"))
892892
return WT_STATUS_UNMERGED;
893-
die("bad config variable '%s'", var);
893+
return -1;
894894
}
895895

896896
static int git_status_config(const char *k, const char *v, void *cb)
@@ -910,6 +910,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
910910
}
911911
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
912912
int slot = parse_status_slot(k, 13);
913+
if (slot < 0)
914+
return 0;
913915
if (!v)
914916
return config_error_nonbool(k);
915917
color_parse(v, k, s->color_palette[slot]);

diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int parse_diff_color_slot(const char *var, int ofs)
6363
return DIFF_WHITESPACE;
6464
if (!strcasecmp(var+ofs, "func"))
6565
return DIFF_FUNCINFO;
66-
die("bad config variable '%s'", var);
66+
return -1;
6767
}
6868

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

123123
if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
124124
int slot = parse_diff_color_slot(var, 11);
125+
if (slot < 0)
126+
return 0;
125127
if (!value)
126128
return config_error_nonbool(var);
127129
color_parse(value, var, diff_colors[slot]);

help.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
297297
old->names = NULL;
298298
}
299299

300+
/* An empirically derived magic number */
301+
#define SIMILAR_ENOUGH(x) ((x) < 6)
302+
300303
const char *help_unknown_cmd(const char *cmd)
301304
{
302305
int i, n, best_similarity = 0;
@@ -331,7 +334,7 @@ const char *help_unknown_cmd(const char *cmd)
331334
n = 1;
332335
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
333336
++n;
334-
if (autocorrect && n == 1) {
337+
if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
335338
const char *assumed = main_cmds.names[0]->name;
336339
main_cmds.names[0] = NULL;
337340
clean_cmdnames(&main_cmds);
@@ -349,7 +352,7 @@ const char *help_unknown_cmd(const char *cmd)
349352

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

352-
if (best_similarity < 6) {
355+
if (SIMILAR_ENOUGH(best_similarity)) {
353356
fprintf(stderr, "\nDid you mean %s?\n",
354357
n < 2 ? "this": "one of these");
355358

setup.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const char *prefix_path(const char *prefix, int len, const char *path)
1818
if (normalize_path_copy(sanitized, sanitized))
1919
goto error_out;
2020
if (is_absolute_path(orig)) {
21+
size_t len, total;
2122
const char *work_tree = get_git_work_tree();
22-
size_t len = strlen(work_tree);
23-
size_t total = strlen(sanitized) + 1;
23+
if (!work_tree)
24+
goto error_out;
25+
len = strlen(work_tree);
26+
total = strlen(sanitized) + 1;
2427
if (strncmp(sanitized, work_tree, len) ||
2528
(sanitized[len] != '\0' && sanitized[len] != '/')) {
2629
error_out:

t/t1501-worktree.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,19 @@ test_expect_success 'git grep' '
174174
GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)
175175
'
176176

177+
test_expect_success 'git commit' '
178+
(
179+
cd repo.git &&
180+
GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done
181+
)
182+
'
183+
184+
test_expect_success 'absolute pathspec should fail gracefully' '
185+
(
186+
cd repo.git || exit 1
187+
git config --unset core.worktree
188+
test_must_fail git log HEAD -- /home
189+
)
190+
'
191+
177192
test_done

t/t4026-color.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,21 @@ test_expect_success 'extra character after attribute' '
6666
invalid_color "dimX"
6767
'
6868

69+
test_expect_success 'unknown color slots are ignored (diff)' '
70+
git config --unset diff.color.new
71+
git config color.diff.nosuchslotwilleverbedefined white &&
72+
git diff --color
73+
'
74+
75+
test_expect_success 'unknown color slots are ignored (branch)' '
76+
git config color.branch.nosuchslotwilleverbedefined white &&
77+
git branch -a
78+
'
79+
80+
test_expect_success 'unknown color slots are ignored (status)' '
81+
git config color.status.nosuchslotwilleverbedefined white || exit
82+
git status
83+
case $? in 0|1) : ok ;; *) false ;; esac
84+
'
85+
6986
test_done

0 commit comments

Comments
 (0)