Skip to content

Commit 5d477a3

Browse files
dschogitster
authored andcommitted
fsck (receive-pack): allow demoting errors to warnings
For example, missing emails in commit and tag objects can be demoted to mere warnings with git config receive.fsck.missingemail=warn The value is actually a comma-separated list. In case that the same key is listed in multiple receive.fsck.<msg-id> lines in the config, the latter configuration wins (this can happen for example when both $HOME/.gitconfig and .git/config contain message type settings). As git receive-pack does not actually perform the checks, it hands off the setting to index-pack or unpack-objects in the form of an optional argument to the --strict option. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0282f4d commit 5d477a3

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

builtin/index-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
16331633
} else if (!strcmp(arg, "--strict")) {
16341634
strict = 1;
16351635
do_fsck_object = 1;
1636+
} else if (skip_prefix(arg, "--strict=", &arg)) {
1637+
strict = 1;
1638+
do_fsck_object = 1;
1639+
fsck_set_msg_types(&fsck_options, arg);
16361640
} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
16371641
strict = 1;
16381642
check_self_contained_and_connected = 1;

builtin/receive-pack.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "tag.h"
2020
#include "gpg-interface.h"
2121
#include "sigchain.h"
22+
#include "fsck.h"
2223

2324
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
2425

@@ -36,6 +37,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
3637
static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
3738
static int receive_fsck_objects = -1;
3839
static int transfer_fsck_objects = -1;
40+
static struct strbuf fsck_msg_types = STRBUF_INIT;
3941
static int receive_unpack_limit = -1;
4042
static int transfer_unpack_limit = -1;
4143
static int advertise_atomic_push = 1;
@@ -115,6 +117,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
115117
return 0;
116118
}
117119

120+
if (skip_prefix(var, "receive.fsck.", &var)) {
121+
if (is_valid_msg_type(var, value))
122+
strbuf_addf(&fsck_msg_types, "%c%s=%s",
123+
fsck_msg_types.len ? ',' : '=', var, value);
124+
else
125+
warning("Skipping unknown msg id '%s'", var);
126+
return 0;
127+
}
128+
118129
if (strcmp(var, "receive.fsckobjects") == 0) {
119130
receive_fsck_objects = git_config_bool(var, value);
120131
return 0;
@@ -1490,7 +1501,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
14901501
if (quiet)
14911502
argv_array_push(&child.args, "-q");
14921503
if (fsck_objects)
1493-
argv_array_push(&child.args, "--strict");
1504+
argv_array_pushf(&child.args, "--strict%s",
1505+
fsck_msg_types.buf);
14941506
child.no_stdout = 1;
14951507
child.err = err_fd;
14961508
child.git_cmd = 1;
@@ -1508,7 +1520,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
15081520
argv_array_pushl(&child.args, "index-pack",
15091521
"--stdin", hdr_arg, keep_arg, NULL);
15101522
if (fsck_objects)
1511-
argv_array_push(&child.args, "--strict");
1523+
argv_array_pushf(&child.args, "--strict%s",
1524+
fsck_msg_types.buf);
15121525
if (fix_thin)
15131526
argv_array_push(&child.args, "--fix-thin");
15141527
child.out = -1;

builtin/unpack-objects.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
530530
strict = 1;
531531
continue;
532532
}
533+
if (skip_prefix(arg, "--strict=", &arg)) {
534+
strict = 1;
535+
fsck_set_msg_types(&fsck_options, arg);
536+
continue;
537+
}
533538
if (starts_with(arg, "--pack_header=")) {
534539
struct pack_header *hdr;
535540
char *c;

fsck.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ static int parse_msg_type(const char *str)
131131
die("Unknown fsck message type: '%s'", str);
132132
}
133133

134+
int is_valid_msg_type(const char *msg_id, const char *msg_type)
135+
{
136+
if (parse_msg_id(msg_id) < 0)
137+
return 0;
138+
parse_msg_type(msg_type);
139+
return 1;
140+
}
141+
134142
void fsck_set_msg_type(struct fsck_options *options,
135143
const char *msg_id, const char *msg_type)
136144
{

fsck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct fsck_options;
99
void fsck_set_msg_type(struct fsck_options *options,
1010
const char *msg_id, const char *msg_type);
1111
void fsck_set_msg_types(struct fsck_options *options, const char *values);
12+
int is_valid_msg_type(const char *msg_id, const char *msg_type);
1213

1314
/*
1415
* callback function for fsck_walk

0 commit comments

Comments
 (0)