Introduce an internal API to interact with the fsck machinery
cover Introduce an internal API to interact with the fsck machinery
At the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.
This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.
I am proud to report that this work has been sponsored by GitHub.
Johannes Schindelin (18):
Introduce fsck options
Introduce identifiers for fsck messages
Provide a function to parse fsck message IDs
Offer a function to demote fsck errors to warnings Allow demoting errors to warnings via receive.fsck.<key> = warn
fsck: report the ID of the error/warning
Make fsck_ident() warn-friendly
Make fsck_commit() warn-friendly
fsck: handle multiple authors in commits specially Make fsck_tag() warn-friendly
Add a simple test for receive.fsck.*
Disallow demoting grave fsck errors to warnings Optionally ignore specific fsck issues completely
fsck: allow upgrading fsck warnings to errors Document the new receive.fsck.* options.
fsck: support demoting errors to warnings
Introduce git fsck --quick
git receive-pack: support excluding objects from fsck'ing
Documentation/config.txt | 27 +++ Documentation/git-fsck.txt | 7 +- builtin/fsck.c | 66 ++++-- builtin/index-pack.c | 13 +- builtin/receive-pack.c | 36 ++- builtin/unpack-objects.c | 16 +- fsck.c | 512 +++++++++++++++++++++++++++++++--------- fsck.h | 28 ++- t/t1450-fsck.sh | 33 +++ t/t5302-pack-index.sh | 2 +- t/t5504-fetch-receive-strict.sh | 46 ++++ 11 files changed, 624 insertions(+), 162 deletions(-)
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 1/18 Introduce fsck options
Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.
--- builtin/fsck.c | 20 +++++-- builtin/index-pack.c | 9 +-- builtin/unpack-objects.c | 11 ++-- fsck.c | 150 +++++++++++++++++++++++------------------------ fsck.h | 17 +++++- 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
@@ -25,6 +25,8 @@ static int include_reflogs = 1;static int check_full =1 ;static int check_strict;static int keep_cache_objects; +static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;static unsigned char head_sha1[20 ];static const char *head_points_at;static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)static struct object_array pending; -static int mark_object (struct object *obj,int type,void *data) +static int mark_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct object *parent = data;
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)static void mark_object_reachable (struct object *obj) { -mark_object (obj,OBJ_ANY ,NULL ); +mark_object (obj,OBJ_ANY ,NULL ,NULL ); }static int traverse_one_object (struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)if (parse_tree (tree) <0 )return 1 ;/* error already displayed */ } - result =fsck_walk (obj, mark_object, obj); + result =fsck_walk (obj, obj, &fsck_walk_options);if (tree)free_tree_buffer (tree);return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data) +static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return 1 ;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)fprintf (stderr,"Checking %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); -if (fsck_walk (obj, mark_used,NULL )) +if (fsck_walk (obj,NULL , &fsck_obj_options))objerror (obj,"broken links" ); -if (fsck_object (obj,NULL ,0 , check_strict, fsck_error_func)) +if (fsck_object (obj,NULL ,0 , &fsck_obj_options))return -1 ;if (obj->type ==OBJ_TREE ) {
@@ -630,6 +632,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, fsck_opts, fsck_usage,0 ); + fsck_walk_options.walk = mark_object; + fsck_obj_options.walk = mark_used; + fsck_obj_options.error_func = fsck_error_func; +if (check_strict) + fsck_obj_options.strict =1 ; +if (show_progress ==-1 ) show_progress =isatty (2 );if (verbose)
builtin/index-pack.c +5 -4
@@ -74,6 +74,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static int verbose;static int show_stat;static int check_self_contained_and_connected;
@@ -191,7 +192,7 @@ static void cleanup_thread(void)#endif -static int mark_link (struct object *obj,int type,void *data) +static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return -1 ;
@@ -782,10 +783,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,if (!obj)die (_ ("invalid %s" ),typename (type));if (do_fsck_object && -fsck_object (obj, buf, size,1 , - fsck_error_function)) +fsck_object (obj, buf, size, &fsck_options))die (_ ("Error in object" )); -if (fsck_walk (obj, mark_link,NULL )) + fsck_options.walk = mark_link; +if (fsck_walk (obj,NULL , &fsck_options))die (_ ("Not all child objects of %s are reachable" ),sha1_to_hex (obj->sha1));if (obj->type ==OBJ_TREE ) {
builtin/unpack-objects.c +6 -5
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];static unsigned int offset, len;static off_t consumed_bytes;static git_SHA_CTX ctx; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;/* * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data) +static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data) obj_buf =lookup_object_buffer (obj);if (!obj_buf)die ("Whoops! Cannot find object '%s'" ,sha1_to_hex (obj->sha1)); -if (fsck_object (obj, obj_buf->buffer, obj_buf->size,1 , - fsck_error_function)) +if (fsck_object (obj, obj_buf->buffer, obj_buf->size, &fsck_options))die ("Error in object" ); -if (fsck_walk (obj, check_object,NULL )) + fsck_options.walk = check_object; +if (fsck_walk (obj,NULL , &fsck_options))die ("Error on reachable objects of %s" ,sha1_to_hex (obj->sha1));write_cached_object (obj, obj_buf);return 0 ;
@@ -217,7 +218,7 @@ static void write_rest(void)unsigned i;for (i =0 ; i < nr_objects; i++) {if (obj_list[i].obj) -check_object (obj_list[i].obj,OBJ_ANY ,NULL ); +check_object (obj_list[i].obj,OBJ_ANY ,NULL ,NULL ); } }
fsck.c +75 -75
391 lines not on this page · raw message
fsck.h +14 -3
@@ -4,6 +4,8 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +struct fsck_options ; +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data); +typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); __attribute__((format (printf,3 ,4 )))int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +int strict:1 ; +}; + +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +/* descend in all linked child objects * the return value is: * -1 error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);* >0 return value of the first signaled error >0 (in the case of no other errors) * 0 everything OK */ -int fsck_walk (struct object *obj,fsck_walk_func walk,void *data); +int fsck_walk (struct object *obj,void *data,struct fsck_options *options);/* If NULL is passed for data, we assume the object is local and read it. */ int fsck_object (struct object *obj,void *data,unsigned long size, -int strict,fsck_error error_func); +struct fsck_options *options);#endif
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 2/18 Introduce identifiers for fsck messages
In reply to Johannes SchindelinRather than specifying only whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.
In the course, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.
--- builtin/fsck.c | 24 +++----- fsck.c | 185 +++++++++++++++++++++++++++++++++++++++------------------ fsck.h | 5 +- 3 files changed, 137 insertions(+), 77 deletions(-)
builtin/fsck.c +7 -17
@@ -47,32 +47,22 @@ static int show_dangling = 1;#endif static void objreport (struct object *obj,const char *severity, -const char *err,va_list params) +const char *err) { -fprintf (stderr,"%s in %s %s: " , - severity,typename (obj->type),sha1_to_hex (obj->sha1)); -vfprintf (stderr, err, params); -fputs ("\n" , stderr); +fprintf (stderr,"%s in %s %s: %s\n" , + severity,typename (obj->type),sha1_to_hex (obj->sha1), err); } -__attribute__((format (printf,2 ,3 ))) -static int objerror (struct object *obj,const char *err, ...) +static int objerror (struct object *obj,const char *err) { -va_list params; -va_start (params, err); errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err, params); -va_end (params); +objreport (obj,"error" , err);return -1 ; } -__attribute__((format (printf,3 ,4 ))) -static int fsck_error_func (struct object *obj,int type,const char *err, ...) +static int fsck_error_func (struct object *obj,int type,const char *message) { -va_list params; -va_start (params, err); -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , err, params); -va_end (params); +objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message);return (type ==FSCK_WARN ) ?0 :1 ; }
fsck.c +128 -57
339 lines not on this page · raw message
fsck.h +2 -3
@@ -17,10 +17,9 @@ struct fsck_options;typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ -typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...); +typedef int (*fsck_error )(struct object *obj,int type,const char *message); -__attribute__((format (printf,3 ,4 ))) -int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +int fsck_error_function (struct object *obj,int type,const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 3/18 Provide a function to parse fsck message IDs
In reply to Johannes SchindelinThis function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines.
To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both "missing-email" and "missingEmail" will match the "MISSING_EMAIL" key).
--- fsck.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
fsck.c +32 -0
@@ -63,6 +63,38 @@ enum fsck_msg_id {FSCK_MSG_MAX }; +#define STR (x) #x +#define MSG_ID_STR (x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX +1 ] = { +FOREACH_MSG_ID (MSG_ID_STR ) + NULL +}; + +static int parse_msg_id (const char *text,int len) +{ +int i, j; + +for (i =0 ; i <FSCK_MSG_MAX ; i++) { +const char *key = msg_id_str[i]; +/* msg_id_str is upper-case, with underscores */ +for (j =0 ; j < len; j++) { +char c = *(key++); +if (c =='_' ) { +if (isalpha (text[j])) + c = *(key++); +else if (text[j] !='_' ) + c ='-' ; + } +if (toupper (text[j]) != c) +break ; + } +if (j == len && !*key) +return i; + } + +die ("Unhandled type: %.*s" , len, text); +} +int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) {return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 4/18 Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinThere are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.
The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all FSCK_ERROR in those cases.
--- fsck.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fsck.h | 7 +++++-- 2 files changed, 63 insertions(+), 2 deletions(-)
fsck.c +58 -0
@@ -97,9 +97,63 @@ static int parse_msg_id(const char *text, int len)int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { +if (options->strict_mode && msg_id >=0 && msg_id <FSCK_MSG_MAX ) +return options->strict_mode[msg_id]; +if (options->strict) +return FSCK_ERROR ;return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ; } +static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +} + +void fsck_strict_mode (struct fsck_options *options,const char *mode) +{ +int type =FSCK_ERROR ; + +if (!options->strict_mode) { +int i; +int *strict_mode =malloc (sizeof (int ) *FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + strict_mode[i] =fsck_msg_type (i, options); + options->strict_mode = strict_mode; + } + +while (*mode) { +int len =strcspn (mode," ,|" ), equal, msg_id; + +if (!len) { + mode++; +continue ; + } + +for (equal =0 ; equal < len; equal++) +if (mode[equal] =='=' ) +break ; + +if (equal < len) { +const char *type_str = mode + equal +1 ; +int type_len = len - equal -1 ; +if (!substrcmp (type_str, type_len,"error" )) + type =FSCK_ERROR ; +else if (!substrcmp (type_str, type_len,"warn" )) + type =FSCK_WARN ; +else +die ("Unknown fsck message type: '%.*s'" , + len - equal -1 , type_str); + } + + msg_id =parse_msg_id (mode, equal); + options->strict_mode[msg_id] = type; + mode += len; + } +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -585,6 +639,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct object *obj,int type,const char *message) { +if (type ==FSCK_WARN ) { +warning ("object %s: %s" ,sha1_to_hex (obj->sha1), message); +return 0 ; + }error ("object %s: %s" ,sha1_to_hex (obj->sha1), message);return 1 ; }
fsck.h +5 -2
@@ -6,6 +6,8 @@struct fsck_options ; +void fsck_strict_mode (struct fsck_options *options,const char *mode); +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -25,10 +27,11 @@ struct fsck_options {fsck_walk_func walk;fsck_error error_func; int strict:1; +int *strict_mode; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 5/18 Allow demoting errors to warnings via receive.fsck.<key> = warn
In reply to Johannes SchindelinFor example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.missing-email warn
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.
--- builtin/index-pack.c | 4 ++++ builtin/receive-pack.c | 27 +++++++++++++++++++++++---- builtin/unpack-objects.c | 5 +++++ 3 files changed, 32 insertions(+), 4 deletions(-)
builtin/index-pack.c +4 -0
@@ -1565,6 +1565,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (!strcmp (arg,"--strict" )) { strict =1 ; do_fsck_object =1 ; + }else if (starts_with (arg,"--strict=" )) { + strict =1 ; + do_fsck_object =1 ; +fsck_strict_mode (&fsck_options, arg +9 ); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +23 -4
@@ -35,6 +35,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; +static struct strbuf fsck_strict_mode =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int unpack_limit =100 ;
@@ -109,6 +110,14 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck." )) { +if (fsck_strict_mode.len) +strbuf_addch (&fsck_strict_mode,',' ); +strbuf_addf (&fsck_strict_mode, +"%s=%s" , var +13 , value ? value :"error" ); +return 0 ; + } +if (strcmp (var,"receive.fsckobjects" ) ==0 ) { receive_fsck_objects =git_config_bool (var, value);return 0 ;
@@ -1266,8 +1275,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"unpack-objects" , hdr_arg,NULL );if (quiet)argv_array_push (&child.args,"-q" ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_strict_mode.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_strict_mode.buf); +else +argv_array_push (&child.args,"--strict" ); + } child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1284,8 +1298,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_strict_mode.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_strict_mode.buf); +else +argv_array_push (&child.args,"--strict" ); + }if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +5 -0
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } +if (starts_with (arg,"--strict=" )) { + strict =1 ; +fsck_strict_mode (&fsck_options, arg +9 ); +continue ; + }if (starts_with (arg,"--pack_header=" )) {struct pack_header *hdr;char *c;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 6/18 fsck: report the ID of the error/warning
In reply to Johannes SchindelinSome legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missing-email", the user might want to call git config receive.fsck.missing-email warn).
--- fsck.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fsck.c +19 -0
@@ -154,6 +154,23 @@ void fsck_strict_mode(struct fsck_options *options, const char *mode) } } +static void append_msg_id (struct strbuf *sb,const char *msg_id) +{ +for (;;) { +char c = *(msg_id)++; + +if (!c) +break ; +if (c =='_' ) + c ='-' ; +else + c =tolower (c); +strbuf_addch (sb, c); + } + +strbuf_addstr (sb,": " ); +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -162,6 +179,8 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_type =fsck_msg_type (id, options), result; +append_msg_id (&sb, msg_id_str[id]); +va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (object, msg_type, sb.buf);
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 7/18 Make fsck_ident() warn-friendly
In reply to Johannes SchindelinWhen fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.
--- fsck.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
@@ -444,40 +444,45 @@ static int require_end_of_header(const void *data, unsigned long size,static int fsck_ident (const char **ident,struct object *obj,struct fsck_options *options) { +const char *p = *ident;char *end; -if (**ident =='<' ) + *ident =strchrnul (*ident,'\n' ); +if (**ident =='\n' ) + (*ident)++; + +if (*p =='<' )return report (options, obj,FSCK_MSG_MISSING_NAME_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - *ident +=strcspn (*ident,"<>\n" ); -if (**ident =='>' ) + p +=strcspn (p,"<>\n" ); +if (*p =='>' )return report (options, obj,FSCK_MSG_BAD_NAME ,"invalid author/committer line - bad name" ); -if (**ident !='<' ) +if (*p !='<' )return report (options, obj,FSCK_MSG_MISSING_EMAIL ,"invalid author/committer line - missing email" ); -if ((*ident)[-1 ] !=' ' ) +if (p[-1 ] !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - (*ident)++; - *ident +=strcspn (*ident,"<>\n" ); -if (**ident !='>' ) + p++; + p +=strcspn (p,"<>\n" ); +if (*p !='>' )return report (options, obj,FSCK_MSG_BAD_EMAIL ,"invalid author/committer line - bad email" ); - (*ident)++; -if (**ident !=' ' ) + p++; +if (*p !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_DATE ,"invalid author/committer line - missing space before date" ); - (*ident)++; -if (**ident =='0' && (*ident)[1 ] !=' ' ) + p++; +if (*p =='0' && p[1 ] !=' ' )return report (options, obj,FSCK_MSG_ZERO_PADDED_DATE ,"invalid author/committer line - zero-padded date" ); -if (date_overflows (strtoul (*ident, &end,10 ))) +if (date_overflows (strtoul (p, &end,10 )))return report (options, obj,FSCK_MSG_DATE_OVERFLOW ,"invalid author/committer line - date causes integer overflow" ); -if (end == *ident || *end !=' ' ) +if ((end == p || *end !=' ' ))return report (options, obj,FSCK_MSG_BAD_DATE ,"invalid author/committer line - bad date" ); - *ident = end +1 ; -if ((**ident !='+' && **ident !='-' ) || - !isdigit ((*ident)[1 ]) || - !isdigit ((*ident)[2 ]) || - !isdigit ((*ident)[3 ]) || - !isdigit ((*ident)[4 ]) || - ((*ident)[5 ] !='\n' )) + p = end +1 ; +if ((*p !='+' && *p !='-' ) || + !isdigit (p[1 ]) || + !isdigit (p[2 ]) || + !isdigit (p[3 ]) || + !isdigit (p[4 ]) || + (p[5 ] !='\n' ))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - (*ident) +=6 ; + p +=6 ;return 0 ; }
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 8/18 Make fsck_commit() warn-friendly
In reply to Johannes SchindelinWhen fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missing-author error to a warning would hide a problematic committer line.
--- fsck.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
@@ -499,12 +499,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (!skip_prefix (buffer,"tree " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_TREE ,"invalid format - expected 'tree' line" ); -if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ;while (skip_prefix (buffer,"parent " , &buffer)) { -if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ; parent_line_count++; }
@@ -513,11 +519,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (graft) {if (graft->nr_parent ==-1 && !parent_count) ;/* shallow commit */ -else if (graft->nr_parent != parent_count) -return report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +else if (graft->nr_parent != parent_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +if (err) +return err; + } }else { -if (parent_count != parent_line_count) -return report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (parent_count != parent_line_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (err) +return err; + } }if (!skip_prefix (buffer,"author " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_AUTHOR ,"invalid format - expected 'author' line" );
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 9/18 fsck: handle multiple authors in commits specially
In reply to Johannes SchindelinThis problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
Technically, we could handle such repositories by setting missing-committer = warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.
--- fsck.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fsck.c +8 -0
@@ -37,6 +37,7 @@ FUNC(MISSING_TREE) \ FUNC(MISSING_TYPE) \ FUNC(MISSING_TYPE_ENTRY) \ + FUNC(MULTIPLE_AUTHORS) \ FUNC(NOT_SORTED) \ FUNC(NUL_IN_HEADER) \ FUNC(TAG_OBJECT_NOT_TAG) \
@@ -536,6 +537,13 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, err =fsck_ident (&buffer, &commit->object, options);if (err)return err; +while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err; +/* require_end_of_header() ensured that there is a newline */ + buffer =strchr (buffer,'\n' ) +1 ; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 10/18 Make fsck_tag() warn-friendly
In reply to Johannes SchindelinWhen fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.
--- fsck.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
@@ -604,7 +604,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, }if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { ret =report (options, &tag->object,FSCK_MSG_INVALID_OBJECT_SHA1 ,"invalid 'object' line format - bad sha1" ); - goto done; +if (ret) + goto done; } buffer +=41 ;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 11/18 Add a simple test for receive.fsck.*
In reply to Johannes Schindelin--- t/t5504-fetch-receive-strict.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
t/t5504-fetch-receive-strict.sh +20 -0
@@ -115,4 +115,24 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' +cat >bogus-commit << EOF +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +author Bugs Bunny 1234567890 +0000 +committer Bugs Bunny <[email protected]> 1234567890 +0000 + +This commit object intentionally broken +EOF + +test_expect_success 'push with receive.fsck.missing-mail = warn' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.missing-email warn && + git push --porcelain dst bogus >act 2>&1 && + grep "missing-email" act +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 12/18 Disallow demoting grave fsck errors to warnings
In reply to Johannes SchindelinSome kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
--- fsck.c | 8 ++++++-- t/t5504-fetch-receive-strict.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
fsck.c +6 -2
@@ -9,6 +9,9 @@#include "refs.h" #define FOREACH_MSG_ID (FUNC ) \ +/* fatal errors */ \ + FUNC(NUL_IN_HEADER) \ + FUNC(UNTERMINATED_HEADER) \/* errors */ \FUNC (BAD_DATE) \FUNC (BAD_EMAIL) \
@@ -39,10 +42,8 @@ FUNC(MISSING_TYPE_ENTRY) \ FUNC(MULTIPLE_AUTHORS) \ FUNC(NOT_SORTED) \ - FUNC(NUL_IN_HEADER) \ FUNC(TAG_OBJECT_NOT_TAG) \ FUNC(UNKNOWN_TYPE) \ - FUNC(UNTERMINATED_HEADER) \ FUNC(ZERO_PADDED_DATE) \ /* warnings */ \ FUNC(BAD_FILEMODE) \
@@ -56,6 +57,7 @@ FUNC(NULL_SHA1) \ FUNC(ZERO_PADDED_FILEMODE) +#define FIRST_NON_FATAL_ERROR FSCK_MSG_BAD_DATE#define FIRST_WARNING FSCK_MSG_BAD_FILEMODE#define MSG_ID (x) FSCK_MSG_##x,
@@ -150,6 +152,8 @@ void fsck_strict_mode(struct fsck_options *options, const char *mode) } msg_id =parse_msg_id (mode, equal); +if (type !=FSCK_ERROR && msg_id <FIRST_NON_FATAL_ERROR ) +die ("Cannot demote %.*s" , len, mode); options->strict_mode[msg_id] = type; mode += len; }
t/t5504-fetch-receive-strict.sh +9 -0
@@ -135,4 +135,13 @@ test_expect_success 'push with receive.fsck.missing-mail = warn' ' grep "missing-email" act ' +test_expect_success 'receive.fsck.unterminated-header = warn triggers error' ' + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + git --git-dir=dst/.git config receive.fsck.unterminated-header warn && + test_must_fail git push --porcelain dst HEAD >act 2>&1 && + grep "Cannot demote unterminated-header=warn" act +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 13/18 Optionally ignore specific fsck issues completely
In reply to Johannes SchindelinAn fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective error to "ignore".
This change "abuses" the missing-email=warn test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).
--- fsck.c | 5 +++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
fsck.c +5 -0
@@ -146,6 +146,8 @@ void fsck_strict_mode(struct fsck_options *options, const char *mode) type =FSCK_ERROR ; else if (!substrcmp(type_str, type_len, "warn")) type =FSCK_WARN ; + else if (!substrcmp(type_str, type_len, "ignore")) + type =FSCK_IGNORE ; else die("Unknown fsck message type: '%.*s'", len - equal - 1, type_str);
@@ -184,6 +186,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_type =fsck_msg_type (id, options), result; +if (msg_type ==FSCK_IGNORE ) +return 0 ; +append_msg_id (&sb, msg_id_str[id]);va_start (ap, fmt);
fsck.h +1 -0
@@ -3,6 +3,7 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +#define FSCK_IGNORE 3struct fsck_options ;
t/t5504-fetch-receive-strict.sh +6 -1
@@ -132,7 +132,12 @@ test_expect_success 'push with receive.fsck.missing-mail = warn' ' test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config receive.fsck.missing-email warn && git push --porcelain dst bogus >act 2>&1 && - grep "missing-email" act + grep "missing-email" act && + git --git-dir=dst/.git branch -D bogus && + git --git-dir=dst/.git config receive.fsck.missing-email ignore && + git --git-dir=dst/.git config receive.fsck.bad-date warn && + git push --porcelain dst bogus >act 2>&1 && + test_must_fail grep "missing-email" act ' test_expect_success 'receive.fsck.unterminated-header = warn triggers error' '
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 14/18 fsck: allow upgrading fsck warnings to errors
In reply to Johannes SchindelinThe 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by setting receive.fsck.invalid-tag-name and receive.fsck.missing-tagger-entry to 'error'.
Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).
--- fsck.c | 24 ++++++++++++++++-------- t/t5302-pack-index.sh | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-)
fsck.c +16 -8
@@ -52,13 +52,15 @@FUNC (HAS_DOT) \FUNC (HAS_DOTDOT ) \FUNC (HAS_DOTGIT ) \ - FUNC(INVALID_TAG_NAME) \ - FUNC(MISSING_TAGGER_ENTRY) \FUNC (NULL_SHA1 ) \ - FUNC(ZERO_PADDED_FILEMODE) +FUNC (ZERO_PADDED_FILEMODE ) \ +/* infos (reported as warnings, but ignored by default) */ \ +FUNC (INVALID_TAG_NAME ) \ +FUNC (MISSING_TAGGER_ENTRY ) #define FIRST_NON_FATAL_ERROR FSCK_MSG_BAD_DATE #define FIRST_WARNING FSCK_MSG_BAD_FILEMODE +#define FIRST_INFO FSCK_MSG_INVALID_TAG_NAME #define MSG_ID(x) FSCK_MSG_##x, enum fsck_msg_id {
@@ -103,7 +105,7 @@ int fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options)if (options->strict_mode && msg_id >=0 && msg_id <FSCK_MSG_MAX )return options->strict_mode[msg_id];if (options->strict) -return FSCK_ERROR ; +return msg_id <FIRST_INFO ?FSCK_ERROR :FSCK_WARN ;return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ; }
@@ -643,13 +645,19 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, goto done; }strbuf_addf (&sb,"refs/tags/%.*s" , (int )(eol - buffer), buffer); -if (check_refname_format (sb.buf,0 )) -report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %s" , buffer); +if (check_refname_format (sb.buf,0 )) { + ret =report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %s" , buffer); +if (ret) + goto done; + } buffer = eol +1 ; -if (!skip_prefix (buffer,"tagger " , &buffer)) +if (!skip_prefix (buffer,"tagger " , &buffer)) {/* early tags do not contain 'tagger' lines; warn only */ -report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); + ret =report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); +if (ret) + goto done; + }else ret =fsck_ident (&buffer, &tag->object, options);
t/t5302-pack-index.sh +1 -1
@@ -259,7 +259,7 @@ EOF thirtyeight=${tag#??} && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^error:.* expected .tagger. line" err + grep "^warning:.* expected .tagger. line" err ' test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 15/18 Document the new receive.fsck.* options.
In reply to Johannes Schindelin--- Documentation/config.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/config.txt +14 -0
@@ -2109,6 +2109,20 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.*:: + When `receive.fsckObjects is set to true, errors can be switched + to warnings and vice versa by setting e.g. `receive.fsck.bad-name` + to `warn` or `error` (or `ignore` to hide those errors + completely). For convenience, fsck prefixes the error/warning + with the name of the option, e.g. "missing-email: invalid + author/committer line - missing email" means that setting + `receive.fsck.missing-email` to `ignore` will hide that issue. + For convenience, camelCased options are accepted, too (e.g. + `receive.fsck.missingEmail`). ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 16/18 fsck: support demoting errors to warnings
In reply to Johannes SchindelinWe already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.
Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.
Example: git -c fsck.missing-email=ignore fsck would hide problems with missing emails in author, committer and tagger lines.
--- Documentation/config.txt | 13 +++++++++++++ builtin/fsck.c | 15 +++++++++++++++ t/t1450-fsck.sh | 11 +++++++++++ 3 files changed, 39 insertions(+)
Documentation/config.txt +13 -0
@@ -1192,6 +1192,19 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. +fsck.*:: + With these options, fsck errors can be switched to warnings and + vice versa by setting e.g. `fsck.bad-name` to `warn` or `error` + (or `ignore` to hide those errors completely). For convenience, + fsck prefixes the error/warning with the name of the option, e.g. + "missing-email: invalid author/committer line - missing email" + means that setting `fsck.missing-email` to `ignore` will hide that + issue. For convenience, camelCased options are accepted, too (e.g. + `fsck.missingEmail`). ++ +This feature is intended to support working with legacy repositories +which cannot be repaired without disruptive changes. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +15 -0
@@ -46,6 +46,19 @@ static int show_dangling = 1;#define DIRENT_SORT_HINT (de) ((de)->d_ino)#endif +static int fsck_config (const char *var,const char *value,void *cb) +{ +if (starts_with (var,"fsck." )) { +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"%s=%s" , var +5 , value ? value :"error" ); +fsck_strict_mode (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } + +return git_default_config (var, value, cb); +} +static void objreport (struct object *obj,const char *severity,const char *err) {
@@ -638,6 +651,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) include_reflogs =0 ; } +git_config (fsck_config,NULL ); +fsck_head_link ();fsck_object_dir (get_object_directory ());
t/t1450-fsck.sh +11 -0
@@ -283,6 +283,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' ' grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out ' +test_expect_success 'force fsck to ignore double author' ' + git cat-file commit HEAD >basis && + sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && + new=$(git hash-object -t commit -w --stdin <multiple-authors) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + test_must_fail git fsck && + git -c fsck.multiple-authors=ignore fsck +' + _bz='\0' _bz5="$_bz$_bz$_bz$_bz$_bz" _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 17/18 Introduce `git fsck --quick`
In reply to Johannes SchindelinThis option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.
--- Documentation/git-fsck.txt | 7 ++++++- builtin/fsck.c | 7 ++++++- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found] [--[no-]dangling] [--[no-]progress] [<object>*] DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs object pools. This is now default; you can turn it off with --no-full. +--quick:: + Check only the connectivity of tags, commits and tree objects. By + avoiding to unpack blobs, this speeds up the operation, at the + expense of missing corrupt objects. + --strict:: Enable more strict checking, namely to catch a file mode recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
@@ -23,6 +23,7 @@ static int show_tags;static int show_unreachable;static int include_reflogs =1 ;static int check_full =1 ; +static int quick;static int check_strict;static int keep_cache_objects;static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ;
@@ -184,6 +185,8 @@ static void check_reachable_object(struct object *obj)if (!(obj->flags &HAS_OBJ )) {if (has_sha1_pack (obj->sha1))return ;/* it is in pack - forget about it */ +if (quick &&has_sha1_file (obj->sha1)) +return ;printf ("missing %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); errors_found |=ERROR_REACHABLE ;return ;
@@ -618,6 +621,7 @@ static struct option fsck_opts[] = {OPT_BOOL (0 ,"cache" , &keep_cache_objects,N_ ("make index objects head nodes" )),OPT_BOOL (0 ,"reflogs" , &include_reflogs,N_ ("make reflogs head nodes (default)" )),OPT_BOOL (0 ,"full" , &check_full,N_ ("also consider packs and alternate objects" )), +OPT_BOOL (0 ,"quick" , &quick,N_ ("check only connectivity" )),OPT_BOOL (0 ,"strict" , &check_strict,N_ ("enable more strict checking" )),OPT_BOOL (0 ,"lost-found" , &write_lost_and_found, N_("write dangling objects in .git/lost-found")),
@@ -654,7 +658,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)git_config (fsck_config,NULL );fsck_head_link (); -fsck_object_dir (get_object_directory ()); +if (!quick) +fsck_object_dir (get_object_directory ());prepare_alt_odb ();for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
@@ -407,4 +407,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' ' test_must_fail git -C missing fsck ' +test_expect_success 'fsck --quick' ' + rm -rf quick && + git init quick && + ( + cd quick && + touch empty && + git add empty && + test_commit empty && + empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 && + rm -f $empty && + echo invalid >$empty && + test_must_fail git fsck --strict && + git fsck --strict --quick && + tree=$(git rev-parse HEAD:) && + suffix=${tree#??} && + tree=.git/objects/${tree%$suffix}/$suffix && + rm -f $tree && + echo invalid >$tree && + test_must_fail git fsck --strict --quick + ) +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH 18/18 git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinThe optional new config option receive.fsck.skip-list specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.
--- builtin/receive-pack.c | 9 +++++++ fsck.c | 59 +++++++++++++++++++++++++++++++++++++++-- fsck.h | 2 ++ t/t5504-fetch-receive-strict.sh | 12 +++++++++ 4 files changed, 80 insertions(+), 2 deletions(-)
builtin/receive-pack.c +9 -0
@@ -110,6 +110,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck.skip-list" )) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +if (fsck_strict_mode.len) +strbuf_addch (&fsck_strict_mode,',' ); +strbuf_addf (&fsck_strict_mode,"skip-list=%s" , path); +return 0 ; + } +if (starts_with (var,"receive.fsck." )) {if (fsck_strict_mode.len)strbuf_addch (&fsck_strict_mode,',' );
fsck.c +57 -2
95 lines not on this page · raw message
fsck.h +2 -0
@@ -29,6 +29,8 @@ struct fsck_options {fsck_error error_func; int strict:1;int *strict_mode; +/* TODO: consider reading into a hashmap */ +struct sha1_array *skip_list; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000 This commit object intentionally broken EOF +test_expect_success 'push with receive.fsck.skip-list' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.skip-list SKIP && + echo $commit > dst/.git/SKIP && + git push --porcelain dst bogus +' + test_expect_success 'push with receive.fsck.missing-mail = warn' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
Re: [PATCH 01/18] Introduce fsck options
In reply to Johannes SchindelinJohannes Schindelin <[email protected]> writes:
THis is not limited to this step, but
Quoted 1 line
Subject: Re: [PATCH 01/18] Introduce fsck options
please make it easier to cluster and spot the series in the eventual shortlog by giving a common prefix to the patches, e.g.
fsck: introduce fsck_options struct
builtin/fsck.c static int include_reflogs = 1; · line 29
Quoted 2 lines
builtin/fsck.c +2
-0+static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;
Is it a good idea to allow walker to be strict but obj verifier to be not (or vice versa)? I am wondering why this is not a single struct with two callback function pointers.
fsck.h typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); · line 28
Quoted 4 lines
fsck.h +4
-0+struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +int strict:1 ;
A signed 1-bit-wide bitfield can hold its sign-bit and nothing else, no?
unsigned strict:1;
Re: [PATCH 03/18] Provide a function to parse fsck message IDs
In reply to Johannes SchindelinQuoted 21 lines · Johannes Schindelin
This function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines.
To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both "missing-email" and "missingEmail" will match the "
MISSING_EMAIL" key).Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)fsck.c +0
-0
fsck.c enum fsck_msg_id { · line 71
Quoted 9 lines
fsck.c +6
-0@@ -63,6 +63,38 @@ enum fsck_msg_id {FSCK_MSG_MAX }; +#define STR (x) #x +#define MSG_ID_STR (x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX +1 ] = { +FOREACH_MSG_ID (MSG_ID_STR ) + NULL +};
I wondered what the ugly macro was in the previous step, but as a way to keep these two lists in sync it makes sense.
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinQuoted 30 lines · Johannes Schindelin
There are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting
receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all
FSCK_ERRORin those cases.Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fsck.h | 7 +++++-- 2 files changed, 63 insertions(+), 2 deletions(-)fsck.c +0
-0
fsck.c static int parse_msg_id(const char *text, int len) · line 105
Quoted 9 lines
fsck.c +4
-0@@ -97,9 +97,63 @@ static int parse_msg_id(const char *text, int len)int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { +if (options->strict_mode && msg_id >=0 && msg_id <FSCK_MSG_MAX ) +return options->strict_mode[msg_id]; +if (options->strict) +return FSCK_ERROR ;return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ; }
Hmm, if you are later going to allow demoting (hopefully also promoting) error to warn, etc., would the comparison between msg_id and FIRST_WARNING make much sense?
In other words, at some point wouldn't we be better off with something like this
struct {
enum id;
const char *id_string;
enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR };
} possible_fsck_errors[];Re: [PATCH 05/18] Allow demoting errors to warnings via receive.fsck.<key> = warn
In reply to Johannes SchindelinQuoted 4 lines · Johannes Schindelin
For example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.missing-email warn
No punctuations in the first and the last level of configuration variable names, please. I.e. s/missing-email/missingEmail/ or something.
Re: [PATCH 09/18] fsck: handle multiple authors in commits specially
In reply to Johannes Schindelinfsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 543
Quoted 8 lines · Johannes Schindelin
This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
...fsck.c +4
-0+while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err;
If we have an option to demote this to a warning, wouldn't we want to do the same fsck_ident() on that secondary author line?
Quoted 6 lines
fsck.c +3
-0+/* require_end_of_header() ensured that there is a newline */ + buffer =strchr (buffer,'\n' ) +1 ; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Re: [PATCH 12/18] Disallow demoting grave fsck errors to warnings
In reply to Johannes SchindelinQuoted 3 lines · Johannes Schindelin
Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
Makes sense, but the patch makes it look as if this is an "oops, we should have done the list in patch 02/18 in this order from the beginning". Can we reorder the patches?
Quoted 67 lines
Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 8 ++++++-- t/t5504-fetch-receive-strict.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)fsck.c +6
-2@@ -9,6 +9,9 @@#include "refs.h" #define FOREACH_MSG_ID (FUNC ) \ +/* fatal errors */ \ + FUNC(NUL_IN_HEADER) \ + FUNC(UNTERMINATED_HEADER) \/* errors */ \FUNC (BAD_DATE) \FUNC (BAD_EMAIL) \@@ -39,10 +42,8 @@ FUNC(MISSING_TYPE_ENTRY) \ FUNC(MULTIPLE_AUTHORS) \ FUNC(NOT_SORTED) \ - FUNC(NUL_IN_HEADER) \ FUNC(TAG_OBJECT_NOT_TAG) \ FUNC(UNKNOWN_TYPE) \ - FUNC(UNTERMINATED_HEADER) \ FUNC(ZERO_PADDED_DATE) \ /* warnings */ \ FUNC(BAD_FILEMODE) \@@ -56,6 +57,7 @@ FUNC(NULL_SHA1) \ FUNC(ZERO_PADDED_FILEMODE) +#define FIRST_NON_FATAL_ERROR FSCK_MSG_BAD_DATE#define FIRST_WARNING FSCK_MSG_BAD_FILEMODE#define MSG_ID (x) FSCK_MSG_##x,@@ -150,6 +152,8 @@ void fsck_strict_mode(struct fsck_options *options, const char *mode) } msg_id =parse_msg_id (mode, equal); +if (type !=FSCK_ERROR && msg_id <FIRST_NON_FATAL_ERROR ) +die ("Cannot demote %.*s" , len, mode); options->strict_mode[msg_id] = type; mode += len; }t/t5504-fetch-receive-strict.sh +9
-0@@ -135,4 +135,13 @@ test_expect_success 'push with receive.fsck.missing-mail = warn' ' grep "missing-email" act ' +test_expect_success 'receive.fsck.unterminated-header = warn triggers error' ' + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + git --git-dir=dst/.git config receive.fsck.unterminated-header warn && + test_must_fail git push --porcelain dst HEAD >act 2>&1 && + grep "Cannot demote unterminated-header=warn" act +' + test_done
Re: [PATCH 13/18] Optionally ignore specific fsck issues completely
In reply to Johannes SchindelinQuoted 3 lines · Johannes Schindelin
An fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective error to "ignore".
Makes sense.
Re: [PATCH 14/18] fsck: allow upgrading fsck warnings to errors
In reply to Johannes SchindelinQuoted 3 lines · Johannes Schindelin
The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by setting receive.fsck.invalid-tag-name and receive.fsck.missing-tagger-entry to 'error'.
Hmm, why can't all warnings promotable to errors, or are the above two mentioned only as examples?
Quoted 80 lines
Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).
Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 24 ++++++++++++++++-------- t/t5302-pack-index.sh | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-)fsck.c +16
-8@@ -52,13 +52,15 @@FUNC (HAS_DOT) \FUNC (HAS_DOTDOT ) \FUNC (HAS_DOTGIT ) \ - FUNC(INVALID_TAG_NAME) \ - FUNC(MISSING_TAGGER_ENTRY) \FUNC (NULL_SHA1 ) \ - FUNC(ZERO_PADDED_FILEMODE) +FUNC (ZERO_PADDED_FILEMODE ) \ +/* infos (reported as warnings, but ignored by default) */ \ +FUNC (INVALID_TAG_NAME ) \ +FUNC (MISSING_TAGGER_ENTRY ) #define FIRST_NON_FATAL_ERROR FSCK_MSG_BAD_DATE #define FIRST_WARNING FSCK_MSG_BAD_FILEMODE +#define FIRST_INFO FSCK_MSG_INVALID_TAG_NAME #define MSG_ID(x) FSCK_MSG_##x, enum fsck_msg_id {@@ -103,7 +105,7 @@ int fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options)if (options->strict_mode && msg_id >=0 && msg_id <FSCK_MSG_MAX )return options->strict_mode[msg_id];if (options->strict) -return FSCK_ERROR ; +return msg_id <FIRST_INFO ?FSCK_ERROR :FSCK_WARN ;return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ; }@@ -643,13 +645,19 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, goto done; }strbuf_addf (&sb,"refs/tags/%.*s" , (int )(eol - buffer), buffer); -if (check_refname_format (sb.buf,0 )) -report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %s" , buffer); +if (check_refname_format (sb.buf,0 )) { + ret =report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %s" , buffer); +if (ret) + goto done; + } buffer = eol +1 ; -if (!skip_prefix (buffer,"tagger " , &buffer)) +if (!skip_prefix (buffer,"tagger " , &buffer)) {/* early tags do not contain 'tagger' lines; warn only */ -report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); + ret =report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); +if (ret) + goto done; + }else ret =fsck_ident (&buffer, &tag->object, options);t/t5302-pack-index.sh +1
-1@@ -259,7 +259,7 @@ EOF thirtyeight=${tag#??} && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^error:.* expected .tagger. line" err + grep "^warning:.* expected .tagger. line" err ' test_done
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Johannes SchindelinQuoted 9 lines · Johannes Schindelin
We already have support in
git receive-packto deal with some legacy repositories which have non-fatal issues.Let's make
git fsckitself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.Example:
git -c fsck.missing-email=ignore fsckwould hide problems with missing emails in author, committer and tagger lines.
Hopefully I do not have to repeat myself, but please do not have punctuations in the first and the last level of configuration variable names, i.e. fsck.missingEmail, not mising-email.
Should these be tied to receive-pack ones in any way? E.g. if you set fsck.missingEmail to ignore, you do not have to do the same for receive and accept a push with the specific error turned off?
Not a rhetorical question. I can see it argued both ways. The justification to defend the position of not tying these two I would have is so that I can be more strict to newer breakages (i.e. not accepting a push that introduce a new breakage by not ignoring with receive.fsck.*) while allowing breakages that are already present. The justification for the opposite position is to make it more convenient to write a consistent policy. Whichever way is chosen, we would want to see the reason left in the log message so that people do not have to wonder what the original motivation was when they decide if it is a good idea to change this part of the code.
Thanks.
Re: [PATCH 18/18] git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinQuoted 27 lines · Johannes Schindelin
The optional new config option
receive.fsck.skip-listspecifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored bygit receive-packwhenreceive.fsckObjects = true.This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by
git pushas being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.Signed-off-by Johannes Schindelin <[email protected]>--- builtin/receive-pack.c | 9 +++++++ fsck.c | 59 +++++++++++++++++++++++++++++++++++++++-- fsck.h | 2 ++ t/t5504-fetch-receive-strict.sh | 12 +++++++++ 4 files changed, 80 insertions(+), 2 deletions(-)builtin/receive-pack.c +0
-0
builtin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 113
Quoted 4 lines
builtin/receive-pack.c +1
-0@@ -110,6 +110,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck.skip-list" )) {
s/skip-list/skiplist/;
Quoted 24 lines
builtin/receive-pack.c +8
-0+const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +if (fsck_strict_mode.len) +strbuf_addch (&fsck_strict_mode,',' ); +strbuf_addf (&fsck_strict_mode,"skip-list=%s" , path); +return 0 ; + } +if (starts_with (var,"receive.fsck." )) {if (fsck_strict_mode.len)strbuf_addch (&fsck_strict_mode,',' );fsck.c +1
-0@@ -7,6 +7,7 @@#include "tag.h" #include "fsck.h" #include "refs.h" +#include "sha1-array.h" #define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \
fsck.c line 62
Quoted 7 lines
fsck.c +3
-1@@ -56,7 +57,9 @@ FUNC(ZERO_PADDED_FILEMODE) \ /* infos (reported as warnings, but ignored by default) */ \ FUNC(INVALID_TAG_NAME) \ - FUNC(MISSING_TAGGER_ENTRY) + FUNC(MISSING_TAGGER_ENTRY) \ + /* special value */ \ + FUNC(SKIP_LIST)
This feels like a kludge to me without comment on what "special value" means. Does it mean "this object has an error (which by default is ignored) of being on the skip list?" Should we be able to optionally warn an object on the skip-list exists with the same mechansim the rest of the series uses to tweak the error level?
Quoted 8 lines · Johannes Schindelin
At the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects.
Overall I very much like what this series aims to do. Thanks for working on this.
Re: [PATCH 01/18] Introduce fsck options
In reply to Junio C HamanoHi Junio,
Quoted 8 lines · Junio C Hamano
Quoted 1 line · Johannes Schindelin
Subject: Re: [PATCH 01/18] Introduce fsck options
please make it easier to cluster and spot the series in the eventual shortlog by giving a common prefix to the patches, e.g.
fsck: introduce
fsck_optionsstruct
I use the fsck: prefix consistently now.
Quoted 6 lines
builtin/fsck.c static int include_reflogs = 1; · line 29
Quoted 2 lines
builtin/fsck.c +2
-0+static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;Is it a good idea to allow walker to be strict but obj verifier to be not (or vice versa)? I am wondering why this is not a single struct with two callback function pointers.
Unfortunately not. There are two different walkers used, and in fact, fsck_walk_options() is only used to walk the objects, not to fsck them.
Now, I could use only one struct and set the walker, but that is not thread-safe, and while code is not threaded yet AFAICT, it might be in the future. That is why I decided to be rather safe than sorry. If you want it differently, please just say the word, I will make it so.
Quoted 9 lines
fsck.h typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); · line 28
Quoted 4 lines
fsck.h +4
-0+struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +int strict:1 ;A signed 1-bit-wide bitfield can hold its sign-bit and nothing else, no?
unsigned strict:1;
Oops. Right. For some reason, it worked here, though... Fixed!
Ciao,
Dscho
Re: [PATCH 01/18] Introduce fsck options
Quoted 11 lines · Johannes Schindelin
Quoted 3 lines
Is it a good idea to allow walker to be strict but obj verifier to be not (or vice versa)? I am wondering why this is not a single struct with two callback function pointers.
Unfortunately not. There are two different walkers used, and in fact,
fsck_walk_options()is only used to walk the objects, not to fsck them.Now, I could use only one struct and set the walker, but that is not thread-safe, and while code is not threaded yet AFAICT, it might be in the future. That is why I decided to be rather safe than sorry. If you want it differently, please just say the word, I will make it so.
Thanks for explaining; I just found that the reason behind the design choice was unclear and wanted to know.
Re: [PATCH 03/18] Provide a function to parse fsck message IDs
In reply to Junio C HamanoHi Junio,
Quoted 26 lines · Junio C Hamano
Quoted 24 lines · Johannes Schindelin
This function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines.
To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both "missing-email" and "missingEmail" will match the "
MISSING_EMAIL" key).Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)fsck.c +0
-0@@ -63,6 +63,38 @@ enum fsck_msg_id { FSCK_MSG_MAX };
Quoted 9 lines
fsck.c enum fsck_msg_id { · line 71
Quoted 6 lines
fsck.c +6
-0+#define STR (x) #x +#define MSG_ID_STR (x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX +1 ] = { +FOREACH_MSG_ID (MSG_ID_STR ) + NULL +};I wondered what the ugly macro was in the previous step, but as a way to keep these two lists in sync it makes sense.
I added a comment to the commit message.
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
In reply to Junio C HamanoHi Junio,
Quoted 33 lines · Junio C Hamano
Quoted 31 lines · Johannes Schindelin
There are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting
receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all
FSCK_ERRORin those cases.Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fsck.h | 7 +++++-- 2 files changed, 63 insertions(+), 2 deletions(-)fsck.c +0
-0@@ -97,9 +97,63 @@ static int parse_msg_id(const char *text, int len)
Quoted 12 lines
fsck.c static int parse_msg_id(const char *text, int len) · line 105
Quoted 8 lines
fsck.c +4
-0int fsck_msg_type (enum fsck_msg_id msg_id,struct fsck_options *options) { +if (options->strict_mode && msg_id >=0 && msg_id <FSCK_MSG_MAX ) +return options->strict_mode[msg_id]; +if (options->strict) +return FSCK_ERROR ;return msg_id <FIRST_WARNING ?FSCK_ERROR :FSCK_WARN ; }Hmm, if you are later going to allow demoting (hopefully also promoting) error to warn, etc., would the comparison between
msg_idandFIRST_WARNINGmake much sense?
A later patch indeed adds that option. The reason the comparison still makes sense is that the pure infos do not return at all so far, but all of the reported warnings are fatal in strict mode (i.e. when receive.fsckObjects = true). In another later patch it is made possible to promote even infos (such as 'missing tagger') to warnings or even errors, and that is when the "return FSCK_ERROR" is changed to "return msg_id < FIRST_INFO ? FSCK_ERROR : FSCK_WARN".
Quoted 8 lines
In other words, at some point wouldn't we be better off with something like this
struct { enum id; const char *id_string; enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR }; } possible_fsck_errors[];
I considered that, and Michael Haggerty also suggested that in a private mail. However, I find that there is a clear hierarchy in the default
messages: fatal errors, errors, warnings and infos. This should be reflected by the order IMHO.
But I guess it would make a lot of sense to insert those levels as special enum values to make it harder to forget to adjust, say, "#define FIRST_WARNING FSCK_MSG_BAD_FILEMODE" when introducing another warning that sorts before said ID alphabetically. In other words, I think that we can really afford to put something like
...
FUNC(UNKNOWN_TYPE) \
FUNC(ZERO_PADDED_DATE) \
FUNC(___WARNINGS) \
FUNC(BAD_FILEMODE) \
FUNC(EMPTY_NAME) \
...at the price of making the parsing a little more complicated and wasting a slight bit of more space for the msg_id_str array.
What do you think?
Ciao,
Dscho
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Quoted 9 lines · Johannes Schindelin
Quoted 8 lines
In other words, at some point wouldn't we be better off with something like this
struct { enum id; const char *id_string; enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR }; } possible_fsck_errors[];
Quoted 3 lines
I considered that, and Michael Haggerty also suggested that in a private mail. However, I find that there is a clear hierarchy in the default
messages: fatal errors, errors, warnings and infos.
I am glad I am not alone ;-)
These classes are ordered from more severe to less, but I do not think it makes much sense to force the default view of "if you customize to demote a questionable Q that is classified as an error by default as an warning, you must demote all the other ones that we deem less serious than Q, which come earlier (or later---I do not remember which) in our predefined list". So in that sense, I do not consider that various kinds of questionables fsck can detect are hierarchical at all.
I do agree that it makes it easier to code the initialization of such an array to have "up to this point we assign the level 'fatal error' by default" constants. Then the initialization can become
for (i = 0; i < FIRST_WARN; i++)
possible_fsck_errors[i].error_level = FSCK_INFO;
while (i < FIRST_ERROR)
possible_fsck_errors[i++].error_level = FSCK_WARN;
while (i < ARRAY_SIZE(possible_fsck_errors))
possible_fsck_errors[i++].error_level = FSCK_ERROR;or something. So I am not against the FIRST_WARNING constant at all, but I find it very questionable in a fully customizable system to use such a constant anywhere other than the initialization time.
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 17 lines · Junio C Hamano
Quoted 9 lines · Johannes Schindelin
Quoted 8 lines
In other words, at some point wouldn't we be better off with something like this
struct { enum id; const char *id_string; enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR }; } possible_fsck_errors[];Quoted 3 lines
I considered that, and Michael Haggerty also suggested that in a private mail. However, I find that there is a clear hierarchy in the default
messages: fatal errors, errors, warnings and infos.I am glad I am not alone ;-)
Quoted 8 lines
These classes are ordered from more severe to less, but I do not think it makes much sense to force the default view of "if you customize to demote a questionable Q that is classified as an error by default as an warning, you must demote all the other ones that we deem less serious than Q, which come earlier (or later---I do not remember which) in our predefined list". So in that sense, I do not consider that various kinds of questionables fsck can detect are hierarchical at all.
Oh, but please understand that this hierarchy only applies to the default settings. All of these settings can be overridden individually – and the first override will initialize a full array with the default settings.
So the order really only plays a role for the defaults, no more.
Quoted 11 lines
I do agree that it makes it easier to code the initialization of such an array to have "up to this point we assign the level 'fatal error' by default" constants. Then the initialization can become
for (i = 0; i < FIRST_WARN; i++) possible_fsck_errors[i].error_level = FSCK_INFO; while (i < FIRST_ERROR) possible_fsck_errors[i++].error_level = FSCK_WARN; while (i < ARRAY_SIZE(possible_fsck_errors)) possible_fsck_errors[i++].error_level = FSCK_ERROR;
Quoted 3 lines
or something. So I am not against the
FIRST_WARNINGconstant at all, but I find it very questionable in a fully customizable system to use such a constant anywhere other than the initialization time.
This is indeed the case. The code we are discussing comes after the
if (options->strict_mode) return options->strict_mode[msg_id];
In other words, once the overrides are in place, the default settings are skipped entirely.
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Quoted 19 lines · Johannes Schindelin
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Johannes Schindelin
Quoted 8 lines
In other words, at some point wouldn't we be better off with something like this
struct { enum id; const char *id_string; enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR }; } possible_fsck_errors[];I considered that, and Michael Haggerty also suggested that in a private mail. However, I find that there is a clear hierarchy in the default
messages: fatal errors, errors, warnings and infos.
Quoted 5 lines
Quoted 2 lines
I am glad I am not alone ;-)
...Oh, but please understand that this hierarchy only applies to the default settings. All of these settings can be overridden individually – and the first override will initialize a full array with the default settings.
But that means that the runtime needs to switch between two code with and without override, no?
Quoted 2 lines
if (options->strict_mode) return options->strict_mode[msg_id];
In other words, I think this is misleading and unnecessary optimization for the "full array" allocation. A code that uses an array of a struct like the above that Michael and I independently suggested would initialize once with or without an override and then at the runtime there is no "if the array is there use it" conditional.
I do not know why Michael suggested the same thing, but the reason why I prefer that arrangement is because I think it would be easier to read and maintain.
Thanks.
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 38 lines · Junio C Hamano
Quoted 17 lines · Johannes Schindelin
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Johannes Schindelin
Quoted 8 lines
In other words, at some point wouldn't we be better off with something like this
struct { enum id; const char *id_string; enum error_level { FSCK_PASS, FSCK_WARN, FSCK_ERROR }; } possible_fsck_errors[];I considered that, and Michael Haggerty also suggested that in a private mail. However, I find that there is a clear hierarchy in the default
messages: fatal errors, errors, warnings and infos.Quoted 5 lines
Quoted 2 lines
I am glad I am not alone ;-)
...Oh, but please understand that this hierarchy only applies to the default settings. All of these settings can be overridden individually – and the first override will initialize a full array with the default settings.
But that means that the runtime needs to switch between two code with and without override, no?
Quoted 2 lines
if (options->strict_mode) return options->strict_mode[msg_id];In other words, I think this is misleading and unnecessary optimization for the "full array" allocation. A code that uses an array of a struct like the above that Michael and I independently suggested would initialize once with or without an override and then at the runtime there is no "if the array is there use it" conditional.
Quoted 3 lines
I do not know why Michael suggested the same thing, but the reason why I prefer that arrangement is because I think it would be easier to read and maintain.
Well, I disagree that it would be easier to maintain, because it appears to me that the clear hierarchy keeps things simple. For example if some clearly fatal error is clustered with non-fatal ones due to alphabetical ordering, it is much harder to spot when it is marked as a demoteable error by mistake.
For example, try to spot the error here:
... F(ALMOST_HAPPY, INFO) \ F(CANNOT_RECOVER, ERROR) \ F(COFFEE_IS_EMPTY, WARN) \ F(JUST_BEING_CHATTY, INFO) \ F(LIFE_IS_GOOD, INFO) \ F(MISSING_SOMETHING_VITAL, FATAL_ERROR) \ F(NEED_TO_SLEEP, WARN) \ F(SOMETHING_WENT_WRONG, ERROR) \ ...
Personally, I find it very, very hard to spot that CANNOT_RECOVER is marked as a mere ERROR instead of a FATAL_ERROR. Even if it is nicely alphabetically ordered.
I will sleep over this, though. Maybe I can come up with a solution that makes all three of us happy.
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Quoted 12 lines · Johannes Schindelin
For example, try to spot the error here:
... F(ALMOST_HAPPY, INFO) \ F(CANNOT_RECOVER, ERROR) \ F(COFFEE_IS_EMPTY, WARN) \ F(JUST_BEING_CHATTY, INFO) \ F(LIFE_IS_GOOD, INFO) \ F(MISSING_SOMETHING_VITAL, FATAL_ERROR) \ F(NEED_TO_SLEEP, WARN) \ F(SOMETHING_WENT_WRONG, ERROR) \ ...
But that is not what is being suggested at all. I already said that FIRST_SOMETHING is fine as a measure to initialize, didn't I?
I am only saying that if you have a place to store customized level, you should initialize that part with default levels and always look it up from that place at runtime. It is perfectly fine for the initialization step to take advantage of the ordering and FIRST_SOMETHING constants.
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Johannes Schindelin
For example, try to spot the error here:
... F(ALMOST_HAPPY, INFO) \ F(CANNOT_RECOVER, ERROR) \ F(COFFEE_IS_EMPTY, WARN) \ F(JUST_BEING_CHATTY, INFO) \ F(LIFE_IS_GOOD, INFO) \ F(MISSING_SOMETHING_VITAL, FATAL_ERROR) \ F(NEED_TO_SLEEP, WARN) \ F(SOMETHING_WENT_WRONG, ERROR) \ ...
Quoted 8 lines
But that is not what is being suggested at all. I already said that
FIRST_SOMETHINGis fine as a measure to initialize, didn't I?I am only saying that if you have a place to store customized level, you should initialize that part with default levels and always look it up from that place at runtime. It is perfectly fine for the initialization step to take advantage of the ordering and
FIRST_SOMETHINGconstants.
Thanks for clarifying, I was worried that you wanted to encode the severity levels explicitly (F(ID, LEVEL) instead of F(ID) in the correct order). The DRY principle also suggests that we should not encode the severity level in two ways (which would leave the door open for inconsistencies). That means that we should not initialize a static array of severity levels, but initialize the array using a loop.
Okay, now that we have established that the initial ordering by severity makes sense, let's examine the initialization step.
Basically, our approaches differ only in *when* to initialize that array of severity levels: you want to initialize it always, and I want to initialize it only when the severity levels are customized by the caller.
Now, let's have a look how the fsck_options are currently initialized. My code follows the convention established with strbufs, argv_arrays, etc:
there is a preprocessor definition (_DEFAULT, imitating the _INIT definitions) that allows us to initialize such structs very conveniently. Please note that no loop is required, and certainly no extra code has to be called to initialize the struct. We get away with initializing that array lazily in the fsck_strict_mode() function when we detect that it needs to be initialized, being populated by the very same function that provides the default settings before customization. This is a very robust setup as the knowledge about, say, the size of that array is confined strictly to fsck.c.
However, if we had to change the lookup such that it uses an array always, we would have to introduce a function to initialize the struct, always, in particular we would have to find a place to call that initialization function in, say, builtin/fsck.c (actually, in every code path that calls into the fsck machinery). Arguably, the code would get more complex – introducing new call paths just to initialize the fsck_options struct – and I would argue further that there is no gain from an elegance, readability and maintenance point of view: whether the array is initialized lazily or not, it will be initialized the exact same way. All it means is that we have to introduce separate code paths because we would separate explicitly the initialization from the configuration step.
Therefore, I do not believe that introducing an fsck_options_init() is what you would really want.
An alternative would be to initialize the array at compile time – we would have to violate the DRY principle for that, repeating the severity levels many times over, and we could no longer confine the visibility to the message IDs to fsck.c because not only the size of the array of severity levels would have to be known to every user of fsck.h, but the exact default severity levels themselves, to be able to initialize the struct. But we could initialize the struct with a known set of settings via the _DEFAULTS definition that way.
However, you already expressed slight disagreement with the preprocessor magic needed to initialize both the enum and the array of message ID strings from the same list in a way that lets the compiler ensure consistency; I am afraid that if I were to modify _DEFAULTS to populate the entire severity level array, the resulting code would find your utter contempt.
I believe, therefore, that this is also not what you want.
So that leaves only one alternative: to initialize a global array with the default severity levels at *some* stage. I have no idea what that stage would be, therefore we would have to either establish ugly, and DRY-violating, compile time initialization, or we would have to call a function before using any of the fsck machinery – but that is fragile: it is too easy to forget one call path and access an uninitialized array! Worse, even if we *had* a fully initialized array of default severity levels, we would still have to have an on-demand copy (i.e. lazy initialization) of said array lest we modify the global defaults in fsck_strict_mode()! Essentially, we would just *add* complexity to the current solution, not replace it with anything simpler.
Therefore, I believe that you cannot be a fan of this alternative, either.
In short, I still find it much more elegant to determine the default severity levels from the numeric enum values, and initialize the severity level array only on demand, than to introduce a separate call to initialize the array always, in particular since we would have to execute that initialization loop *all* the time in the latter case – even if we do not customize, let alone look up, any value – or clutter the code with ugly, ugly preprocessor constructs.
And I hope that my arguments convinced you, too!
Ciao,
Dscho
Re: [PATCH 05/18] Allow demoting errors to warnings via receive.fsck.<key> = warn
In reply to Junio C HamanoHi Junio,
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
For example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.missing-email warn
No punctuations in the first and the last level of configuration variable names, please. I.e. s/missing-email/missingEmail/ or something.
Fixed.
Ciao,
Dscho
Re: [PATCH 09/18] fsck: handle multiple authors in commits specially
In reply to Junio C HamanoHi Junio,
Quoted 13 lines · Junio C Hamano
fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 543
Quoted 8 lines · Johannes Schindelin
This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
...fsck.c +4
-0+while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err;If we have an option to demote this to a warning, wouldn't we want to do the same
fsck_ident()on that secondary author line?
Good point! I changed the following to use fsck_ident() instead:
Quoted 6 lines
fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 549
Quoted 6 lines
fsck.c +3
-0+/* require_end_of_header() ensured that there is a newline */ + buffer =strchr (buffer,'\n' ) +1 ; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Ciao,
Dscho
Re: [PATCH 12/18] Disallow demoting grave fsck errors to warnings
In reply to Junio C HamanoHi Junio,
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
Makes sense, but the patch makes it look as if this is an "oops, we should have done the list in patch 02/18 in this order from the beginning". Can we reorder the patches?
I considered this already, but it would more be like a squash than a reordering. And when I squashed the patches, the story did not read as clearly to me as it does now. However, if you think this argument is too weak, I will squash them.
Is it too weak?
Ciao,
Dscho
Re: [PATCH 14/18] fsck: allow upgrading fsck warnings to errors
In reply to Junio C HamanoHi Junio,
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by setting receive.fsck.invalid-tag-name and receive.fsck.missing-tagger-entry to 'error'.
Hmm, why can't all warnings promotable to errors, or are the above two mentioned only as examples?
Those were the only ones that were always shown as warnings but never treated as errors.
There is a third one coming, as part of the patches that will let fsck warn about NTFS-incompatible file names, but I want to get this patch series integrated into git.git first.
Ciao,
Dscho
Re: [PATCH 14/18] fsck: allow upgrading fsck warnings to errors
Quoted 10 lines · Johannes Schindelin
Hi Junio,
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by setting receive.fsck.invalid-tag-name and receive.fsck.missing-tagger-entry to 'error'.
Quoted 5 lines
Quoted 2 lines
Hmm, why can't all warnings promotable to errors, or are the above two mentioned only as examples?
Those were the only ones that were always shown as warnings but never treated as errors.
Sorry but I don't quite understand this comment; I suspect the root cause might be that we have different mental models on these tweakable error severities.
Because I come from the school "To these N kinds of events you can independently assign different (i.e. info, warn, error) outcomes", moving the FIRST_{INFO,WARNING,...} position in the array would only affect what happens by default, never hindering the user's ability to tweak (in other words, there is no linkage between "now you can tweak" and the order of events in the list, the latter of which only would affect what the default severity of each event is).
It appears that your design is from a different mental model and the order and position in that list has more significance than what the default severity of each event is but how much the severity can be tweaked, or something, which I somehow find incomprehensible.
Puzzled...
Re: [PATCH 14/18] fsck: allow upgrading fsck warnings to errors
Hi Junio,
Quoted 20 lines · Junio C Hamano
Quoted 8 lines · Johannes Schindelin
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by setting receive.fsck.invalid-tag-name and receive.fsck.missing-tagger-entry to 'error'.
Quoted 5 lines
Quoted 2 lines
Hmm, why can't all warnings promotable to errors, or are the above two mentioned only as examples?
Those were the only ones that were always shown as warnings but never treated as errors.
Sorry but I don't quite understand this comment; I suspect the root cause might be that we have different mental models on these tweakable error severities.
Quoted 7 lines
Because I come from the school "To these N kinds of events you can independently assign different (i.e. info, warn, error) outcomes", moving the FIRST_{INFO,WARNING,...} position in the array would only affect what happens by default, never hindering the user's ability to tweak (in other words, there is no linkage between "now you can tweak" and the order of events in the list, the latter of which only would affect what the default severity of each event is).
We agree on this mental model.
The only problem this patch tries to fix is that the warnings about a missing tagger and about invalid tag names were never leading to an error. They were purely printed, but then ignored. So what this patch does is to add "if (err) return err;" handling for those two warnings.
As a consequence, the ordering of message IDs needs to be fixed because the non-fatal warnings were ordered alphabetically before, but now the non-fatal warnings are extracted so that we can give them the appropriate FSCK_WARN by defauly – even in the git-receive-pack case.
In other words, the value assigned to those two warnings was completely ignored before, which was the reason why it did not matter that we assigned them to report FSCK_ERRORs in the git-receive-pack case before:
they were still only printed out and never stopped any tag from entering the host's repository.
I could change the ordering in the patch that introduces the message IDs, of course, but it would be even more puzzling if those two messages, of all, were not ordered alphabetically with the others.
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Junio C HamanoHi Junio,
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Johannes Schindelin
We already have support in
git receive-packto deal with some legacy repositories which have non-fatal issues.Let's make
git fsckitself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.
Quoted 6 lines
Quoted 2 lines
Example:
git -c fsck.missing-email=ignore fsckwould hide problems with missing emails in author, committer and tagger lines.Hopefully I do not have to repeat myself, but please do not have punctuations in the first and the last level of configuration variable names, i.e. fsck.missingEmail, not mising-email.
I vetted the complete patch series and think I caught them all.
Or do you want the error messages to also use camelCased IDs, i.e.
warning in tag $tag: missingTaggerEntry: invalid format ...
instead of
warning in tag $tag: missing-tagger-entry: invalid format ...
? It is easy to do, but looks slightly uglier to this developer's eyes...
Quoted 4 lines
Should these be tied to receive-pack ones in any way? E.g. if you set fsck.missingEmail to ignore, you do not have to do the same for receive and accept a push with the specific error turned off?
Quoted 10 lines
Not a rhetorical question. I can see it argued both ways. The justification to defend the position of not tying these two I would have is so that I can be more strict to newer breakages (i.e. not accepting a push that introduce a new breakage by not ignoring with receive.fsck.*) while allowing breakages that are already present. The justification for the opposite position is to make it more convenient to write a consistent policy. Whichever way is chosen, we would want to see the reason left in the log message so that people do not have to wonder what the original motivation was when they decide if it is a good idea to change this part of the code.
Hmm. I really tried very hard to separate the fsck.* from the receive.* settings because the two code paths already behave differently: many warnings reported (and ignored) by fsck are fatal errors when pushing with receive.fsckObjects=true. My understanding was that these differences are deliberate, and my interpretation was that the fsck and the receive settings were considered to be fundamentally different, even if the same fsck machinery performs the validation.
If you agree, I would rephrase this line of argument and add it to the commit message. Do you agree?
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 9 lines · Johannes Schindelin
Or do you want the error messages to also use camelCased IDs, i.e.
warning in tag $tag: missingTaggerEntry: invalid format ...
instead of
warning in tag $tag: missing-tagger-entry: invalid format ...
? It is easy to do, but looks slightly uglier to this developer's eyes...
Do you really need to know what I think? Can I say "The latter is probably slightly better, but both look ugly to me"?
If we want a human readable message
"warning: tag object lacks tagger field '$tag'"
would be my preference.
But I personally think it may not be necessary to give a pretty message that later can go through l10n here. If we take that position, it is just a machine-readble error token, so I'd say whichever way you find more readable is OK.
Quoted 15 lines
Quoted 4 lines
Should these be tied to receive-pack ones in any way? E.g. if you set fsck.missingEmail to ignore, you do not have to do the same for receive and accept a push with the specific error turned off?
Quoted 10 lines
Not a rhetorical question. I can see it argued both ways. The justification to defend the position of not tying these two I would have is so that I can be more strict to newer breakages (i.e. not accepting a push that introduce a new breakage by not ignoring with receive.fsck.*) while allowing breakages that are already present. The justification for the opposite position is to make it more convenient to write a consistent policy. Whichever way is chosen, we would want to see the reason left in the log message so that people do not have to wonder what the original motivation was when they decide if it is a good idea to change this part of the code.
Quoted 5 lines
Hmm. I really tried very hard to separate the fsck.* from the receive.* settings because the two code paths already behave differently:...
If you agree, I would rephrase this line of argument and add it to the commit message. Do you agree?
Yeah, that reasoning sounds sensible.
Thanks.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Or do you want the error messages to also use camelCased IDs, i.e.
warning in tag $tag: missingTaggerEntry: invalid format ...
Quoted 7 lines
Quoted 5 lines
instead of
warning in tag $tag: missing-tagger-entry: invalid format ...
? It is easy to do, but looks slightly uglier to this developer's eyes...
Do you really need to know what I think?
Well, but yes ;-)
Quoted 2 lines
Can I say "The latter is probably slightly better, but both look ugly to me"?
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Quoted 10 lines
If we want a human readable message
"warning: tag object lacks tagger field '$tag'"
would be my preference.
But I personally think it may not be necessary to give a pretty message that later can go through l10n here. If we take that position, it is just a machine-readble error token, so I'd say whichever way you find more readable is OK.
Okay, I will leave it as-is, then.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Should these be tied to receive-pack ones in any way? E.g. if you set fsck.missingEmail to ignore, you do not have to do the same for receive and accept a push with the specific error turned off?
Not a rhetorical question. I can see it argued both ways. The justification to defend the position of not tying these two I would have is so that I can be more strict to newer breakages (i.e. not accepting a push that introduce a new breakage by not ignoring with receive.fsck.*) while allowing breakages that are already present. The justification for the opposite position is to make it more convenient to write a consistent policy. Whichever way is chosen, we would want to see the reason left in the log message so that people do not have to wonder what the original motivation was when they decide if it is a good idea to change this part of the code.
Quoted 7 lines
Quoted 5 lines
Hmm. I really tried very hard to separate the fsck.* from the receive.* settings because the two code paths already behave differently:...
If you agree, I would rephrase this line of argument and add it to the commit message. Do you agree?
Yeah, that reasoning sounds sensible.
I added this paragraph:
In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.* from the receive.fsck.* settings.
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 3 lines · Johannes Schindelin
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Thanks.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Except that cunning me has made it so that both missing-tagger-entry *and* missingTaggerEntry work...
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 10 lines · Johannes Schindelin
Hi Junio,
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Quoted 5 lines
Quoted 2 lines
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Except that cunning me has made it so that both missing-tagger-entry *and* missingTaggerEntry work...
Then the missing-tagger-entry side needs to be dropped. The naming does not conform to the way how we name our officially supported configuration variables.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Johannes Schindelin
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Quoted 6 lines
Quoted 2 lines
Except that cunning me has made it so that both missing-tagger-entry *and* missingTaggerEntry work...
Then the missing-tagger-entry side needs to be dropped. The naming does not conform to the way how we name our officially supported configuration variables.
But it does conform with the way we do our command-line parameters, and it would actually cause *more* work (and more complicated code) to have two separate parsers, or even to force the parser to accept only one way to specify settings...
Should I really introduce more complexity just to disallow non-camelCased config variables?
Ciao,
Dscho
Re: [PATCH 18/18] git receive-pack: support excluding objects from fsck'ing
In reply to Junio C HamanoHi Junio,
Quoted 57 lines · Junio C Hamano
Quoted 27 lines · Johannes Schindelin
The optional new config option
receive.fsck.skip-listspecifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored bygit receive-packwhenreceive.fsckObjects = true.This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by
git pushas being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.Signed-off-by Johannes Schindelin <[email protected]>--- builtin/receive-pack.c | 9 +++++++ fsck.c | 59 +++++++++++++++++++++++++++++++++++++++-- fsck.h | 2 ++ t/t5504-fetch-receive-strict.sh | 12 +++++++++ 4 files changed, 80 insertions(+), 2 deletions(-)builtin/receive-pack.c +0
-0builtin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 113
Quoted 4 lines
builtin/receive-pack.c +1
-0@@ -110,6 +110,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck.skip-list" )) {s/skip-list/skiplist/;
Quoted 21 lines
builtin/receive-pack.c +8
-0+const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +if (fsck_strict_mode.len) +strbuf_addch (&fsck_strict_mode,',' ); +strbuf_addf (&fsck_strict_mode,"skip-list=%s" , path); +return 0 ; + } +if (starts_with (var,"receive.fsck." )) {if (fsck_strict_mode.len)strbuf_addch (&fsck_strict_mode,',' );fsck.c +1
-0@@ -7,6 +7,7 @@#include "tag.h" #include "fsck.h" #include "refs.h" +#include "sha1-array.h"
Quoted 16 lines
fsck.c line 62
Quoted 10 lines
fsck.c +3
-1#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \@@ -56,7 +57,9 @@ FUNC(ZERO_PADDED_FILEMODE) \ /* infos (reported as warnings, but ignored by default) */ \ FUNC(INVALID_TAG_NAME) \ - FUNC(MISSING_TAGGER_ENTRY) + FUNC(MISSING_TAGGER_ENTRY) \ + /* special value */ \ + FUNC(SKIP_LIST)This feels like a kludge to me without comment on what "special value" means. Does it mean "this object has an error (which by default is ignored) of being on the skip list?" Should we be able to optionally warn an object on the skip-list exists with the same mechansim the rest of the series uses to tweak the error level?
I addressed both concerns – I hope... ;-)
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinQuoted 5 lines · Johannes Schindelin
However, if we had to change the lookup such that it uses an array always, we would have to introduce a function to initialize the struct, always, in particular we would have to find a place to call that initialization function in, say,
builtin/fsck.c(actually, in every code path that calls into the fsck machinery).
You would need to call a function to "initialize" the table if you support customization by reading the configuration files anyway. I am not sure why you think finding such a place is hard. Puzzled.
Also I suspect that you can tell the compiler to initialize the array in place with default values, perhaps like this?
-- >8 --
#include <stdio.h>
/* sorted by the default severity (lowest impact first) */
#define EVENT_LIST(F) \ F(EVENT_A), \ F(EVENT_B), \ F(EVENT_C), \ F(EVENT_D)
#define ID_(event) ID_ ## event
enum event_id {
EVENT_LIST(ID_)
};enum severity_level {
severity_info, severity_warn, severity_error
};
/* below this one are INFO */
#define FIRST_WARN_EVENT_ID ID_EVENT_B
/* below this one are WARN */
#define FIRST_ERROR_EVENT_ID ID_EVENT_C
#define STRING_(s) #s
#define DESC_(event) \
{ \
ID_ ## event, \
STRING_(event), \
(ID_ ## event < FIRST_WARN_EVENT_ID \
? severity_info \
: ID_ ## event < FIRST_ERROR_EVENT_ID \
? severity_warn \
: severity_error) \
}struct event_config {
enum event_id id;
const char * name;
enum severity_level level;
} event[] = { EVENT_LIST(DESC_)
};
int main(int ac, char **av)
{
int i;
for (i = 0; i < sizeof(event) / sizeof(event[0]); i++) {
printf("%d, %s, %d\n",
event[i].id, event[i].name, event[i].level);
}
return 0;
}Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin
However, if we had to change the lookup such that it uses an array always, we would have to introduce a function to initialize the struct, always, in particular we would have to find a place to call that initialization function in, say,
builtin/fsck.c(actually, in every code path that calls into the fsck machinery).You would need to call a function to "initialize" the table if you support customization by reading the configuration files anyway.
Yes, this is the config machinery. But I need employ that only if I want to let the caller customize the severity levels. However, the fsck machinery is also called from places where such a customization is not offered. They would now need to be changed, too.
Quoted 29 lines
Also I suspect that you can tell the compiler to initialize the array in place with default values, perhaps like this?
-- >8 --
#include <stdio.h>/* sorted by the default severity (lowest impact first) */
#define EVENT_LIST(F) \ F(EVENT_A), \ F(EVENT_B), \ F(EVENT_C), \ F(EVENT_D)#define
ID_(event)ID_## eventenum event_id { EVENT_LIST(ID_) };enum
severity_level{
severity_info,severity_warn,severity_error
};/* below this one are INFO */
#defineFIRST_WARN_EVENT_IDID_EVENT_B
/* below this one are WARN */
#defineFIRST_ERROR_EVENT_IDID_EVENT_C#define
STRING_(s)#s
Quoted 10 lines
#define DESC_(event) \
{ \
ID_ ## event, \
STRING_(event), \
(ID_ ## event < FIRST_WARN_EVENT_ID \
? severity_info \
: ID_ ## event < FIRST_ERROR_EVENT_ID \
? severity_warn \
: severity_error) \
}This is exactly the ugly, ugly preprocessor construct I thought you would meet with contempt. I mean, compared to this, my FUNC() hack is outright pretty ;-)
And *still*, this is *just* a global table with defaults. I would *still* need to copy-on-write when the first customization of the severity level takes place because I cannot allow the global defaults to be modified by one caller (that would defeat the whole purpose of having per-caller settings bundled in the fsck_options struct).
You see, I still would need to have a lazy initialization, the complexity in that part would not be reduced at all.
So I am afraid that this approach really adds complexity rather than replacing it with something simpler than my current code.
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Quoted 5 lines · Johannes Schindelin
And *still*, this is *just* a global table with defaults. I would *still* need to copy-on-write when the first customization of the severity level takes place because I cannot allow the global defaults to be modified by one caller (that would defeat the whole purpose of having per-caller settings bundled in the
fsck_optionsstruct).
If you allocate a per-invocation fsck_options struct, then the initialization the default with code is dead easy---you can just do it immediately after you x[cm]alloc()---no?
What am I missing?
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin
And *still*, this is *just* a global table with defaults. I would *still* need to copy-on-write when the first customization of the severity level takes place because I cannot allow the global defaults to be modified by one caller (that would defeat the whole purpose of having per-caller settings bundled in the
fsck_optionsstruct).If you allocate a per-invocation
fsck_optionsstruct, then the initialization the default with code is dead easy---you can just do it immediately after you x[cm]alloc()---no?
There is no alloc. Right now, the initialization reads:
struct fsck_options options = strict ? FSCK_OPTIONS_STRICT : FSCK_OPTIONS_DEFAULT;
Ciao,
Dscho
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Quoted 8 lines · Johannes Schindelin
Quoted 7 lines
Quoted 5 lines · Johannes Schindelin
And *still*, this is *just* a global table with defaults. I would *still* need to copy-on-write when the first customization of the severity level takes place because I cannot allow the global defaults to be modified by one caller (that would defeat the whole purpose of having per-caller settings bundled in the
fsck_optionsstruct).
Quoted 4 lines
There is no alloc. Right now, the initialization reads:
struct
fsck_optionsoptions = strict ?
FSCK_OPTIONS_STRICT:FSCK_OPTIONS_DEFAULT;
Then it is just the matter of having
fsck_options_init(&options);
if (strict)
options.some_field = make_it_strict;as the first few statements, no?
I am not sure why it is so difficult....
Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 17 lines · Junio C Hamano
Quoted 8 lines · Johannes Schindelin
Quoted 7 lines
Quoted 5 lines · Johannes Schindelin
And *still*, this is *just* a global table with defaults. I would *still* need to copy-on-write when the first customization of the severity level takes place because I cannot allow the global defaults to be modified by one caller (that would defeat the whole purpose of having per-caller settings bundled in the
fsck_optionsstruct).Quoted 4 lines
There is no alloc. Right now, the initialization reads:
struct
fsck_optionsoptions = strict ?
FSCK_OPTIONS_STRICT:FSCK_OPTIONS_DEFAULT;Then it is just the matter of having
Quoted 7 lines
fsck_options_init(&options); if (strict) options.some_field = make_it_strict;as the first few statements, no?
I am not sure why it is so difficult....
It is not difficult. But I try to avoid complexity when I can. Since you asked specifically, I will introduce it, though. Hopefully still this year (I'll not be available for a while starting tomorrow).
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Johannes SchindelinQuoted 7 lines · Johannes Schindelin
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Except that cunning me has made it so that both missing-tagger-entry *and* missingTaggerEntry work...
Then the missing-tagger-entry side needs to be dropped. The naming does not conform to the way how we name our officially supported configuration variables.
But it does conform with the way we do our command-line parameters,
Hmmm.... What is the expected user interaction? The way I read the series was ($MISSING_TAGGER stands for the "token" we choose to show):
(1) The user runs fsck without customization, and may see a warning (or error):
$ git fsck
error in tag d6602ec5194c87b0fc87103ca4d67251c76f233a: $MISSING_TAGGER
(2) The user demotes it to warning and runs fsck again:
$ git config fsck.$MISSING_TAGGER warn
$ git fsck
warning: tag d6602ec5194c87b0fc87103ca4d67251c76f233a: $MISSING_TAGGER
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfError
Then a one-shot override would make sense and easier to give as command line option, e.g.
$ git fsck --warn=missingTagger,someOtherKindOfError
But the proposed organization to use one variable per questionable event type (as opposed to one variable per severity level) would lead to a one-shot override of this form, e.g.
$ git fsck --missing-tagger=warn --some-other-kind-of-error=warn
which I think is insane to require us to support unbound number of dashed options.
Or are you saying that we allow "git config core.file-mode true" from the command line to set core.fileMode configuration?
Puzzled...
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 25 lines · Junio C Hamano
Quoted 8 lines · Johannes Schindelin
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Of course you can say that! ;-) The problem these ugly messages try to solve is to give the user a hint which setting to change if they want to override the default behavior, though...
Ahh, OK, then dashed form would not work as a configuration variable names, so missingTaggerEntry would be the only usable option.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Except that cunning me has made it so that both missing-tagger-entry *and* missingTaggerEntry work...
Then the missing-tagger-entry side needs to be dropped. The naming does not conform to the way how we name our officially supported configuration variables.
But it does conform with the way we do our command-line parameters,
Hmmm.... What is the expected user interaction? The way I read the series was ($MISSING_TAGGER stands for the "token" we choose to show):
(1) The user runs fsck without customization, and may see a warning (or error):
Quoted 8 lines
$ git fsck
error in tagd6602ec5194c87b0fc87103ca4d67251c76f233a: $MISSING_TAGGER(2) The user demotes it to warning and runs fsck again:
$ git config fsck.$MISSING_TAGGER warn
$ git fsck
warning: tagd6602ec5194c87b0fc87103ca4d67251c76f233a: $MISSING_TAGGER
The intended use case is actually when receive.fsckObjects = true and you call git push, seeing 'remote: error: $MULTIPLE_AUTHORS: ...'.
Now, the $MULTIPLE_AUTHORS *config* setting is parsed by git receive-pack, but that is not the command that needs to customize the fsck call: it is either git index-pack or git unpack-objects. So what git receive-pack does is to pass the config options as command-line options to the called command. For consistency with the rest of Git, the command-line options were *not* camel-cased, but lower-case, dash-separated.
The parser I wrote actually accepts both versions, allowing me to skip the tedious step to convert the camelCased config setting into a lower-case-dashed version to pass to index-pack or unpack-objects, only to be parsed by the same parser as fsck would use directly.
So I am rather happy with the fact that the parser handles both camelCased and lower-case-dashed versions.
Quoted 4 lines
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfError
I had something similar in an earlier version of my patch series, but it was shot down rightfully: if you want to allow inheriting defaults from $HOME/.gitconfig, you have to configure the severity levels individually.
(The current solution also sidesteps the problematic situation when both fsck.warn *and* fsck.error contain, say, missingTagger.)
Quoted 4 lines
Then a one-shot override would make sense and easier to give as command line option, e.g.
$ git fsck --warn=missingTagger,someOtherKindOfError
Yep, my first implementation actually used --strict=missing-tagger,-some-demoted-error. But as I mentioned above, that approach is not as flexible as the current one.
Quoted 8 lines
But the proposed organization to use one variable per questionable event type (as opposed to one variable per severity level) would lead to a one-shot override of this form, e.g.
$ git fsck --missing-tagger=warn --some-other-kind-of-error=warnwhich I think is insane to require us to support unbound number of dashed options.
The intended use case is actually *not* the command-line, but the config file, in particular allowing /etc/gitconfig, $HOME/.gitconfig *and* .git/config to customize the settings.
Quoted 2 lines
Or are you saying that we allow "git config core.file-mode true" from the command line to set core.fileMode configuration?
I do not understand this reference. I did not suggest to change git config, did I? If I did, I apologize; it was definitely *not* my intention to change long-standing customs.
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 7 lines · Johannes Schindelin
The parser I wrote actually accepts both versions, allowing me to skip the tedious step to convert the camelCased config setting into a lower-case-dashed version to pass to
index-packorunpack-objects, only to be parsed by the same parser asfsckwould use directly.So I am rather happy with the fact that the parser handles both camelCased and lower-case-dashed versions.
That is myopic view of the world that ignores maintainability and teachability, doing disservice to our user base.
What message does it send to an unsuspecting new user that fsck.random-error is silently accepted (because we will never document it) as an alias for fsck.randomError, while most of the configuration variables will not take such an alias?
Quoted 8 lines
Quoted 4 lines
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfErrorI had something similar in an earlier version of my patch series, but it was shot down rightfully: if you want to allow inheriting defaults from $HOME/.gitconfig, you have to configure the severity levels individually.
Hmmm. What's wrong with "fsck.warn -missingTagger" that overrides the earlier one, or even "fsck.info missingTagger" after having "fsck.warn other,missingTagger,yetanother", with the usual "last one wins" rule?
Whoever shot it down "rightfully" is wrong here, I would think.
Quoted 4 lines
Quoted 4 lines
But the proposed organization to use one variable per questionable event type (as opposed to one variable per severity level) would lead to a one-shot override of this form, e.g.
Quoted 8 lines
Quoted 4 lines
$ git fsck --missing-tagger=warn --some-other-kind-of-error=warnwhich I think is insane to require us to support unbound number of dashed options.
The intended use case is actually *not* the command-line, but the config file, in particular allowing
/etc/gitconfig, $HOME/.gitconfig *and* .git/config to customize the settings.
But we do need to worry about one-shot override from the command line. A configuration that sticks without a way to override is a no-no.
Quoted 4 lines
Quoted 2 lines
Or are you saying that we allow "git config core.file-mode true" from the command line to set core.fileMode configuration?
I do not understand this reference.
I was puzzled by your "command line" and wondering if you meant "from the command line, aVariable can be spelled a-variable".
Quoted 3 lines
I did not suggest to change `git
config`, did I? If I did, I apologize; it was definitely *not* my intention to change long-standing customs.
Then fsck.missing-tagger is definitely out. Long standing customs is that a multi-word token at the first and the last level is not dashed-multi-word.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin
The parser I wrote actually accepts both versions, allowing me to skip the tedious step to convert the camelCased config setting into a lower-case-dashed version to pass to
index-packorunpack-objects, only to be parsed by the same parser asfsckwould use directly.
Quoted 5 lines
Quoted 2 lines
So I am rather happy with the fact that the parser handles both camelCased and lower-case-dashed versions.
That is myopic view of the world that ignores maintainability and teachability, doing disservice to our user base.
Okay, so just to clarify: you want me to
- split the parser into
- a parser that accepts only camelCased variable names when they come from the config (for use in fsck and receive-pack), and
- another parser that rejects camelCased variable names and only accepts lower-case-dashed, intended for command-line parsing in fsck, index-pack and unpack-objects, and
- consequently have a converter from the camelCased variable names we receive from the config in receive-pack so we can pass lower-case-dashed settings to index-pack and unpack-objects.
If you want it this way, I will do it this way.
Quoted 4 lines
What message does it send to an unsuspecting new user that fsck.random-error is silently accepted (because we will never document it) as an alias for fsck.randomError, while most of the configuration variables will not take such an alias?
I will not participate in a discussion about consistency again. There is nothing that can be done about it; what matters is what you will accept and what not. I will make the code stricter (and consequently more complex) if that is what you want.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfErrorI had something similar in an earlier version of my patch series, but it was shot down rightfully: if you want to allow inheriting defaults from $HOME/.gitconfig, you have to configure the severity levels individually.
Quoted 4 lines
Hmmm. What's wrong with "fsck.warn -missingTagger" that overrides the earlier one, or even "fsck.info missingTagger" after having "fsck.warn other,missingTagger,yetanother", with the usual "last one wins" rule?
I will change the code (next year...).
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
But the proposed organization to use one variable per questionable event type (as opposed to one variable per severity level) would lead to a one-shot override of this form, e.g.
$ git fsck --missing-tagger=warn --some-other-kind-of-error=warnwhich I think is insane to require us to support unbound number of dashed options.
Quoted 7 lines
Quoted 3 lines
The intended use case is actually *not* the command-line, but the config file, in particular allowing
/etc/gitconfig, $HOME/.gitconfig *and* .git/config to customize the settings.But we do need to worry about one-shot override from the command line. A configuration that sticks without a way to override is a no-no.
And of course you can, by specifying the config setting via the -c command-line option. The only inconsistency here is that all other command-line options are lower-case-dashed, while the config settings are camelCased.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Or are you saying that we allow "git config core.file-mode true" from the command line to set core.fileMode configuration?
I do not understand this reference.
I was puzzled by your "command line" and wondering if you meant "from the command line, aVariable can be spelled a-variable".
Well, of course, if you call git -c aVariable command --option=a-variable you have a nice accumulation of styles right there ;-)
Quoted 7 lines
Quoted 3 lines
I did not suggest to change
git config, did I? If I did, I apologize; it was definitely *not* my intention to change long-standing customs.Then fsck.missing-tagger is definitely out. Long standing customs is that a multi-word token at the first and the last level is not dashed-multi-word.
But I already changed all of the patches to fsck.missingTagger.
The only thing I did not do yet is to split the parser into two, one accepting only camelCased, one accepting only lower-case-dashed options, and a translator to convert from camelCase to lower-case-dashed versions (because it is a lot of work and additional complexity, as well as opportunity for bugs to hide because we'll have three code paths). I asked you above whether you want that, and I will do it if you say that you do.
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 6 lines · Johannes Schindelin
Okay, so just to clarify: you want me to
- split the parser into
- a parser that accepts only camelCased variable names when they come from the config (for use in fsck and receive-pack), and
OK.
Quoted 7 lines
- another parser that rejects camelCased variable names and only accepts lower-case-dashed, intended for command-line parsing in fsck, index-pack and unpack-objects, and
- consequently have a converter from the camelCased variable names we receive from the config in receive-pack so we can pass lower-case-dashed settings to index-pack and unpack-objects.
I am not sure about the latter two. This needs a design discussion what the command line options should be.
I think the command line should be like this:
git cmd --warn=missingTags,missingAuthor
in the first place, i.e. "we may invent tokens to denote new kinds of errors as we improve fsck", not with "we may add options for new kinds of errors", i.e. the command line should not look like this:
git cmd --missing-tags=warn --missing-author=warn
And from that point of view, I see no reason to support the dashed variant anywhere in the code, neither in the config parser or in the command line parser.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 19 lines · Junio C Hamano
Quoted 6 lines · Johannes Schindelin
Okay, so just to clarify: you want me to
- split the parser into
- a parser that accepts only camelCased variable names when they come from the config (for use in fsck and receive-pack), and
OK.
Quoted 7 lines
- another parser that rejects camelCased variable names and only accepts lower-case-dashed, intended for command-line parsing in fsck, index-pack and unpack-objects, and
- consequently have a converter from the camelCased variable names we receive from the config in receive-pack so we can pass lower-case-dashed settings to index-pack and unpack-objects.
Quoted 6 lines
I am not sure about the latter two. This needs a design discussion what the command line options should be.
I think the command line should be like this:
git cmd --warn=missingTags,missingAuthor
Okay. This contradicts the convention where Git uses lower-case-dashed command-line option values (e.g. on-demand, error-all, etc) and no camelCased options were present so far. But your wish is my command.
Ciao,
Dscho
Quoted 11 lines
in the first place, i.e. "we may invent tokens to denote new kinds of errors as we improve fsck", not with "we may add options for new kinds of errors", i.e. the command line should not look like this:
git cmd --missing-tags=warn --missing-author=warnAnd from that point of view, I see no reason to support the dashed variant anywhere in the code, neither in the config parser or in the command line parser.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Junio C HamanoQuoted 30 lines · Junio C Hamano
Quoted 6 lines · Johannes Schindelin
Okay, so just to clarify: you want me to
- split the parser into
- a parser that accepts only camelCased variable names when they come from the config (for use in fsck and receive-pack), and
OK.
Quoted 7 lines
- another parser that rejects camelCased variable names and only accepts lower-case-dashed, intended for command-line parsing in fsck, index-pack and unpack-objects, and
- consequently have a converter from the camelCased variable names we receive from the config in receive-pack so we can pass lower-case-dashed settings to index-pack and unpack-objects.
I am not sure about the latter two. This needs a design discussion what the command line options should be.
I think the command line should be like this:
git cmd --warn=missingTags,missingAuthorin the first place, i.e. "we may invent tokens to denote new kinds of errors as we improve fsck", not with "we may add options for new kinds of errors", i.e. the command line should not look like this:
Quoted 5 lines
git cmd --missing-tags=warn --missing-author=warnAnd from that point of view, I see no reason to support the dashed variant anywhere in the code, neither in the config parser or in the command line parser.
Having said that, I think "missingTags" etc. should not be configuration variable names (instead, they should be values).
Because of that, I do not think we need consistency between the way these "tokens that denote kinds of errors fsck denotes" are spelled and the way "configuration variable names" are spelled.
In other words, I do not think there is nothing that comes from how our configuration variable names are spelled that gives preference to one over the other between the two styles:
(1) Tokens are camelCased
[fsck]
warn = missingTagger,missingAuthor
error = zeroPadTreeEntry
$ git cmd --warn=missingTagger,missingAuthor(2) Tokens are dashed-multi-words
[fsck]
warn = missing-tagger,missing-author
error = zero-pad-tree-entry
$ git cmd --warn=missing-tagger,missing-authorDo I have a strong preference between these two?
Not really. My gut reaction is that (2) may be easier to read, but I can be persuaded either way.
Who else has/had opinions on this? Earlier you said that the configuration the other way, i.e. "[fsck] warn = missingTag", was shot down---who did shoot it? Perhaps that person may be able to point out where in my thinking above I am going in the wrong direction.
Thanks.
[Footnote]
In either case, I'd recommend that we take [ ,]+ as inter-token separator to ease the use on the command line and config file, to allow these:
[fsck] warn = missingTagger missingAuthor warn = missingTagger,missingAuthor $ git cmd --warn missingTagger,missingAuthor $ git cmd --warn "missingTagger missingAuthor"
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 6 lines · Junio C Hamano
Having said that, I think "missingTags" etc. should not be configuration variable names (instead, they should be values).
Because of that, I do not think we need consistency between the way these "tokens that denote kinds of errors fsck denotes" are spelled and the way "configuration variable names" are spelled.
Okay. That makes more sense.
Now I can remove the complexity introduced by teaching the parser to accept camelCased values, and we're golden.
Quoted 2 lines
In either case, I'd recommend that we take [ ,]+ as inter-token separator to ease the use on the command line and config file
And this is indeed the case:
+void fsck_strict_mode(struct fsck_options *options, const char *mode)
+...
+ while (*mode) {
+ int len = strcspn(mode, " ,|"), equal, msg_id;
+...
In other words, I even allowed the pipe symbol as separator.
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 4 lines · Johannes Schindelin
Hi Junio,
On Tue, 23 Dec 2014, Junio C Hamano wrote:
Quoted 8 lines
Quoted 6 lines
Having said that, I think "missingTags" etc. should not be configuration variable names (instead, they should be values).
Because of that, I do not think we need consistency between the way these "tokens that denote kinds of errors fsck denotes" are spelled and the way "configuration variable names" are spelled.
Okay. That makes more sense.
I am sorry that I didn't step back and think about it earlier to notice that we shouldn't be talking about configuration variable name syntax. I could have saved us time going back and forth if I did so earlier.
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Johannes Schindelin
Quoted 6 lines · Junio C Hamano
Having said that, I think "missingTags" etc. should not be configuration variable names (instead, they should be values).
Because of that, I do not think we need consistency between the way these "tokens that denote kinds of errors fsck denotes" are spelled and the way "configuration variable names" are spelled.
Quoted 5 lines
Quoted 1 line
Okay. That makes more sense.
I am sorry that I didn't step back and think about it earlier to notice that we shouldn't be talking about configuration variable name syntax. I could have saved us time going back and forth if I did so earlier.
Do not worry. You were just trying to make this software better, same as I tried.
Unfortunately, I will not be able to submit v2 of this patch series this year, but I will do so in the second week of January (including the change to the global array with the default severity levels because I do want to see this feature integrated).
Ciao,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Quoted 4 lines · Johannes Schindelin
Unfortunately, I will not be able to submit v2 of this patch series this year, but I will do so in the second week of January (including the change to the global array with the default severity levels because I do want to see this feature integrated).
Heh, we are not in a hurry. Enjoy your holidays.
A happy new year to you in advance ;-)
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Junio C HamanoQuoted 4 lines · Junio C Hamano
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfError
By the way, I think I like this organization is much better than the other way around, i.e. "fsck.missingTagger=warn", as we do not want the namespace under fsck.* for variables that control the behaviour of fsck that are *NOT* kinds of questionable conditions fsck can find.
PATCH v2 10/18 fsck: Make fsck_tag() warn-friendly
In reply to Johannes SchindelinWhen fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.
--- fsck.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
@@ -614,7 +614,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, }if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { ret =report (options, &tag->object,FSCK_MSG_INVALID_OBJECT_SHA1 ,"invalid 'object' line format - bad sha1" ); - goto done; +if (ret) + goto done; } buffer +=41 ;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 11/18 fsck: Add a simple test for receive.fsck.*
In reply to Johannes Schindelin--- t/t5504-fetch-receive-strict.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
t/t5504-fetch-receive-strict.sh +20 -0
@@ -115,4 +115,24 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' +cat >bogus-commit << EOF +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +author Bugs Bunny 1234567890 +0000 +committer Bugs Bunny <[email protected]> 1234567890 +0000 + +This commit object intentionally broken +EOF + +test_expect_success 'push with receive.fsck.warn = missing-email' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.warn missing-email && + git push --porcelain dst bogus >act 2>&1 && + grep "missing-email" act +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 13/18 fsck: Optionally ignore specific fsck issues completely
In reply to Johannes SchindelinAn fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective error to "ignore".
This change "abuses" the warn=missing-email test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).
--- fsck.c | 5 +++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
fsck.c +5 -0
@@ -152,6 +152,8 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) severity =FSCK_ERROR ; else if (!substrcmp(mode, equal, "warn")) severity =FSCK_WARN ; + else if (!substrcmp(mode, equal, "ignore")) + severity =FSCK_IGNORE ; else die("Unknown fsck message severity: '%.*s'", equal, mode);
@@ -193,6 +195,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_IGNORE ) +return 0 ; +if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ;
fsck.h +1 -0
@@ -3,6 +3,7 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +#define FSCK_IGNORE 3struct fsck_options ;
t/t5504-fetch-receive-strict.sh +6 -1
@@ -132,7 +132,12 @@ test_expect_success 'push with receive.fsck.warn = missing-email' ' test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config receive.fsck.warn missing-email && git push --porcelain dst bogus >act 2>&1 && - grep "missing-email" act + grep "missing-email" act && + git --git-dir=dst/.git branch -D bogus && + git --git-dir=dst/.git config receive.fsck.ignore missing-email && + git --git-dir=dst/.git config receive.fsck.warn bad-date && + git push --porcelain dst bogus >act 2>&1 && + test_must_fail grep "missing-email" act ' test_expect_success 'receive.fsck.warn = unterminated-header triggers error' '
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 15/18 fsck: Document the new receive.fsck.* options.
In reply to Johannes Schindelin--- Documentation/config.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Documentation/config.txt +25 -0
@@ -2130,6 +2130,31 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.*:: + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.*` + settings. These settings contain comma-separated lists of fsck + message IDs. For convenience, fsck prefixes the error/warning with + the message ID, e.g. "missing-email: invalid author/committer line + - missing email" means that setting `receive.fsck.ignore = + missing-email` will hide that issue. ++ +-- + error:: + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. + warn:: + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. + ignore:: + a comma-separated list of fsck message IDs that should be + ignored completely. ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories certain known issues but still catch +other issues. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
v2 cover Introduce an internal API to interact with the fsck machinery
In reply to Junio C HamanoAt the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.
This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.
I am proud to report that this work has been sponsored by GitHub.
Interdiff vs v1 below the diffstat. Sorry for the size; the comments I received for v1 made it necessary to change the patch series rather extensively (I rebased the branch twenty-five times since sending off the first version of the patch series, which might also serve as an apology for not getting v2 out sooner).
Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings
fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.*
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.* options.
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --quick
fsck: git receive-pack: support excluding objects from fsck'ing
Documentation/config.txt | 38 +++ Documentation/git-fsck.txt | 7 +- builtin/fsck.c | 66 +++-- builtin/index-pack.c | 13 +- builtin/receive-pack.c | 35 ++- builtin/unpack-objects.c | 16 +- fsck.c | 525 +++++++++++++++++++++++++++++++--------- fsck.h | 27 ++- t/t1450-fsck.sh | 37 ++- t/t5302-pack-index.sh | 2 +- t/t5504-fetch-receive-strict.sh | 46 ++++ 11 files changed, 648 insertions(+), 164 deletions(-)
Documentation/config.txt +29 -18
@@ -1209,14 +1209,14 @@ filter.<driver>.smudge:: linkgit:gitattributes[5] for details. fsck.*:: - With these options, fsck errors can be switched to warnings and - vice versa by setting e.g. `fsck.bad-name` to `warn` or `error` - (or `ignore` to hide those errors completely). For convenience, - fsck prefixes the error/warning with the name of the option, e.g. - "missing-email: invalid author/committer line - missing email" - means that setting `fsck.missing-email` to `ignore` will hide that - issue. For convenience, camelCased options are accepted, too (e.g. - `fsck.missingEmail`). + The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify + comma-separated lists of fsck message IDs which should trigger + fsck to error out, to print the message and continue, or to ignore + said messages, respectively. ++ +For convenience, fsck prefixes the error/warning with the name of the option, +e.g. "missing-email: invalid author/committer line - missing email" means +that setting `fsck.ignore = missing-email` will hide that issue. + This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes.
@@ -2144,18 +2144,29 @@ receive.fsckObjects:: is used instead. receive.fsck.*:: - When `receive.fsckObjects is set to true, errors can be switched - to warnings and vice versa by setting e.g. `receive.fsck.bad-name` - to `warn` or `error` (or `ignore` to hide those errors - completely). For convenience, fsck prefixes the error/warning - with the name of the option, e.g. "missing-email: invalid - author/committer line - missing email" means that setting - `receive.fsck.missing-email` to `ignore` will hide that issue. - For convenience, camelCased options are accepted, too (e.g. - `receive.fsck.missingEmail`). + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.*` + settings. These settings contain comma-separated lists of fsck + message IDs. For convenience, fsck prefixes the error/warning with + the message ID, e.g. "missing-email: invalid author/committer line + - missing email" means that setting `receive.fsck.ignore = + missing-email` will hide that issue. ++ +-- + error:: + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. + warn:: + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. + ignore:: + a comma-separated list of fsck message IDs that should be + ignored completely. + This feature is intended to support working with legacy repositories -which would not pass pushing when `receive.fsckObjects = true`. +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories certain known issues but still catch +other issues. receive.unpackLimit:: If the number of objects received in a push is below this
builtin/fsck.c +2 -2
@@ -51,8 +51,8 @@ static int fsck_config(const char *var, const char *value, void *cb) {if (starts_with (var,"fsck." )) {struct strbuf sb =STRBUF_INIT ; -strbuf_addf (&sb,"%s=%s" , var +5 , value ? value :"error" ); -fsck_strict_mode (&fsck_obj_options, sb.buf); +strbuf_addf (&sb,"%s=%s" , var +5 , value); +fsck_set_severity (&fsck_obj_options, sb.buf);strbuf_release (&sb);return 0 ; }
builtin/index-pack.c +1 -1
@@ -1568,7 +1568,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (starts_with (arg,"--strict=" )) { strict =1 ; do_fsck_object =1 ; -fsck_strict_mode (&fsck_options, arg +9 ); +fsck_set_severity (&fsck_options, arg +9 ); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +12 -13
@@ -36,7 +36,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; -static struct strbuf fsck_strict_mode =STRBUF_INIT ; +static struct strbuf fsck_severity =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int advertise_atomic_push =1 ;
@@ -116,20 +116,19 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } -if (starts_with (var,"receive.fsck.skip-list" )) { +if (starts_with (var,"receive.fsck.skiplist" )) {const char *path =is_absolute_path (value) ? value :git_path ("%s" , value); -if (fsck_strict_mode.len) -strbuf_addch (&fsck_strict_mode,',' ); -strbuf_addf (&fsck_strict_mode,"skip-list=%s" , path); +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"skiplist=%s" , path);return 0 ; }if (starts_with (var,"receive.fsck." )) { -if (fsck_strict_mode.len) -strbuf_addch (&fsck_strict_mode,',' ); -strbuf_addf (&fsck_strict_mode, -"%s=%s" , var +13 , value ? value :"error" ); +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"%s=%s" , var +13 , value);return 0 ; }
@@ -1489,9 +1488,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)if (quiet)argv_array_push (&child.args,"-q" );if (fsck_objects) { -if (fsck_strict_mode.len) +if (fsck_severity.len)argv_array_pushf (&child.args,"--strict=%s" , - fsck_strict_mode.buf); + fsck_severity.buf);else argv_array_push (&child.args,"--strict" ); }
@@ -1512,9 +1511,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL );if (fsck_objects) { -if (fsck_strict_mode.len) +if (fsck_severity.len)argv_array_pushf (&child.args,"--strict=%s" , - fsck_strict_mode.buf); + fsck_severity.buf);else argv_array_push (&child.args,"--strict" ); }
builtin/unpack-objects.c +1 -1
@@ -532,7 +532,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) }if (starts_with (arg,"--strict=" )) { strict =1 ; -fsck_strict_mode (&fsck_options, arg +9 ); +fsck_set_severity (&fsck_options, arg +9 );continue ; }if (starts_with (arg,"--pack_header=" )) {
fsck.c +132 -120
361 lines not on this page · raw message
fsck.h +4 -5
@@ -7,7 +7,7 @@struct fsck_options ; -void fsck_strict_mode (struct fsck_options *options,const char *mode); +void fsck_set_severity (struct fsck_options *options,const char *mode);/* * callback function for fsck_walk
@@ -27,10 +27,9 @@ int fsck_error_function(struct object *obj, int type, const char *message);struct fsck_options {fsck_walk_func walk;fsck_error error_func; -int strict:1 ; -int *strict_mode; -/* TODO: consider reading into a hashmap */ -struct sha1_array *skip_list; +unsigned strict:1 ; +int *msg_severity; +struct sha1_array *skiplist; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t1450-fsck.sh +3 -3
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' git fsck --tags 2>out && cat >expect <<-EOF && - warning in tag $tag: invalid '\''tag'\'' name: wrong name format - warning in tag $tag: invalid format - expected '\''tagger'\'' line + warning in tag $tag: invalid-tag-name: invalid '\''tag'\'' name: wrong name format + warning in tag $tag: missing-tagger-entry: invalid format - expected '\''tagger'\'' line EOF test_cmp expect out '
@@ -295,7 +295,7 @@ test_expect_success 'force fsck to ignore double author' ' git update-ref refs/heads/bogus "$new" && test_when_finished "git update-ref -d refs/heads/bogus" && test_must_fail git fsck && - git -c fsck.multiple-authors=ignore fsck + git -c fsck.ignore=multiple-authors fsck ' _bz='\0'
t/t5504-fetch-receive-strict.sh +9 -9
@@ -123,42 +123,42 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000 This commit object intentionally broken EOF -test_expect_success 'push with receive.fsck.skip-list' ' +test_expect_success 'push with receive.fsck.skiplist' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus && rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && test_must_fail git push --porcelain dst bogus && - git --git-dir=dst/.git config receive.fsck.skip-list SKIP && + git --git-dir=dst/.git config receive.fsck.skiplist SKIP && echo $commit > dst/.git/SKIP && git push --porcelain dst bogus ' -test_expect_success 'push with receive.fsck.missing-mail = warn' ' +test_expect_success 'push with receive.fsck.warn = missing-email' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus && rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && test_must_fail git push --porcelain dst bogus && - git --git-dir=dst/.git config receive.fsck.missing-email warn && + git --git-dir=dst/.git config receive.fsck.warn missing-email && git push --porcelain dst bogus >act 2>&1 && grep "missing-email" act && git --git-dir=dst/.git branch -D bogus && - git --git-dir=dst/.git config receive.fsck.missing-email ignore && - git --git-dir=dst/.git config receive.fsck.bad-date warn && + git --git-dir=dst/.git config receive.fsck.ignore missing-email && + git --git-dir=dst/.git config receive.fsck.warn bad-date && git push --porcelain dst bogus >act 2>&1 && test_must_fail grep "missing-email" act ' -test_expect_success 'receive.fsck.unterminated-header = warn triggers error' ' +test_expect_success 'receive.fsck.warn = unterminated-header triggers error' ' rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && - git --git-dir=dst/.git config receive.fsck.unterminated-header warn && + git --git-dir=dst/.git config receive.fsck.warn unterminated-header && test_must_fail git push --porcelain dst HEAD >act 2>&1 && - grep "Cannot demote unterminated-header=warn" act + grep "Cannot demote unterminated-header" act ' test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 1/18 fsck: Introduce fsck options
Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.
--- builtin/fsck.c | 20 +++++-- builtin/index-pack.c | 9 +-- builtin/unpack-objects.c | 11 ++-- fsck.c | 150 +++++++++++++++++++++++------------------------ fsck.h | 17 +++++- 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
@@ -25,6 +25,8 @@ static int include_reflogs = 1;static int check_full =1 ;static int check_strict;static int keep_cache_objects; +static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;static unsigned char head_sha1[20 ];static const char *head_points_at;static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)static struct object_array pending; -static int mark_object (struct object *obj,int type,void *data) +static int mark_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct object *parent = data;
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)static void mark_object_reachable (struct object *obj) { -mark_object (obj,OBJ_ANY ,NULL ); +mark_object (obj,OBJ_ANY ,NULL ,NULL ); }static int traverse_one_object (struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)if (parse_tree (tree) <0 )return 1 ;/* error already displayed */ } - result =fsck_walk (obj, mark_object, obj); + result =fsck_walk (obj, obj, &fsck_walk_options);if (tree)free_tree_buffer (tree);return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data) +static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return 1 ;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)fprintf (stderr,"Checking %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); -if (fsck_walk (obj, mark_used,NULL )) +if (fsck_walk (obj,NULL , &fsck_obj_options))objerror (obj,"broken links" ); -if (fsck_object (obj,NULL ,0 , check_strict, fsck_error_func)) +if (fsck_object (obj,NULL ,0 , &fsck_obj_options))return -1 ;if (obj->type ==OBJ_TREE ) {
@@ -630,6 +632,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, fsck_opts, fsck_usage,0 ); + fsck_walk_options.walk = mark_object; + fsck_obj_options.walk = mark_used; + fsck_obj_options.error_func = fsck_error_func; +if (check_strict) + fsck_obj_options.strict =1 ; +if (show_progress ==-1 ) show_progress =isatty (2 );if (verbose)
builtin/index-pack.c +5 -4
@@ -74,6 +74,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static int verbose;static int show_stat;static int check_self_contained_and_connected;
@@ -191,7 +192,7 @@ static void cleanup_thread(void)#endif -static int mark_link (struct object *obj,int type,void *data) +static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return -1 ;
@@ -782,10 +783,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,if (!obj)die (_ ("invalid %s" ),typename (type));if (do_fsck_object && -fsck_object (obj, buf, size,1 , - fsck_error_function)) +fsck_object (obj, buf, size, &fsck_options))die (_ ("Error in object" )); -if (fsck_walk (obj, mark_link,NULL )) + fsck_options.walk = mark_link; +if (fsck_walk (obj,NULL , &fsck_options))die (_ ("Not all child objects of %s are reachable" ),sha1_to_hex (obj->sha1));if (obj->type ==OBJ_TREE ) {
builtin/unpack-objects.c +6 -5
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];static unsigned int offset, len;static off_t consumed_bytes;static git_SHA_CTX ctx; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;/* * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data) +static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data) obj_buf =lookup_object_buffer (obj);if (!obj_buf)die ("Whoops! Cannot find object '%s'" ,sha1_to_hex (obj->sha1)); -if (fsck_object (obj, obj_buf->buffer, obj_buf->size,1 , - fsck_error_function)) +if (fsck_object (obj, obj_buf->buffer, obj_buf->size, &fsck_options))die ("Error in object" ); -if (fsck_walk (obj, check_object,NULL )) + fsck_options.walk = check_object; +if (fsck_walk (obj,NULL , &fsck_options))die ("Error on reachable objects of %s" ,sha1_to_hex (obj->sha1));write_cached_object (obj, obj_buf);return 0 ;
@@ -217,7 +218,7 @@ static void write_rest(void)unsigned i;for (i =0 ; i < nr_objects; i++) {if (obj_list[i].obj) -check_object (obj_list[i].obj,OBJ_ANY ,NULL ); +check_object (obj_list[i].obj,OBJ_ANY ,NULL ,NULL ); } }
fsck.c +75 -75
392 lines not on this page · raw message
fsck.h +14 -3
@@ -4,6 +4,8 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +struct fsck_options ; +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data); +typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); __attribute__((format (printf,3 ,4 )))int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +unsigned strict:1 ; +}; + +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +/* descend in all linked child objects * the return value is: * -1 error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);* >0 return value of the first signaled error >0 (in the case of no other errors) * 0 everything OK */ -int fsck_walk (struct object *obj,fsck_walk_func walk,void *data); +int fsck_walk (struct object *obj,void *data,struct fsck_options *options);/* If NULL is passed for data, we assume the object is local and read it. */ int fsck_object (struct object *obj,void *data,unsigned long size, -int strict,fsck_error error_func); +struct fsck_options *options);#endif
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 2/18 fsck: Introduce identifiers for fsck messages
In reply to Johannes SchindelinInstead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.
In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.
We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate severity levels. Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.
--- builtin/fsck.c | 24 ++----- fsck.c | 201 +++++++++++++++++++++++++++++++++++++++++---------------- fsck.h | 5 +- 3 files changed, 153 insertions(+), 77 deletions(-)
builtin/fsck.c +7 -17
@@ -47,32 +47,22 @@ static int show_dangling = 1;#endif static void objreport (struct object *obj,const char *severity, -const char *err,va_list params) +const char *err) { -fprintf (stderr,"%s in %s %s: " , - severity,typename (obj->type),sha1_to_hex (obj->sha1)); -vfprintf (stderr, err, params); -fputs ("\n" , stderr); +fprintf (stderr,"%s in %s %s: %s\n" , + severity,typename (obj->type),sha1_to_hex (obj->sha1), err); } -__attribute__((format (printf,2 ,3 ))) -static int objerror (struct object *obj,const char *err, ...) +static int objerror (struct object *obj,const char *err) { -va_list params; -va_start (params, err); errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err, params); -va_end (params); +objreport (obj,"error" , err);return -1 ; } -__attribute__((format (printf,3 ,4 ))) -static int fsck_error_func (struct object *obj,int type,const char *err, ...) +static int fsck_error_func (struct object *obj,int type,const char *message) { -va_list params; -va_start (params, err); -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , err, params); -va_end (params); +objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message);return (type ==FSCK_WARN ) ?0 :1 ; }
fsck.c +144 -57
356 lines not on this page · raw message
fsck.h +2 -3
@@ -17,10 +17,9 @@ struct fsck_options;typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ -typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...); +typedef int (*fsck_error )(struct object *obj,int type,const char *message); -__attribute__((format (printf,3 ,4 ))) -int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +int fsck_error_function (struct object *obj,int type,const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 3/18 fsck: Provide a function to parse fsck message IDs
In reply to Johannes SchindelinThis function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, 'missing-email,missing-tagger-entry' command lines.
To make the parsing robust, we generate strings from the enum keys, and using these keys, we will map lower-case, dash-separated strings values to the corresponding enum values.
--- fsck.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
fsck.c +25 -2
@@ -63,15 +63,38 @@ enum fsck_msg_id { };#undef MSG_ID -#define MSG_ID (id, severity) { FSCK_##severity }, +#define STR (x) #x +#define MSG_ID (id, severity) { STR(id), FSCK_##severity },static struct { +const char *id_string;int severity; } msg_id_info[FSCK_MSG_MAX +1 ] = { FOREACH_MSG_ID(MSG_ID) - {-1 } + {NULL ,-1 } };#undef MSG_ID +static int parse_msg_id (const char *text,int len) +{ +int i, j; + +for (i =0 ; i <FSCK_MSG_MAX ; i++) { +const char *key = msg_id_info[i].id_string; +/* id_string is upper-case, with underscores */ +for (j =0 ; j < len; j++) { +char c = *(key++); +if (c =='_' ) + c ='-' ; +if (text[j] !=tolower (c)) +break ; + } +if (j == len && !*key) +return i; + } + +die ("Unhandled message id: %.*s" , len, text); +} +static int fsck_msg_severity (enum fsck_msg_id msg_id,struct fsck_options *options) {
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 4/18 fsck: Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinThere are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.
The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all FSCK_ERROR in those cases.
--- fsck.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- fsck.h | 7 +++++-- 2 files changed, 66 insertions(+), 5 deletions(-)
fsck.c +61 -3
@@ -100,13 +100,67 @@ static int fsck_msg_severity(enum fsck_msg_id msg_id, {int severity; - severity = msg_id_info[msg_id].severity; -if (options->strict && severity ==FSCK_WARN ) - severity =FSCK_ERROR ; +if (options->msg_severity && msg_id >=0 && msg_id <FSCK_MSG_MAX ) + severity = options->msg_severity[msg_id]; +else { + severity = msg_id_info[msg_id].severity; +if (options->strict && severity ==FSCK_WARN ) + severity =FSCK_ERROR ; + }return severity; } +static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +} + +void fsck_set_severity (struct fsck_options *options,const char *mode) +{ +int severity =FSCK_ERROR ; + +if (!options->msg_severity) { +int i; +int *msg_severity =malloc (sizeof (int ) *FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + msg_severity[i] =fsck_msg_severity (i, options); + options->msg_severity = msg_severity; + } + +while (*mode) { +int len =strcspn (mode," ,|" ), equal, msg_id; + +if (!len) { + mode++; +continue ; + } + +for (equal =0 ; equal < len; equal++) +if (mode[equal] =='=' ) +break ; + +if (equal < len) { +if (!substrcmp (mode, equal,"error" )) + severity =FSCK_ERROR ; +else if (!substrcmp (mode, equal,"warn" )) + severity =FSCK_WARN ; +else +die ("Unknown fsck message severity: '%.*s'" , + equal, mode); + mode += equal +1 ; + len -= equal +1 ; + } + + msg_id =parse_msg_id (mode, len); + options->msg_severity[msg_id] = severity; + mode += len; + } +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -596,6 +650,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct object *obj,int severity,const char *message) { +if (severity ==FSCK_WARN ) { +warning ("object %s: %s" ,sha1_to_hex (obj->sha1), message); +return 0 ; + }error ("object %s: %s" ,sha1_to_hex (obj->sha1), message);return 1 ; }
fsck.h +5 -2
@@ -6,6 +6,8 @@struct fsck_options ; +void fsck_set_severity (struct fsck_options *options,const char *mode); +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -25,10 +27,11 @@ struct fsck_options {fsck_walk_func walk;fsck_error error_func; unsigned strict:1; +int *msg_severity; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 5/18 fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
In reply to Johannes SchindelinFor example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.warn = missing-email
The value is actually a comma-separated list, and there is a corresponding receive.fsck.error setting.
In case that the same key is listed in multiple receive.fsck.* lines in the config, the latter configuration wins.
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.
--- builtin/index-pack.c | 4 ++++ builtin/receive-pack.c | 26 ++++++++++++++++++++++---- builtin/unpack-objects.c | 5 +++++ 3 files changed, 31 insertions(+), 4 deletions(-)
builtin/index-pack.c +4 -0
@@ -1565,6 +1565,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (!strcmp (arg,"--strict" )) { strict =1 ; do_fsck_object =1 ; + }else if (starts_with (arg,"--strict=" )) { + strict =1 ; + do_fsck_object =1 ; +fsck_set_severity (&fsck_options, arg +9 ); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +22 -4
@@ -36,6 +36,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; +static struct strbuf fsck_severity =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int advertise_atomic_push =1 ;
@@ -115,6 +116,13 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck." )) { +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"%s=%s" , var +13 , value); +return 0 ; + } +if (strcmp (var,"receive.fsckobjects" ) ==0 ) { receive_fsck_objects =git_config_bool (var, value);return 0 ;
@@ -1470,8 +1478,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"unpack-objects" , hdr_arg,NULL );if (quiet)argv_array_push (&child.args,"-q" ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + } child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1488,8 +1501,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + }if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +5 -0
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } +if (starts_with (arg,"--strict=" )) { + strict =1 ; +fsck_set_severity (&fsck_options, arg +9 ); +continue ; + }if (starts_with (arg,"--pack_header=" )) {struct pack_header *hdr;char *c;
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 6/18 fsck: Report the ID of the error/warning
In reply to Johannes SchindelinSome legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missing-email", the user might want to call git config receive.fsck.warn missing-email).
--- fsck.c | 19 +++++++++++++++++++ t/t1450-fsck.sh | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-)
fsck.c +19 -0
@@ -161,6 +161,23 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) } } +static void append_msg_id (struct strbuf *sb,const char *msg_id) +{ +for (;;) { +char c = *(msg_id)++; + +if (!c) +break ; +if (c =='_' ) + c ='-' ; +else + c =tolower (c); +strbuf_addch (sb, c); + } + +strbuf_addstr (sb,": " ); +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -169,6 +186,8 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +append_msg_id (&sb, msg_id_info[id].id_string); +va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (object, msg_severity, sb.buf);
t/t1450-fsck.sh +2 -2
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' git fsck --tags 2>out && cat >expect <<-EOF && - warning in tag $tag: invalid '\''tag'\'' name: wrong name format - warning in tag $tag: invalid format - expected '\''tagger'\'' line + warning in tag $tag: invalid-tag-name: invalid '\''tag'\'' name: wrong name format + warning in tag $tag: missing-tagger-entry: invalid format - expected '\''tagger'\'' line EOF test_cmp expect out '
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 7/18 fsck: Make fsck_ident() warn-friendly
In reply to Johannes SchindelinWhen fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.
--- fsck.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
@@ -453,40 +453,45 @@ static int require_end_of_header(const void *data, unsigned long size,static int fsck_ident (const char **ident,struct object *obj,struct fsck_options *options) { +const char *p = *ident;char *end; -if (**ident =='<' ) + *ident =strchrnul (*ident,'\n' ); +if (**ident =='\n' ) + (*ident)++; + +if (*p =='<' )return report (options, obj,FSCK_MSG_MISSING_NAME_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - *ident +=strcspn (*ident,"<>\n" ); -if (**ident =='>' ) + p +=strcspn (p,"<>\n" ); +if (*p =='>' )return report (options, obj,FSCK_MSG_BAD_NAME ,"invalid author/committer line - bad name" ); -if (**ident !='<' ) +if (*p !='<' )return report (options, obj,FSCK_MSG_MISSING_EMAIL ,"invalid author/committer line - missing email" ); -if ((*ident)[-1 ] !=' ' ) +if (p[-1 ] !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - (*ident)++; - *ident +=strcspn (*ident,"<>\n" ); -if (**ident !='>' ) + p++; + p +=strcspn (p,"<>\n" ); +if (*p !='>' )return report (options, obj,FSCK_MSG_BAD_EMAIL ,"invalid author/committer line - bad email" ); - (*ident)++; -if (**ident !=' ' ) + p++; +if (*p !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_DATE ,"invalid author/committer line - missing space before date" ); - (*ident)++; -if (**ident =='0' && (*ident)[1 ] !=' ' ) + p++; +if (*p =='0' && p[1 ] !=' ' )return report (options, obj,FSCK_MSG_ZERO_PADDED_DATE ,"invalid author/committer line - zero-padded date" ); -if (date_overflows (strtoul (*ident, &end,10 ))) +if (date_overflows (strtoul (p, &end,10 )))return report (options, obj,FSCK_MSG_DATE_OVERFLOW ,"invalid author/committer line - date causes integer overflow" ); -if (end == *ident || *end !=' ' ) +if ((end == p || *end !=' ' ))return report (options, obj,FSCK_MSG_BAD_DATE ,"invalid author/committer line - bad date" ); - *ident = end +1 ; -if ((**ident !='+' && **ident !='-' ) || - !isdigit ((*ident)[1 ]) || - !isdigit ((*ident)[2 ]) || - !isdigit ((*ident)[3 ]) || - !isdigit ((*ident)[4 ]) || - ((*ident)[5 ] !='\n' )) + p = end +1 ; +if ((*p !='+' && *p !='-' ) || + !isdigit (p[1 ]) || + !isdigit (p[2 ]) || + !isdigit (p[3 ]) || + !isdigit (p[4 ]) || + (p[5 ] !='\n' ))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - (*ident) +=6 ; + p +=6 ;return 0 ; }
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 8/18 fsck: Make fsck_commit() warn-friendly
In reply to Johannes SchindelinWhen fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missing-author error to a warning would hide a problematic committer line.
--- fsck.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
@@ -508,12 +508,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (!skip_prefix (buffer,"tree " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_TREE ,"invalid format - expected 'tree' line" ); -if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ;while (skip_prefix (buffer,"parent " , &buffer)) { -if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ; parent_line_count++; }
@@ -522,11 +528,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (graft) {if (graft->nr_parent ==-1 && !parent_count) ;/* shallow commit */ -else if (graft->nr_parent != parent_count) -return report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +else if (graft->nr_parent != parent_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +if (err) +return err; + } }else { -if (parent_count != parent_line_count) -return report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (parent_count != parent_line_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (err) +return err; + } }if (!skip_prefix (buffer,"author " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_AUTHOR ,"invalid format - expected 'author' line" );
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 9/18 fsck: Handle multiple authors in commits specially
In reply to Johannes SchindelinThis problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
Technically, we could handle such repositories by setting receive.fsck.warn = missing-committer, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.
--- fsck.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fsck.c +9 -0
@@ -38,6 +38,7 @@ FUNC(MISSING_TREE, ERROR) \ FUNC(MISSING_TYPE, ERROR) \ FUNC(MISSING_TYPE_ENTRY, ERROR) \ + FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ FUNC(NUL_IN_HEADER, ERROR) \FUNC (TAG_OBJECT_NOT_TAG ,ERROR ) \
@@ -545,6 +546,14 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, err =fsck_ident (&buffer, &commit->object, options);if (err)return err; +while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err; + err =fsck_ident (&buffer, &commit->object, options); +if (err) +return err; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 12/18 fsck: Disallow demoting grave fsck errors to warnings
In reply to Johannes SchindelinSome kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
--- fsck.c | 13 +++++++++++-- t/t5504-fetch-receive-strict.sh | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
fsck.c +11 -2
@@ -9,7 +9,12 @@#include "refs.h" #include "utf8.h" +#define FSCK_FATAL -1 +#define FOREACH_MSG_ID (FUNC ) \ +/* fatal errors */ \ + FUNC(NUL_IN_HEADER, FATAL) \ + FUNC(UNTERMINATED_HEADER, FATAL) \/* errors */ \ FUNC(BAD_DATE, ERROR) \FUNC (BAD_EMAIL ,ERROR ) \
@@ -40,10 +45,8 @@ FUNC(MISSING_TYPE_ENTRY, ERROR) \ FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ - FUNC(NUL_IN_HEADER, ERROR) \ FUNC(TAG_OBJECT_NOT_TAG, ERROR) \ FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(UNTERMINATED_HEADER, ERROR) \FUNC (ZERO_PADDED_DATE ,ERROR ) \ /* warnings */ \FUNC (BAD_FILEMODE ,WARN ) \
@@ -157,6 +160,9 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) } msg_id =parse_msg_id (mode, len); +if (severity !=FSCK_ERROR && + msg_id_info[msg_id].severity ==FSCK_FATAL ) +die ("Cannot demote %.*s" , len, mode); options->msg_severity[msg_id] = severity; mode += len; }
@@ -187,6 +193,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_FATAL ) + msg_severity =FSCK_ERROR ; +append_msg_id (&sb, msg_id_info[id].id_string);va_start (ap, fmt);
t/t5504-fetch-receive-strict.sh +9 -0
@@ -135,4 +135,13 @@ test_expect_success 'push with receive.fsck.warn = missing-email' ' grep "missing-email" act ' +test_expect_success 'receive.fsck.warn = unterminated-header triggers error' ' + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + git --git-dir=dst/.git config receive.fsck.warn unterminated-header && + test_must_fail git push --porcelain dst HEAD >act 2>&1 && + grep "Cannot demote unterminated-header" act +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 14/18 fsck: Allow upgrading fsck warnings to errors
In reply to Johannes SchindelinThe 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalid-tag-name and missing-tagger-entry to the receive.fsck.error config setting.
Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).
--- fsck.c | 24 +++++++++++++++++------- t/t5302-pack-index.sh | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
@@ -10,6 +10,7 @@#include "utf8.h" #define FSCK_FATAL -1 +#define FSCK_INFO -2#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \
@@ -55,10 +56,11 @@ FUNC(HAS_DOT, WARN) \ FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTGIT, WARN) \ - FUNC(INVALID_TAG_NAME, WARN) \ - FUNC(MISSING_TAGGER_ENTRY, WARN) \ FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) +FUNC (ZERO_PADDED_FILEMODE ,WARN ) \ + /* infos (reported as warnings, but ignored by default) */ \ + FUNC(INVALID_TAG_NAME, INFO) \ + FUNC(MISSING_TAGGER_ENTRY, INFO)#define MSG_ID (id, severity) FSCK_MSG_##id,enum fsck_msg_id {
@@ -200,6 +202,8 @@ static int report(struct fsck_options *options, struct object *object,if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ; +else if (msg_severity ==FSCK_INFO ) + msg_severity =FSCK_WARN ;append_msg_id (&sb, msg_id_info[id].id_string);
@@ -658,15 +662,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, goto done; }strbuf_addf (&sb,"refs/tags/%.*s" , (int )(eol - buffer), buffer); -if (check_refname_format (sb.buf,0 )) -report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME , +if (check_refname_format (sb.buf,0 )) { + ret =report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %.*s" , (int )(eol - buffer), buffer); +if (ret) + goto done; + } buffer = eol +1 ; -if (!skip_prefix (buffer,"tagger " , &buffer)) +if (!skip_prefix (buffer,"tagger " , &buffer)) {/* early tags do not contain 'tagger' lines; warn only */ -report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); + ret =report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); +if (ret) + goto done; + }else ret =fsck_ident (&buffer, &tag->object, options);
t/t5302-pack-index.sh +1 -1
@@ -259,7 +259,7 @@ EOF thirtyeight=${tag#??} && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^error:.* expected .tagger. line" err + grep "^warning:.* expected .tagger. line" err ' test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
Re: [PATCH v2 15/18] fsck: Document the new receive.fsck.* options.
In reply to Johannes SchindelinQuoted 23 lines · Johannes Schindelin
Signed-off-by Johannes Schindelin <[email protected]>---
Documentation/config.txt +13
-0@@ -2130,6 +2130,31 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.*:: + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.*` + settings. These settings contain comma-separated lists of fsck + message IDs. For convenience, fsck prefixes the error/warning with + the message ID, e.g. "missing-email: invalid author/committer line + - missing email" means that setting `receive.fsck.ignore = + missing-email` will hide that issue. ++ +-- + error:: + a comma-separated list of fsck message IDs that should be + trigger fsck to error out.
Documentation/config.txt receive.fsckObjects:: · line 2155
Quoted 10 lines
Documentation/config.txt +10
-0+ warn:: + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. + ignore:: + a comma-separated list of fsck message IDs that should be + ignored completely. ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories certain known issues but still catch
s/certain/with &/
Quoted 14 lines
Documentation/config.txt +2
-1+other issues. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object --2.0.0.rc3.9669.g840d1f9
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 15/18] fsck: Document the new receive.fsck.* options.
Hi Eric,
Quoted 29 lines · Eric Sunshine
Quoted 27 lines · Johannes Schindelin
Signed-off-by Johannes Schindelin <[email protected]>---
Documentation/config.txt +17
-0@@ -2130,6 +2130,31 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.*:: + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.*` + settings. These settings contain comma-separated lists of fsck + message IDs. For convenience, fsck prefixes the error/warning with + the message ID, e.g. "missing-email: invalid author/committer line + - missing email" means that setting `receive.fsck.ignore = + missing-email` will hide that issue. ++ +-- + error:: + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. + warn:: + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. + ignore::
Quoted 8 lines
Documentation/config.txt receive.fsckObjects:: · line 2155
Quoted 6 lines
Documentation/config.txt +6
-0+ a comma-separated list of fsck message IDs that should be + ignored completely. ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories certain known issues but still catchs/certain/with &/
Good catch. Fixed here (to be included in the next re-roll):
Thanks!
Dscho
PATCH v2 16/18 fsck: Support demoting errors to warnings
In reply to Johannes SchindelinWe already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.
Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.
Example: git -c fsck.ignore=missing-email fsck would hide problems with missing emails in author, committer and tagger lines.
In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.* from the receive.fsck.* settings.
--- Documentation/config.txt | 13 +++++++++++++ builtin/fsck.c | 15 +++++++++++++++ t/t1450-fsck.sh | 11 +++++++++++ 3 files changed, 39 insertions(+)
Documentation/config.txt +13 -0
@@ -1208,6 +1208,19 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. +fsck.*:: + The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify + comma-separated lists of fsck message IDs which should trigger + fsck to error out, to print the message and continue, or to ignore + said messages, respectively. ++ +For convenience, fsck prefixes the error/warning with the name of the option, +e.g. "missing-email: invalid author/committer line - missing email" means +that setting `fsck.ignore = missing-email` will hide that issue. ++ +This feature is intended to support working with legacy repositories +which cannot be repaired without disruptive changes. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +15 -0
@@ -46,6 +46,19 @@ static int show_dangling = 1;#define DIRENT_SORT_HINT (de) ((de)->d_ino)#endif +static int fsck_config (const char *var,const char *value,void *cb) +{ +if (starts_with (var,"fsck." )) { +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"%s=%s" , var +5 , value); +fsck_set_severity (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } + +return git_default_config (var, value, cb); +} +static void objreport (struct object *obj,const char *severity,const char *err) {
@@ -638,6 +651,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) include_reflogs =0 ; } +git_config (fsck_config,NULL ); +fsck_head_link ();fsck_object_dir (get_object_directory ());
t/t1450-fsck.sh +11 -0
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' ' grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out ' +test_expect_success 'force fsck to ignore double author' ' + git cat-file commit HEAD >basis && + sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && + new=$(git hash-object -t commit -w --stdin <multiple-authors) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + test_must_fail git fsck && + git -c fsck.ignore=multiple-authors fsck +' + _bz='\0' _bz5="$_bz$_bz$_bz$_bz$_bz" _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 17/18 fsck: Introduce `git fsck --quick`
In reply to Johannes SchindelinThis option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.
--- Documentation/git-fsck.txt | 7 ++++++- builtin/fsck.c | 7 ++++++- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found] [--[no-]dangling] [--[no-]progress] [<object>*] DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs object pools. This is now default; you can turn it off with --no-full. +--quick:: + Check only the connectivity of tags, commits and tree objects. By + avoiding to unpack blobs, this speeds up the operation, at the + expense of missing corrupt objects. + --strict:: Enable more strict checking, namely to catch a file mode recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
@@ -23,6 +23,7 @@ static int show_tags;static int show_unreachable;static int include_reflogs =1 ;static int check_full =1 ; +static int quick;static int check_strict;static int keep_cache_objects;static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ;
@@ -184,6 +185,8 @@ static void check_reachable_object(struct object *obj)if (!(obj->flags &HAS_OBJ )) {if (has_sha1_pack (obj->sha1))return ;/* it is in pack - forget about it */ +if (quick &&has_sha1_file (obj->sha1)) +return ;printf ("missing %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); errors_found |=ERROR_REACHABLE ;return ;
@@ -618,6 +621,7 @@ static struct option fsck_opts[] = {OPT_BOOL (0 ,"cache" , &keep_cache_objects,N_ ("make index objects head nodes" )),OPT_BOOL (0 ,"reflogs" , &include_reflogs,N_ ("make reflogs head nodes (default)" )),OPT_BOOL (0 ,"full" , &check_full,N_ ("also consider packs and alternate objects" )), +OPT_BOOL (0 ,"quick" , &quick,N_ ("check only connectivity" )),OPT_BOOL (0 ,"strict" , &check_strict,N_ ("enable more strict checking" )),OPT_BOOL (0 ,"lost-found" , &write_lost_and_found, N_("write dangling objects in .git/lost-found")),
@@ -654,7 +658,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)git_config (fsck_config,NULL );fsck_head_link (); -fsck_object_dir (get_object_directory ()); +if (!quick) +fsck_object_dir (get_object_directory ());prepare_alt_odb ();for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' ' test_must_fail git -C missing fsck ' +test_expect_success 'fsck --quick' ' + rm -rf quick && + git init quick && + ( + cd quick && + touch empty && + git add empty && + test_commit empty && + empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 && + rm -f $empty && + echo invalid >$empty && + test_must_fail git fsck --strict && + git fsck --strict --quick && + tree=$(git rev-parse HEAD:) && + suffix=${tree#??} && + tree=.git/objects/${tree%$suffix}/$suffix && + rm -f $tree && + echo invalid >$tree && + test_must_fail git fsck --strict --quick + ) +' + test_done
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
PATCH v2 18/18 fsck: git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinThe optional new config option receive.fsck.skiplist specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.
--- builtin/receive-pack.c | 9 +++++++ fsck.c | 53 +++++++++++++++++++++++++++++++++++++++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 12 ++++++++++ 4 files changed, 75 insertions(+)
builtin/receive-pack.c +9 -0
@@ -116,6 +116,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (starts_with (var,"receive.fsck.skiplist" )) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"skiplist=%s" , path); +return 0 ; + } +if (starts_with (var,"receive.fsck." )) {if (fsck_severity.len)strbuf_addch (&fsck_severity,',' );
fsck.c +53 -0
77 lines not on this page · raw message
fsck.h +1 -0
@@ -29,6 +29,7 @@ struct fsck_options {fsck_error error_func; unsigned strict:1;int *msg_severity; +struct sha1_array *skiplist; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000 This commit object intentionally broken EOF +test_expect_success 'push with receive.fsck.skiplist' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.skiplist SKIP && + echo $commit > dst/.git/SKIP && + git push --porcelain dst bogus +' + test_expect_success 'push with receive.fsck.warn = missing-email' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.0.0.rc3.9669.g840d1f9
Re: [PATCH v2 04/18] fsck: Offer a function to demote fsck errors to warnings
In reply to Johannes Schindelinfsck.c static int fsck_msg_severity(enum fsck_msg_id msg_id, · line 120
Quoted 7 lines · Johannes Schindelin
fsck.c +7
-0+static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +}
Is this what we call "starts_with()" these days?
fsck.c static int fsck_msg_severity(enum fsck_msg_id msg_id, · line 128
Quoted 7 lines
fsck.c +7
-0+void fsck_set_severity (struct fsck_options *options,const char *mode) +{ +int severity =FSCK_ERROR ; + +if (!options->msg_severity) { +int i; +int *msg_severity =malloc (sizeof (int ) *FSCK_MSG_MAX );
xmalloc()?
Re: [PATCH v2 04/18] fsck: Offer a function to demote fsck errors to warnings
Hi Junio,
Quoted 11 lines · Junio C Hamano
fsck.c static int fsck_msg_severity(enum fsck_msg_id msg_id, · line 120
Quoted 7 lines · Johannes Schindelin
fsck.c +7
-0+static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +}Is this what we call "
starts_with()" these days?
Unfortunately not quite: It really requires the substring specified by string and len to be identical to the full match. For example, substrcmp("Hello world!", 5, "Hell") would report a failure (because the substring "Hello" is *not* matching "Hell"), while starts_with("Hello world!", "Hell") would obviously succeed.
Quoted 9 lines
fsck.c static int fsck_msg_severity(enum fsck_msg_id msg_id, · line 128
Quoted 7 lines
fsck.c +7
-0+void fsck_set_severity (struct fsck_options *options,const char *mode) +{ +int severity =FSCK_ERROR ; + +if (!options->msg_severity) { +int i; +int *msg_severity =malloc (sizeof (int ) *FSCK_MSG_MAX );
xmalloc()?
Absolutely! Fixed.
Thanks,
Dscho
Re: [PATCH v2 05/18] fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
In reply to Johannes Schindelinbuiltin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 122
Quoted 5 lines · Johannes Schindelin
builtin/receive-pack.c +4
-0+if (starts_with (var,"receive.fsck." )) { +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"%s=%s" , var +13 , value);
Wouldn't it be safer to use skip_prefix() that lets you avoid the hardcoded "var + 13" here?
Quoted 19 lines
builtin/receive-pack.c +7
-2@@ -1470,8 +1478,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"unpack-objects" , hdr_arg,NULL );if (quiet)argv_array_push (&child.args,"-q" ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + } child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;@@ -1488,8 +1501,13 @@ static const char *unpack(int err_fd, struct shallow_info *si) argv_array_pushl(&child.args, "index-pack",
builtin/receive-pack.c static const char *unpack(int err_fd, struct shallow_info *si) · line 1510
Quoted 10 lines
builtin/receive-pack.c +7
-2"--stdin", hdr_arg, keep_arg, NULL); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + }
Hmm. The above two hunks look suspiciously similar. Would it be worth to give them a single helper function?
Quoted 16 lines
builtin/unpack-objects.c +5
-0@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } +if (starts_with (arg,"--strict=" )) { + strict =1 ; +fsck_set_severity (&fsck_options, arg +9 ); +continue ; + }if (starts_with (arg,"--pack_header=" )) {struct pack_header *hdr;char *c;
Re: [PATCH v2 05/18] fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
Hi Junio,
Quoted 10 lines · Junio C Hamano
builtin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 122
Quoted 5 lines · Johannes Schindelin
builtin/receive-pack.c +4
-0+if (starts_with (var,"receive.fsck." )) { +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"%s=%s" , var +13 , value);Wouldn't it be safer to use
skip_prefix()that lets you avoid the hardcoded "var + 13" here?
Yep, and much more elegant, too. I also fixed three more instances of the same pattern.
Quoted 18 lines
Quoted 18 lines
builtin/receive-pack.c +7
-2@@ -1470,8 +1478,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"unpack-objects" , hdr_arg,NULL );if (quiet)argv_array_push (&child.args,"-q" ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + } child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;@@ -1488,8 +1501,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)
Quoted 14 lines
builtin/receive-pack.c static const char *unpack(int err_fd, struct shallow_info *si) · line 1510
Quoted 11 lines
builtin/receive-pack.c +7
-2argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + }Hmm. The above two hunks look suspiciously similar. Would it be worth to give them a single helper function?
Hmm. Not sure. I see what you mean, but for now I found
+ argv_array_pushf(&child.args, "--strict%s%s",
+ fsck_severity.len ? "=" : "",
+ fsck_severity.buf);
to be more elegant than to add a fully-fledged new function. But if you feel strongly, I will gladly implement a separate function; I would appreciate suggestions as to the function name...
Ciao,
Dscho
Re: [PATCH v2 05/18] fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
Quoted 23 lines · Johannes Schindelin
Quoted 16 lines
builtin/receive-pack.c static const char *unpack(int err_fd, struct shallow_info *si) · line 1510
Quoted 13 lines
builtin/receive-pack.c +7
-2@@ -1488,8 +1501,13 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL ); -if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +if (fsck_objects) { +if (fsck_severity.len) +argv_array_pushf (&child.args,"--strict=%s" , + fsck_severity.buf); +else +argv_array_push (&child.args,"--strict" ); + }Hmm. The above two hunks look suspiciously similar. Would it be worth to give them a single helper function?
Hmm. Not sure. I see what you mean, but for now I found
(quoted diff) +3
-0+ argv_array_pushf(&child.args, "--strict%s%s", + fsck_severity.len ? "=" : "", + fsck_severity.buf);
Quoted 3 lines
to be more elegant than to add a fully-fledged new function. But if you feel strongly, I will gladly implement a separate function; I would appreciate suggestions as to the function name...
Peff first introduced that trick elsewhere in our codebase, I think, but I find it a bit too ugly.
As you accumulate fsck_severity strbuf like this anyway:
strbuf_addf(&fsck_severity, "%s%s=%s",
fsck_severity.len ? "," : "", var, value);to flip what to prefix each element on the list with, I wonder if it is simpler to change that empty string to "=", which will allow you to say this:
argv_array_pushf(&child.args, "--strict%s", fsck_severity.buf);
Or even this:
strbuf_addf(&fsck_strict_arg, "%s%s=%s",
fsck_strict_arg.len ? "," : "--strict=", var, value);and then the child.args stuff can become
if (fsck_strict_arg.len) argv_array_push(&child.args, fsck_strict_arg.buf);
In any case, I tend to agree with you that it is overkill to add a helper function for just to add a single element to the argument list.
Thanks.
Re: [PATCH v2 05/18] fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
Hi Junio,
Quoted 34 lines · Junio C Hamano
Quoted 23 lines · Johannes Schindelin
Quoted 16 lines
Review static const char *unpack(int err_fd, struct shallow_info *si) · line 1510
Quoted 13 lines
(quoted diff) +7
-2@@ -1488,8 +1501,13 @@ static const char *unpack(int err_fd, struct shallow_info *si) argv_array_pushl(&child.args, "index-pack", "--stdin", hdr_arg, keep_arg, NULL); - if (fsck_objects) - argv_array_push(&child.args, "--strict"); + if (fsck_objects) { + if (fsck_severity.len) + argv_array_pushf(&child.args, "--strict=%s", + fsck_severity.buf); + else + argv_array_push(&child.args, "--strict"); + }Hmm. The above two hunks look suspiciously similar. Would it be worth to give them a single helper function?
Hmm. Not sure. I see what you mean, but for now I found
(quoted diff) +3
-0+ argv_array_pushf(&child.args, "--strict%s%s", + fsck_severity.len ? "=" : "", + fsck_severity.buf);Quoted 3 lines
to be more elegant than to add a fully-fledged new function. But if you feel strongly, I will gladly implement a separate function; I would appreciate suggestions as to the function name...
Peff first introduced that trick elsewhere in our codebase, I think, but I find it a bit too ugly.
As you accumulate
fsck_severitystrbuf like this anyway:
Quoted 8 lines
strbuf_addf(&fsck_severity, "%s%s=%s", fsck_severity.len ? "," : "", var, value);to flip what to prefix each element on the list with, I wonder if it is simpler to change that empty string to "=", which will allow you to say this:
argv_array_pushf(&child.args, "--strict%s", fsck_severity.buf);
But of course! This is what I did now:
-- snip --
builtin/receive-pack.c +4 -6
@@ -126,8 +126,8 @@ static int receive_pack_config(const char *var, const char *value, void *cb) }if (skip_prefix (var,"receive.fsck." , &var)) { -strbuf_addf (&fsck_severity,"%s%s=%s" , - fsck_severity.len ?"," :"" , var, value); +strbuf_addf (&fsck_severity,"%c%s=%s" , + fsck_severity.len ?',' :'=' , var, value);return 0 ; }
@@ -1487,8 +1487,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)if (quiet)argv_array_push (&child.args,"-q" );if (fsck_objects) -argv_array_pushf (&child.args,"--strict%s%s" , - fsck_severity.len ?"=" :"" , +argv_array_pushf (&child.args,"--strict%s" , fsck_severity.buf); child.no_stdout =1 ; child.err = err_fd;
@@ -1507,8 +1506,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL );if (fsck_objects) -argv_array_pushf (&child.args,"--strict%s%s" , - fsck_severity.len ?"=" :"" , +argv_array_pushf (&child.args,"--strict%s" , fsck_severity.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" );
-- snap --
Quoted 4 lines
Or even this:
strbuf_addf(&fsck_strict_arg, "%s%s=%s", fsck_strict_arg.len ? "," : "--strict=", var, value);
Unfortunately not, because just --strict needs to be passed in case no severity levels were overridden.
Quoted 3 lines
In any case, I tend to agree with you that it is overkill to add a helper function for just to add a single element to the argument list.
I am glad we agree!
Ciao,
Dscho
Re: [PATCH v2 07/18] fsck: Make fsck_ident() warn-friendly
In reply to Johannes SchindelinQuoted 3 lines · Johannes Schindelin
When
fsck_ident()identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.
Quite sensible.
Quoted 24 lines
Signed-off-by Johannes Schindelin <[email protected]>--- fsck.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-)fsck.c +6
-1@@ -453,40 +453,45 @@ static int require_end_of_header(const void *data, unsigned long size,static int fsck_ident (const char **ident,struct object *obj,struct fsck_options *options) { +const char *p = *ident;char *end; -if (**ident =='<' ) + *ident =strchrnul (*ident,'\n' ); +if (**ident =='\n' ) + (*ident)++; + +if (*p =='<' )return report (options, obj,FSCK_MSG_MISSING_NAME_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" );
Re: [PATCH v2 11/18] fsck: Add a simple test for receive.fsck.*
In reply to Johannes SchindelinQuoted 10 lines · Johannes Schindelin
Signed-off-by Johannes Schindelin <[email protected]>--- t/t5504-fetch-receive-strict.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)t/t5504-fetch-receive-strict.sh +0
-0
t/t5504-fetch-receive-strict.sh test_expect_success 'push with transfer.fsckobjects' ' · line 118
Quoted 4 lines
t/t5504-fetch-receive-strict.sh +1
-0@@ -115,4 +115,24 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' +cat >bogus-commit << EOF
"cat >bogus-commit <<\EOF", to reduce the mental burden of readers.
Quoted 20 lines
t/t5504-fetch-receive-strict.sh +19
-0+tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +author Bugs Bunny 1234567890 +0000 +committer Bugs Bunny <[email protected]> 1234567890 +0000 + +This commit object intentionally broken +EOF + +test_expect_success 'push with receive.fsck.warn = missing-email' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.warn missing-email && + git push --porcelain dst bogus >act 2>&1 && + grep "missing-email" act +' + test_done
Re: [PATCH v2 11/18] fsck: Add a simple test for receive.fsck.*
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Johannes Schindelin
Signed-off-by Johannes Schindelin <[email protected]>--- t/t5504-fetch-receive-strict.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)t/t5504-fetch-receive-strict.sh +0
-0@@ -115,4 +115,24 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act '
Quoted 3 lines
t/t5504-fetch-receive-strict.sh test_expect_success 'push with transfer.fsckobjects' ' · line 118
Quoted 1 line
t/t5504-fetch-receive-strict.sh +1
-0+cat >bogus-commit << EOF"cat >bogus-commit <<\EOF", to reduce the mental burden of readers.
Certainly!
Dscho
Re: [PATCH v2 18/18] fsck: git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinQuoted 3 lines · Johannes Schindelin
The optional new config option
receive.fsck.skiplistspecifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored bygit receive-packwhenreceive.fsckObjects = true.
Makes sense, but I wonder if it makes sense to have a similar "ok to be broken" list for "git fsck" (or perhaps they could even use the same list) for exactly the same reason why this option makes sense.
Re: [PATCH v2 18/18] fsck: git receive-pack: support excluding objects from fsck'ing
Hi Junio,
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
The optional new config option
receive.fsck.skiplistspecifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored bygit receive-packwhenreceive.fsckObjects = true.Makes sense, but I wonder if it makes sense to have a similar "ok to be broken" list for "git fsck" (or perhaps they could even use the same list) for exactly the same reason why this option makes sense.
Sure! The most pressing use case for the skiplist feature is a Git server, hence this patch. I will implement the corresponding git fsck patch before re-submitting.
Ciao,
Dscho
The documentation did not format well. Tentatively I added the attached fix-up on top of the series before merging to 'pu'.
* The wildcard in "fsck.*" and "receive.fsck.*" may have made sense back in v1 when the variables are unbounded set, but v2 fixes it and we now have a known fixed set of variables, so lets list them explicitly (this is not a "fix to unbreak formatting").
* The "--" that is not closed was giving me this:
asciidoc: ERROR: git-config.txt: line 413: section title not permitted in delimited block
asciidoc: ERROR: config.txt: line 2414: [blockdef-open] missing closing delimiter
make: *** [git-config.xml] Error 1
(this is "workaround to unbreak formatting"; I didn't check the actual output closely).
* the line that begins with "- missing email" after indent was taken as an bulletted item or something, so I rewrapped the paragraph somewhat to avoid having the dash at the beginning.
Documentation/config.txt | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
Documentation/config.txt +19 -16
@@ -1208,7 +1208,9 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. -fsck.*:: +fsck.error:: +fsck.warn:: +fsck.ignore:: The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify comma-separated lists of fsck message IDs which should trigger fsck to error out, to print the message and continue, or to ignore
@@ -2138,25 +2140,26 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. -receive.fsck.*:: +receive.fsck.error:: +receive.fsck.warn:: +receive.fsck.ignore:: When `receive.fsckObjects` is set to true, errors can be switched to warnings and vice versa by configuring the `receive.fsck.*` settings. These settings contain comma-separated lists of fsck message IDs. For convenience, fsck prefixes the error/warning with - the message ID, e.g. "missing-email: invalid author/committer line - - missing email" means that setting `receive.fsck.ignore = - missing-email` will hide that issue. -+ --- - error:: - a comma-separated list of fsck message IDs that should be - trigger fsck to error out. - warn:: - a comma-separated list of fsck message IDs that should be - displayed, but fsck should continue to error out. - ignore:: - a comma-separated list of fsck message IDs that should be - ignored completely. + the message ID, e.g. "missing-email: invalid + author/committer line - missing email" means that setting + `receive.fsck.ignore = missing-email` will hide that issue. ++ +error;; + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. +warn;; + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. +ignore;; + a comma-separated list of fsck message IDs that should be + ignored completely. + This feature is intended to support working with legacy repositories which would not pass pushing when `receive.fsckObjects = true`, allowing
Hi Junio,
Quoted 4 lines · Junio C Hamano
The documentation did not format well. Tentatively I added the attached fix-up on top of the series before merging to 'pu'.
[...]
Sorry for that! I have to admit that I did not even build the documentation :-( I incorporated your fixes into the respective patches.
Ciao,
Dscho
v3 cover Introduce an internal API to interact with the fsck machinery
In reply to Junio C HamanoAt the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.
This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.
I am proud to report that this work has been sponsored by GitHub.
Interdiff vs v2 below the diffstat.
Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings
fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.*
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.* options.
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --quick
fsck: git receive-pack: support excluding objects from fsck'ing
fsck: support ignoring objects in git fsck via fsck.skiplist
Documentation/config.txt | 57 +++++ Documentation/git-fsck.txt | 7 +- builtin/fsck.c | 76 ++++-- builtin/index-pack.c | 13 +- builtin/receive-pack.c | 24 +- builtin/unpack-objects.c | 16 +- fsck.c | 525 +++++++++++++++++++++++++++++++--------- fsck.h | 27 ++- t/t1450-fsck.sh | 37 ++- t/t5302-pack-index.sh | 2 +- t/t5504-fetch-receive-strict.sh | 46 ++++ 11 files changed, 668 insertions(+), 162 deletions(-)
Documentation/config.txt +34 -15
@@ -1208,7 +1208,9 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. -fsck.*:: +fsck.error:: +fsck.warn:: +fsck.ignore:: The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify comma-separated lists of fsck message IDs which should trigger fsck to error out, to print the message and continue, or to ignore
@@ -1221,6 +1223,13 @@ that setting `fsck.ignore = missing-email` will hide that issue. This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes. +fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
@@ -2143,31 +2152,41 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. -receive.fsck.*:: +receive.fsck.error:: +receive.fsck.warn:: +receive.fsck.ignore:: When `receive.fsckObjects` is set to true, errors can be switched to warnings and vice versa by configuring the `receive.fsck.*` settings. These settings contain comma-separated lists of fsck message IDs. For convenience, fsck prefixes the error/warning with - the message ID, e.g. "missing-email: invalid author/committer line - - missing email" means that setting `receive.fsck.ignore = - missing-email` will hide that issue. + the message ID, e.g. "missing-email: invalid + author/committer line - missing email" means that setting + `receive.fsck.ignore = missing-email` will hide that issue. + -- - error:: - a comma-separated list of fsck message IDs that should be - trigger fsck to error out. - warn:: - a comma-separated list of fsck message IDs that should be - displayed, but fsck should continue to error out. - ignore:: - a comma-separated list of fsck message IDs that should be - ignored completely. +error;; + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. +warn;; + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. +ignore;; + a comma-separated list of fsck message IDs that should be + ignored completely. +-- + This feature is intended to support working with legacy repositories which would not pass pushing when `receive.fsckObjects = true`, allowing -the host to accept repositories certain known issues but still catch +the host to accept repositories with certain known issues but still catch other issues. +receive.fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
builtin/fsck.c +12 -2
@@ -49,9 +49,19 @@ static int show_dangling = 1;static int fsck_config (const char *var,const char *value,void *cb) { -if (starts_with (var,"fsck." )) { +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value);struct strbuf sb =STRBUF_INIT ; -strbuf_addf (&sb,"%s=%s" , var +5 , value); +strbuf_addf (&sb,"skiplist=%s" , path); +fsck_set_severity (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } + +if (skip_prefix (var,"fsck." , &var)) { +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"%s=%s" , var, value);fsck_set_severity (&fsck_obj_options, sb.buf);strbuf_release (&sb);return 0 ;
builtin/index-pack.c +2 -2
@@ -1565,10 +1565,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (!strcmp (arg,"--strict" )) { strict =1 ; do_fsck_object =1 ; - }else if (starts_with (arg,"--strict=" )) { + }else if (skip_prefix (arg,"--strict=" , &arg)) { strict =1 ; do_fsck_object =1 ; -fsck_set_severity (&fsck_options, arg +9 ); +fsck_set_severity (&fsck_options, arg); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +12 -19
@@ -116,7 +116,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } -if (starts_with (var,"receive.fsck.skiplist" )) { +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) {const char *path =is_absolute_path (value) ? value :git_path ("%s" , value);if (fsck_severity.len)
@@ -125,10 +125,9 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } -if (starts_with (var,"receive.fsck." )) { -if (fsck_severity.len) -strbuf_addch (&fsck_severity,',' ); -strbuf_addf (&fsck_severity,"%s=%s" , var +13 , value); +if (skip_prefix (var,"receive.fsck." , &var)) { +strbuf_addf (&fsck_severity,"%s%s=%s" , + fsck_severity.len ?"," :"" , var, value);return 0 ; }
@@ -1487,13 +1486,10 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"unpack-objects" , hdr_arg,NULL );if (quiet)argv_array_push (&child.args,"-q" ); -if (fsck_objects) { -if (fsck_severity.len) -argv_array_pushf (&child.args,"--strict=%s" , - fsck_severity.buf); -else -argv_array_push (&child.args,"--strict" ); - } +if (fsck_objects) +argv_array_pushf (&child.args,"--strict%s%s" , + fsck_severity.len ?"=" :"" , + fsck_severity.buf); child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1510,13 +1506,10 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL ); -if (fsck_objects) { -if (fsck_severity.len) -argv_array_pushf (&child.args,"--strict=%s" , - fsck_severity.buf); -else -argv_array_push (&child.args,"--strict" ); - } +if (fsck_objects) +argv_array_pushf (&child.args,"--strict%s%s" , + fsck_severity.len ?"=" :"" , + fsck_severity.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +2 -2
@@ -530,9 +530,9 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } -if (starts_with (arg,"--strict=" )) { +if (skip_prefix (arg,"--strict=" , &arg)) { strict =1 ; -fsck_set_severity (&fsck_options, arg +9 ); +fsck_set_severity (&fsck_options, arg);continue ; }if (starts_with (arg,"--pack_header=" )) {
fsck.c +1 -1
@@ -169,7 +169,7 @@ void fsck_set_severity(struct fsck_options *options, const char *mode)if (!options->msg_severity) {int i; -int *msg_severity =malloc (sizeof (int ) *FSCK_MSG_MAX ); +int *msg_severity =xmalloc (sizeof (int ) *FSCK_MSG_MAX );for (i =0 ; i <FSCK_MSG_MAX ; i++) msg_severity[i] =fsck_msg_severity (i, options); options->msg_severity = msg_severity;
t/t5504-fetch-receive-strict.sh +1 -1
@@ -115,7 +115,7 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' -cat >bogus-commit << EOF +cat >bogus-commit <<\EOF tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 author Bugs Bunny 1234567890 +0000 committer Bugs Bunny <[email protected]> 1234567890 +0000
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 1/19 fsck: Introduce fsck options
Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.
--- builtin/fsck.c | 20 +++++-- builtin/index-pack.c | 9 +-- builtin/unpack-objects.c | 11 ++-- fsck.c | 150 +++++++++++++++++++++++------------------------ fsck.h | 17 +++++- 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
@@ -25,6 +25,8 @@ static int include_reflogs = 1;static int check_full =1 ;static int check_strict;static int keep_cache_objects; +static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;static unsigned char head_sha1[20 ];static const char *head_points_at;static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)static struct object_array pending; -static int mark_object (struct object *obj,int type,void *data) +static int mark_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct object *parent = data;
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)static void mark_object_reachable (struct object *obj) { -mark_object (obj,OBJ_ANY ,NULL ); +mark_object (obj,OBJ_ANY ,NULL ,NULL ); }static int traverse_one_object (struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)if (parse_tree (tree) <0 )return 1 ;/* error already displayed */ } - result =fsck_walk (obj, mark_object, obj); + result =fsck_walk (obj, obj, &fsck_walk_options);if (tree)free_tree_buffer (tree);return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data) +static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return 1 ;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)fprintf (stderr,"Checking %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); -if (fsck_walk (obj, mark_used,NULL )) +if (fsck_walk (obj,NULL , &fsck_obj_options))objerror (obj,"broken links" ); -if (fsck_object (obj,NULL ,0 , check_strict, fsck_error_func)) +if (fsck_object (obj,NULL ,0 , &fsck_obj_options))return -1 ;if (obj->type ==OBJ_TREE ) {
@@ -630,6 +632,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, fsck_opts, fsck_usage,0 ); + fsck_walk_options.walk = mark_object; + fsck_obj_options.walk = mark_used; + fsck_obj_options.error_func = fsck_error_func; +if (check_strict) + fsck_obj_options.strict =1 ; +if (show_progress ==-1 ) show_progress =isatty (2 );if (verbose)
builtin/index-pack.c +5 -4
@@ -74,6 +74,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static int verbose;static int show_stat;static int check_self_contained_and_connected;
@@ -191,7 +192,7 @@ static void cleanup_thread(void)#endif -static int mark_link (struct object *obj,int type,void *data) +static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return -1 ;
@@ -782,10 +783,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,if (!obj)die (_ ("invalid %s" ),typename (type));if (do_fsck_object && -fsck_object (obj, buf, size,1 , - fsck_error_function)) +fsck_object (obj, buf, size, &fsck_options))die (_ ("Error in object" )); -if (fsck_walk (obj, mark_link,NULL )) + fsck_options.walk = mark_link; +if (fsck_walk (obj,NULL , &fsck_options))die (_ ("Not all child objects of %s are reachable" ),sha1_to_hex (obj->sha1));if (obj->type ==OBJ_TREE ) {
builtin/unpack-objects.c +6 -5
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];static unsigned int offset, len;static off_t consumed_bytes;static git_SHA_CTX ctx; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;/* * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data) +static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data) obj_buf =lookup_object_buffer (obj);if (!obj_buf)die ("Whoops! Cannot find object '%s'" ,sha1_to_hex (obj->sha1)); -if (fsck_object (obj, obj_buf->buffer, obj_buf->size,1 , - fsck_error_function)) +if (fsck_object (obj, obj_buf->buffer, obj_buf->size, &fsck_options))die ("Error in object" ); -if (fsck_walk (obj, check_object,NULL )) + fsck_options.walk = check_object; +if (fsck_walk (obj,NULL , &fsck_options))die ("Error on reachable objects of %s" ,sha1_to_hex (obj->sha1));write_cached_object (obj, obj_buf);return 0 ;
@@ -217,7 +218,7 @@ static void write_rest(void)unsigned i;for (i =0 ; i < nr_objects; i++) {if (obj_list[i].obj) -check_object (obj_list[i].obj,OBJ_ANY ,NULL ); +check_object (obj_list[i].obj,OBJ_ANY ,NULL ,NULL ); } }
fsck.c +75 -75
392 lines not on this page · raw message
fsck.h +14 -3
@@ -4,6 +4,8 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +struct fsck_options ; +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data); +typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); __attribute__((format (printf,3 ,4 )))int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +unsigned strict:1 ; +}; + +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +/* descend in all linked child objects * the return value is: * -1 error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);* >0 return value of the first signaled error >0 (in the case of no other errors) * 0 everything OK */ -int fsck_walk (struct object *obj,fsck_walk_func walk,void *data); +int fsck_walk (struct object *obj,void *data,struct fsck_options *options);/* If NULL is passed for data, we assume the object is local and read it. */ int fsck_object (struct object *obj,void *data,unsigned long size, -int strict,fsck_error error_func); +struct fsck_options *options);#endif
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 2/19 fsck: Introduce identifiers for fsck messages
In reply to Johannes SchindelinInstead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.
In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.
We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate severity levels. Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.
--- builtin/fsck.c | 24 ++----- fsck.c | 201 +++++++++++++++++++++++++++++++++++++++++---------------- fsck.h | 5 +- 3 files changed, 153 insertions(+), 77 deletions(-)
builtin/fsck.c +7 -17
@@ -47,32 +47,22 @@ static int show_dangling = 1;#endif static void objreport (struct object *obj,const char *severity, -const char *err,va_list params) +const char *err) { -fprintf (stderr,"%s in %s %s: " , - severity,typename (obj->type),sha1_to_hex (obj->sha1)); -vfprintf (stderr, err, params); -fputs ("\n" , stderr); +fprintf (stderr,"%s in %s %s: %s\n" , + severity,typename (obj->type),sha1_to_hex (obj->sha1), err); } -__attribute__((format (printf,2 ,3 ))) -static int objerror (struct object *obj,const char *err, ...) +static int objerror (struct object *obj,const char *err) { -va_list params; -va_start (params, err); errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err, params); -va_end (params); +objreport (obj,"error" , err);return -1 ; } -__attribute__((format (printf,3 ,4 ))) -static int fsck_error_func (struct object *obj,int type,const char *err, ...) +static int fsck_error_func (struct object *obj,int type,const char *message) { -va_list params; -va_start (params, err); -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , err, params); -va_end (params); +objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message);return (type ==FSCK_WARN ) ?0 :1 ; }
fsck.c +144 -57
356 lines not on this page · raw message
fsck.h +2 -3
@@ -17,10 +17,9 @@ struct fsck_options;typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ -typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...); +typedef int (*fsck_error )(struct object *obj,int type,const char *message); -__attribute__((format (printf,3 ,4 ))) -int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +int fsck_error_function (struct object *obj,int type,const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 3/19 fsck: Provide a function to parse fsck message IDs
In reply to Johannes SchindelinThis function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, 'missing-email,missing-tagger-entry' command lines.
To make the parsing robust, we generate strings from the enum keys, and using these keys, we will map lower-case, dash-separated strings values to the corresponding enum values.
--- fsck.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
fsck.c +25 -2
@@ -63,15 +63,38 @@ enum fsck_msg_id { };#undef MSG_ID -#define MSG_ID (id, severity) { FSCK_##severity }, +#define STR (x) #x +#define MSG_ID (id, severity) { STR(id), FSCK_##severity },static struct { +const char *id_string;int severity; } msg_id_info[FSCK_MSG_MAX +1 ] = { FOREACH_MSG_ID(MSG_ID) - {-1 } + {NULL ,-1 } };#undef MSG_ID +static int parse_msg_id (const char *text,int len) +{ +int i, j; + +for (i =0 ; i <FSCK_MSG_MAX ; i++) { +const char *key = msg_id_info[i].id_string; +/* id_string is upper-case, with underscores */ +for (j =0 ; j < len; j++) { +char c = *(key++); +if (c =='_' ) + c ='-' ; +if (text[j] !=tolower (c)) +break ; + } +if (j == len && !*key) +return i; + } + +die ("Unhandled message id: %.*s" , len, text); +} +static int fsck_msg_severity (enum fsck_msg_id msg_id,struct fsck_options *options) {
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 4/19 fsck: Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinThere are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.
The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all FSCK_ERROR in those cases.
--- fsck.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- fsck.h | 7 +++++-- 2 files changed, 66 insertions(+), 5 deletions(-)
fsck.c +61 -3
@@ -100,13 +100,67 @@ static int fsck_msg_severity(enum fsck_msg_id msg_id, {int severity; - severity = msg_id_info[msg_id].severity; -if (options->strict && severity ==FSCK_WARN ) - severity =FSCK_ERROR ; +if (options->msg_severity && msg_id >=0 && msg_id <FSCK_MSG_MAX ) + severity = options->msg_severity[msg_id]; +else { + severity = msg_id_info[msg_id].severity; +if (options->strict && severity ==FSCK_WARN ) + severity =FSCK_ERROR ; + }return severity; } +static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +} + +void fsck_set_severity (struct fsck_options *options,const char *mode) +{ +int severity =FSCK_ERROR ; + +if (!options->msg_severity) { +int i; +int *msg_severity =xmalloc (sizeof (int ) *FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + msg_severity[i] =fsck_msg_severity (i, options); + options->msg_severity = msg_severity; + } + +while (*mode) { +int len =strcspn (mode," ,|" ), equal, msg_id; + +if (!len) { + mode++; +continue ; + } + +for (equal =0 ; equal < len; equal++) +if (mode[equal] =='=' ) +break ; + +if (equal < len) { +if (!substrcmp (mode, equal,"error" )) + severity =FSCK_ERROR ; +else if (!substrcmp (mode, equal,"warn" )) + severity =FSCK_WARN ; +else +die ("Unknown fsck message severity: '%.*s'" , + equal, mode); + mode += equal +1 ; + len -= equal +1 ; + } + + msg_id =parse_msg_id (mode, len); + options->msg_severity[msg_id] = severity; + mode += len; + } +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -596,6 +650,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct object *obj,int severity,const char *message) { +if (severity ==FSCK_WARN ) { +warning ("object %s: %s" ,sha1_to_hex (obj->sha1), message); +return 0 ; + }error ("object %s: %s" ,sha1_to_hex (obj->sha1), message);return 1 ; }
fsck.h +5 -2
@@ -6,6 +6,8 @@struct fsck_options ; +void fsck_set_severity (struct fsck_options *options,const char *mode); +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -25,10 +27,11 @@ struct fsck_options {fsck_walk_func walk;fsck_error error_func; unsigned strict:1; +int *msg_severity; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 5/19 fsck: Allow demoting errors to warnings via receive.fsck.warn = <key>
In reply to Johannes SchindelinFor example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.warn = missing-email
The value is actually a comma-separated list, and there is a corresponding receive.fsck.error setting.
In case that the same key is listed in multiple receive.fsck.* lines in the config, the latter configuration wins.
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.
--- builtin/index-pack.c | 4 ++++ builtin/receive-pack.c | 15 +++++++++++++-- builtin/unpack-objects.c | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-)
builtin/index-pack.c +4 -0
@@ -1565,6 +1565,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (!strcmp (arg,"--strict" )) { strict =1 ; do_fsck_object =1 ; + }else if (skip_prefix (arg,"--strict=" , &arg)) { + strict =1 ; + do_fsck_object =1 ; +fsck_set_severity (&fsck_options, arg); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +13 -2
@@ -36,6 +36,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; +static struct strbuf fsck_severity =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int advertise_atomic_push =1 ;
@@ -115,6 +116,12 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (skip_prefix (var,"receive.fsck." , &var)) { +strbuf_addf (&fsck_severity,"%s%s=%s" , + fsck_severity.len ?"," :"" , var, value); +return 0 ; + } +if (strcmp (var,"receive.fsckobjects" ) ==0 ) { receive_fsck_objects =git_config_bool (var, value);return 0 ;
@@ -1471,7 +1478,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)if (quiet)argv_array_push (&child.args,"-q" );if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +argv_array_pushf (&child.args,"--strict%s%s" , + fsck_severity.len ?"=" :"" , + fsck_severity.buf); child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1489,7 +1498,9 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL );if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +argv_array_pushf (&child.args,"--strict%s%s" , + fsck_severity.len ?"=" :"" , + fsck_severity.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +5 -0
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } +if (skip_prefix (arg,"--strict=" , &arg)) { + strict =1 ; +fsck_set_severity (&fsck_options, arg); +continue ; + }if (starts_with (arg,"--pack_header=" )) {struct pack_header *hdr;char *c;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 6/19 fsck: Report the ID of the error/warning
In reply to Johannes SchindelinSome legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missing-email", the user might want to call git config receive.fsck.warn missing-email).
--- fsck.c | 19 +++++++++++++++++++ t/t1450-fsck.sh | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-)
fsck.c +19 -0
@@ -161,6 +161,23 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) } } +static void append_msg_id (struct strbuf *sb,const char *msg_id) +{ +for (;;) { +char c = *(msg_id)++; + +if (!c) +break ; +if (c =='_' ) + c ='-' ; +else + c =tolower (c); +strbuf_addch (sb, c); + } + +strbuf_addstr (sb,": " ); +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -169,6 +186,8 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +append_msg_id (&sb, msg_id_info[id].id_string); +va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (object, msg_severity, sb.buf);
t/t1450-fsck.sh +2 -2
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' git fsck --tags 2>out && cat >expect <<-EOF && - warning in tag $tag: invalid '\''tag'\'' name: wrong name format - warning in tag $tag: invalid format - expected '\''tagger'\'' line + warning in tag $tag: invalid-tag-name: invalid '\''tag'\'' name: wrong name format + warning in tag $tag: missing-tagger-entry: invalid format - expected '\''tagger'\'' line EOF test_cmp expect out '
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 7/19 fsck: Make fsck_ident() warn-friendly
In reply to Johannes SchindelinWhen fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.
--- fsck.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
@@ -453,40 +453,45 @@ static int require_end_of_header(const void *data, unsigned long size,static int fsck_ident (const char **ident,struct object *obj,struct fsck_options *options) { +const char *p = *ident;char *end; -if (**ident =='<' ) + *ident =strchrnul (*ident,'\n' ); +if (**ident =='\n' ) + (*ident)++; + +if (*p =='<' )return report (options, obj,FSCK_MSG_MISSING_NAME_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - *ident +=strcspn (*ident,"<>\n" ); -if (**ident =='>' ) + p +=strcspn (p,"<>\n" ); +if (*p =='>' )return report (options, obj,FSCK_MSG_BAD_NAME ,"invalid author/committer line - bad name" ); -if (**ident !='<' ) +if (*p !='<' )return report (options, obj,FSCK_MSG_MISSING_EMAIL ,"invalid author/committer line - missing email" ); -if ((*ident)[-1 ] !=' ' ) +if (p[-1 ] !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - (*ident)++; - *ident +=strcspn (*ident,"<>\n" ); -if (**ident !='>' ) + p++; + p +=strcspn (p,"<>\n" ); +if (*p !='>' )return report (options, obj,FSCK_MSG_BAD_EMAIL ,"invalid author/committer line - bad email" ); - (*ident)++; -if (**ident !=' ' ) + p++; +if (*p !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_DATE ,"invalid author/committer line - missing space before date" ); - (*ident)++; -if (**ident =='0' && (*ident)[1 ] !=' ' ) + p++; +if (*p =='0' && p[1 ] !=' ' )return report (options, obj,FSCK_MSG_ZERO_PADDED_DATE ,"invalid author/committer line - zero-padded date" ); -if (date_overflows (strtoul (*ident, &end,10 ))) +if (date_overflows (strtoul (p, &end,10 )))return report (options, obj,FSCK_MSG_DATE_OVERFLOW ,"invalid author/committer line - date causes integer overflow" ); -if (end == *ident || *end !=' ' ) +if ((end == p || *end !=' ' ))return report (options, obj,FSCK_MSG_BAD_DATE ,"invalid author/committer line - bad date" ); - *ident = end +1 ; -if ((**ident !='+' && **ident !='-' ) || - !isdigit ((*ident)[1 ]) || - !isdigit ((*ident)[2 ]) || - !isdigit ((*ident)[3 ]) || - !isdigit ((*ident)[4 ]) || - ((*ident)[5 ] !='\n' )) + p = end +1 ; +if ((*p !='+' && *p !='-' ) || + !isdigit (p[1 ]) || + !isdigit (p[2 ]) || + !isdigit (p[3 ]) || + !isdigit (p[4 ]) || + (p[5 ] !='\n' ))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - (*ident) +=6 ; + p +=6 ;return 0 ; }
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 8/19 fsck: Make fsck_commit() warn-friendly
In reply to Johannes SchindelinWhen fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missing-author error to a warning would hide a problematic committer line.
--- fsck.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
@@ -508,12 +508,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (!skip_prefix (buffer,"tree " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_TREE ,"invalid format - expected 'tree' line" ); -if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ;while (skip_prefix (buffer,"parent " , &buffer)) { -if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ; parent_line_count++; }
@@ -522,11 +528,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (graft) {if (graft->nr_parent ==-1 && !parent_count) ;/* shallow commit */ -else if (graft->nr_parent != parent_count) -return report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +else if (graft->nr_parent != parent_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +if (err) +return err; + } }else { -if (parent_count != parent_line_count) -return report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (parent_count != parent_line_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (err) +return err; + } }if (!skip_prefix (buffer,"author " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_AUTHOR ,"invalid format - expected 'author' line" );
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 9/19 fsck: Handle multiple authors in commits specially
In reply to Johannes SchindelinThis problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
Technically, we could handle such repositories by setting receive.fsck.warn = missing-committer, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.
--- fsck.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fsck.c +9 -0
@@ -38,6 +38,7 @@ FUNC(MISSING_TREE, ERROR) \ FUNC(MISSING_TYPE, ERROR) \ FUNC(MISSING_TYPE_ENTRY, ERROR) \ + FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ FUNC(NUL_IN_HEADER, ERROR) \FUNC (TAG_OBJECT_NOT_TAG ,ERROR ) \
@@ -545,6 +546,14 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, err =fsck_ident (&buffer, &commit->object, options);if (err)return err; +while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err; + err =fsck_ident (&buffer, &commit->object, options); +if (err) +return err; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 10/19 fsck: Make fsck_tag() warn-friendly
In reply to Johannes SchindelinWhen fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.
--- fsck.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
@@ -614,7 +614,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, }if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { ret =report (options, &tag->object,FSCK_MSG_INVALID_OBJECT_SHA1 ,"invalid 'object' line format - bad sha1" ); - goto done; +if (ret) + goto done; } buffer +=41 ;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 11/19 fsck: Add a simple test for receive.fsck.*
In reply to Johannes Schindelin--- t/t5504-fetch-receive-strict.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
t/t5504-fetch-receive-strict.sh +20 -0
@@ -115,4 +115,24 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' +cat >bogus-commit <<\EOF +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +author Bugs Bunny 1234567890 +0000 +committer Bugs Bunny <[email protected]> 1234567890 +0000 + +This commit object intentionally broken +EOF + +test_expect_success 'push with receive.fsck.warn = missing-email' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.warn missing-email && + git push --porcelain dst bogus >act 2>&1 && + grep "missing-email" act +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 12/19 fsck: Disallow demoting grave fsck errors to warnings
In reply to Johannes SchindelinSome kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
--- fsck.c | 13 +++++++++++-- t/t5504-fetch-receive-strict.sh | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
fsck.c +11 -2
@@ -9,7 +9,12 @@#include "refs.h" #include "utf8.h" +#define FSCK_FATAL -1 +#define FOREACH_MSG_ID (FUNC ) \ +/* fatal errors */ \ + FUNC(NUL_IN_HEADER, FATAL) \ + FUNC(UNTERMINATED_HEADER, FATAL) \/* errors */ \ FUNC(BAD_DATE, ERROR) \FUNC (BAD_EMAIL ,ERROR ) \
@@ -40,10 +45,8 @@ FUNC(MISSING_TYPE_ENTRY, ERROR) \ FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ - FUNC(NUL_IN_HEADER, ERROR) \ FUNC(TAG_OBJECT_NOT_TAG, ERROR) \ FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(UNTERMINATED_HEADER, ERROR) \FUNC (ZERO_PADDED_DATE ,ERROR ) \ /* warnings */ \FUNC (BAD_FILEMODE ,WARN ) \
@@ -157,6 +160,9 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) } msg_id =parse_msg_id (mode, len); +if (severity !=FSCK_ERROR && + msg_id_info[msg_id].severity ==FSCK_FATAL ) +die ("Cannot demote %.*s" , len, mode); options->msg_severity[msg_id] = severity; mode += len; }
@@ -187,6 +193,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_FATAL ) + msg_severity =FSCK_ERROR ; +append_msg_id (&sb, msg_id_info[id].id_string);va_start (ap, fmt);
t/t5504-fetch-receive-strict.sh +9 -0
@@ -135,4 +135,13 @@ test_expect_success 'push with receive.fsck.warn = missing-email' ' grep "missing-email" act ' +test_expect_success 'receive.fsck.warn = unterminated-header triggers error' ' + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + git --git-dir=dst/.git config receive.fsck.warn unterminated-header && + test_must_fail git push --porcelain dst HEAD >act 2>&1 && + grep "Cannot demote unterminated-header" act +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 13/19 fsck: Optionally ignore specific fsck issues completely
In reply to Johannes SchindelinAn fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective error to "ignore".
This change "abuses" the warn=missing-email test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).
--- fsck.c | 5 +++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
fsck.c +5 -0
@@ -152,6 +152,8 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) severity =FSCK_ERROR ; else if (!substrcmp(mode, equal, "warn")) severity =FSCK_WARN ; + else if (!substrcmp(mode, equal, "ignore")) + severity =FSCK_IGNORE ; else die("Unknown fsck message severity: '%.*s'", equal, mode);
@@ -193,6 +195,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_IGNORE ) +return 0 ; +if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ;
fsck.h +1 -0
@@ -3,6 +3,7 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +#define FSCK_IGNORE 3struct fsck_options ;
t/t5504-fetch-receive-strict.sh +6 -1
@@ -132,7 +132,12 @@ test_expect_success 'push with receive.fsck.warn = missing-email' ' test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config receive.fsck.warn missing-email && git push --porcelain dst bogus >act 2>&1 && - grep "missing-email" act + grep "missing-email" act && + git --git-dir=dst/.git branch -D bogus && + git --git-dir=dst/.git config receive.fsck.ignore missing-email && + git --git-dir=dst/.git config receive.fsck.warn bad-date && + git push --porcelain dst bogus >act 2>&1 && + test_must_fail grep "missing-email" act ' test_expect_success 'receive.fsck.warn = unterminated-header triggers error' '
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 14/19 fsck: Allow upgrading fsck warnings to errors
In reply to Johannes SchindelinThe 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalid-tag-name and missing-tagger-entry to the receive.fsck.error config setting.
Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).
--- fsck.c | 24 +++++++++++++++++------- t/t5302-pack-index.sh | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
@@ -10,6 +10,7 @@#include "utf8.h" #define FSCK_FATAL -1 +#define FSCK_INFO -2#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \
@@ -55,10 +56,11 @@ FUNC(HAS_DOT, WARN) \ FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTGIT, WARN) \ - FUNC(INVALID_TAG_NAME, WARN) \ - FUNC(MISSING_TAGGER_ENTRY, WARN) \ FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) +FUNC (ZERO_PADDED_FILEMODE ,WARN ) \ + /* infos (reported as warnings, but ignored by default) */ \ + FUNC(INVALID_TAG_NAME, INFO) \ + FUNC(MISSING_TAGGER_ENTRY, INFO)#define MSG_ID (id, severity) FSCK_MSG_##id,enum fsck_msg_id {
@@ -200,6 +202,8 @@ static int report(struct fsck_options *options, struct object *object,if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ; +else if (msg_severity ==FSCK_INFO ) + msg_severity =FSCK_WARN ;append_msg_id (&sb, msg_id_info[id].id_string);
@@ -658,15 +662,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, goto done; }strbuf_addf (&sb,"refs/tags/%.*s" , (int )(eol - buffer), buffer); -if (check_refname_format (sb.buf,0 )) -report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME , +if (check_refname_format (sb.buf,0 )) { + ret =report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %.*s" , (int )(eol - buffer), buffer); +if (ret) + goto done; + } buffer = eol +1 ; -if (!skip_prefix (buffer,"tagger " , &buffer)) +if (!skip_prefix (buffer,"tagger " , &buffer)) {/* early tags do not contain 'tagger' lines; warn only */ -report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); + ret =report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); +if (ret) + goto done; + }else ret =fsck_ident (&buffer, &tag->object, options);
t/t5302-pack-index.sh +1 -1
@@ -259,7 +259,7 @@ EOF thirtyeight=${tag#??} && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^error:.* expected .tagger. line" err + grep "^warning:.* expected .tagger. line" err ' test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 15/19 fsck: Document the new receive.fsck.* options.
In reply to Johannes Schindelin--- Documentation/config.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Documentation/config.txt +28 -0
@@ -2130,6 +2130,34 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.error:: +receive.fsck.warn:: +receive.fsck.ignore:: + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.*` + settings. These settings contain comma-separated lists of fsck + message IDs. For convenience, fsck prefixes the error/warning with + the message ID, e.g. "missing-email: invalid + author/committer line - missing email" means that setting + `receive.fsck.ignore = missing-email` will hide that issue. ++ +-- +error;; + a comma-separated list of fsck message IDs that should be + trigger fsck to error out. +warn;; + a comma-separated list of fsck message IDs that should be + displayed, but fsck should continue to error out. +ignore;; + a comma-separated list of fsck message IDs that should be + ignored completely. +-- ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories with certain known issues but still catch +other issues. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 16/19 fsck: Support demoting errors to warnings
In reply to Johannes SchindelinWe already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.
Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.
Example: git -c fsck.ignore=missing-email fsck would hide problems with missing emails in author, committer and tagger lines.
In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.* from the receive.fsck.* settings.
--- Documentation/config.txt | 15 +++++++++++++++ builtin/fsck.c | 15 +++++++++++++++ t/t1450-fsck.sh | 11 +++++++++++ 3 files changed, 41 insertions(+)
Documentation/config.txt +15 -0
@@ -1208,6 +1208,21 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. +fsck.error:: +fsck.warn:: +fsck.ignore:: + The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify + comma-separated lists of fsck message IDs which should trigger + fsck to error out, to print the message and continue, or to ignore + said messages, respectively. ++ +For convenience, fsck prefixes the error/warning with the name of the option, +e.g. "missing-email: invalid author/committer line - missing email" means +that setting `fsck.ignore = missing-email` will hide that issue. ++ +This feature is intended to support working with legacy repositories +which cannot be repaired without disruptive changes. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +15 -0
@@ -46,6 +46,19 @@ static int show_dangling = 1;#define DIRENT_SORT_HINT (de) ((de)->d_ino)#endif +static int fsck_config (const char *var,const char *value,void *cb) +{ +if (skip_prefix (var,"fsck." , &var)) { +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"%s=%s" , var, value); +fsck_set_severity (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } + +return git_default_config (var, value, cb); +} +static void objreport (struct object *obj,const char *severity,const char *err) {
@@ -638,6 +651,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) include_reflogs =0 ; } +git_config (fsck_config,NULL ); +fsck_head_link ();fsck_object_dir (get_object_directory ());
t/t1450-fsck.sh +11 -0
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' ' grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out ' +test_expect_success 'force fsck to ignore double author' ' + git cat-file commit HEAD >basis && + sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && + new=$(git hash-object -t commit -w --stdin <multiple-authors) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + test_must_fail git fsck && + git -c fsck.ignore=multiple-authors fsck +' + _bz='\0' _bz5="$_bz$_bz$_bz$_bz$_bz" _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 17/19 fsck: Introduce `git fsck --quick`
In reply to Johannes SchindelinThis option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.
--- Documentation/git-fsck.txt | 7 ++++++- builtin/fsck.c | 7 ++++++- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found] [--[no-]dangling] [--[no-]progress] [<object>*] DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs object pools. This is now default; you can turn it off with --no-full. +--quick:: + Check only the connectivity of tags, commits and tree objects. By + avoiding to unpack blobs, this speeds up the operation, at the + expense of missing corrupt objects. + --strict:: Enable more strict checking, namely to catch a file mode recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
@@ -23,6 +23,7 @@ static int show_tags;static int show_unreachable;static int include_reflogs =1 ;static int check_full =1 ; +static int quick;static int check_strict;static int keep_cache_objects;static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ;
@@ -184,6 +185,8 @@ static void check_reachable_object(struct object *obj)if (!(obj->flags &HAS_OBJ )) {if (has_sha1_pack (obj->sha1))return ;/* it is in pack - forget about it */ +if (quick &&has_sha1_file (obj->sha1)) +return ;printf ("missing %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); errors_found |=ERROR_REACHABLE ;return ;
@@ -618,6 +621,7 @@ static struct option fsck_opts[] = {OPT_BOOL (0 ,"cache" , &keep_cache_objects,N_ ("make index objects head nodes" )),OPT_BOOL (0 ,"reflogs" , &include_reflogs,N_ ("make reflogs head nodes (default)" )),OPT_BOOL (0 ,"full" , &check_full,N_ ("also consider packs and alternate objects" )), +OPT_BOOL (0 ,"quick" , &quick,N_ ("check only connectivity" )),OPT_BOOL (0 ,"strict" , &check_strict,N_ ("enable more strict checking" )),OPT_BOOL (0 ,"lost-found" , &write_lost_and_found, N_("write dangling objects in .git/lost-found")),
@@ -654,7 +658,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)git_config (fsck_config,NULL );fsck_head_link (); -fsck_object_dir (get_object_directory ()); +if (!quick) +fsck_object_dir (get_object_directory ());prepare_alt_odb ();for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' ' test_must_fail git -C missing fsck ' +test_expect_success 'fsck --quick' ' + rm -rf quick && + git init quick && + ( + cd quick && + touch empty && + git add empty && + test_commit empty && + empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 && + rm -f $empty && + echo invalid >$empty && + test_must_fail git fsck --strict && + git fsck --strict --quick && + tree=$(git rev-parse HEAD:) && + suffix=${tree#??} && + tree=.git/objects/${tree%$suffix}/$suffix && + rm -f $tree && + echo invalid >$tree && + test_must_fail git fsck --strict --quick + ) +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 18/19 fsck: git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinThe optional new config option receive.fsck.skiplist specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.
--- Documentation/config.txt | 7 ++++++ builtin/receive-pack.c | 9 +++++++ fsck.c | 53 +++++++++++++++++++++++++++++++++++++++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 12 ++++++++++ 5 files changed, 82 insertions(+)
Documentation/config.txt +7 -0
@@ -2173,6 +2173,13 @@ which would not pass pushing when `receive.fsckObjects = true`, allowing the host to accept repositories with certain known issues but still catch other issues. +receive.fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
builtin/receive-pack.c +9 -0
@@ -116,6 +116,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +if (fsck_severity.len) +strbuf_addch (&fsck_severity,',' ); +strbuf_addf (&fsck_severity,"skiplist=%s" , path); +return 0 ; + } +if (skip_prefix (var,"receive.fsck." , &var)) {strbuf_addf (&fsck_severity,"%s%s=%s" , fsck_severity.len ?"," :"" , var, value);
fsck.c +53 -0
77 lines not on this page · raw message
fsck.h +1 -0
@@ -29,6 +29,7 @@ struct fsck_options {fsck_error error_func; unsigned strict:1;int *msg_severity; +struct sha1_array *skiplist; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000 This commit object intentionally broken EOF +test_expect_success 'push with receive.fsck.skiplist' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.skiplist SKIP && + echo $commit > dst/.git/SKIP && + git push --porcelain dst bogus +' + test_expect_success 'push with receive.fsck.warn = missing-email' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.2.0.33.gc18b867
PATCH v3 19/19 fsck: support ignoring objects in `git fsck` via fsck.skiplist
In reply to Johannes SchindelinIdentical to support in git receive-pack for the config option receive.fsck.skiplist, we now support ignoring given objects in git fsck` altogether.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
--- Documentation/config.txt | 7 +++++++ builtin/fsck.c | 10 ++++++++++ 2 files changed, 17 insertions(+)
Documentation/config.txt +7 -0
@@ -1223,6 +1223,13 @@ that setting `fsck.ignore = missing-email` will hide that issue. This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes. +fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +10 -0
@@ -49,6 +49,16 @@ static int show_dangling = 1;static int fsck_config (const char *var,const char *value,void *cb) { +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"skiplist=%s" , path); +fsck_set_severity (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } +if (skip_prefix (var,"fsck." , &var)) {struct strbuf sb =STRBUF_INIT ;strbuf_addf (&sb,"%s=%s" , var, value);
Signature · 1 line
2.2.0.33.gc18b867
Re: [PATCH 16/18] fsck: support demoting errors to warnings
In reply to Junio C HamanoQuoted 11 lines · Junio C Hamano
Quoted 9 lines · Johannes Schindelin
Quoted 4 lines · Junio C Hamano
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfErrorI had something similar in an earlier version of my patch series, but it was shot down rightfully: if you want to allow inheriting defaults from $HOME/.gitconfig, you have to configure the severity levels individually.
Quoted 6 lines
Hmmm. What's wrong with "fsck.warn -missingTagger" that overrides the earlier one, or even "fsck.info missingTagger" after having "fsck.warn other,missingTagger,yetanother", with the usual "last one wins" rule?
Whoever shot it down "rightfully" is wrong here, I would think.
Sorry I didn't notice this earlier; Johannes, please CC me on these series, especially the ones that I commented on earlier.
I might have been the one who "shot down" the "<severity>=<name>" style of configuration [1].
I don't feel strongly enough to make a big deal about this, especially considering that the other alternative has already been implemented. But for the record, let me explain why I prefer the "<name>=<severity>" style of configuration.
First, it is a truer representation of the data structure within the software, which is basically one severity value for each error type. This is not a decisive argument, but it often means that there is less impedance mismatch between the style of configuration and the concepts that it is configuring. For example,
$ git config receive.fsck.warn A,B,C
$ git config receive.fsck.error C,D,Eseems to be configuring two sets, but it is not. It is mysteriously setting "C" to be an error, in seeming contradiction of the first line [2].
Second, it is not correct to say that this is just an application of the "last setting wins" rule. The "last setting wins" rule has heretofore, as far as I know, only covered *single* settings that take a single value. If we applied that rule to the following:
$ git config receive.fsck.warn A,B,C
$ git config receive.fsck.warn B,Fthen the net result would be "B,F". But that is not your proposal at all; your proposal is for these two settings to be interpreted the same as
$ git config receive.fsck.warn A,B,C,F
Similarly, the traditional last setting rule, applied to the first example above, wouldn't cause the value of "fsck.warn" to be reduced to "A,B", as you propose. This is not the "last setting rule" that we are familiar with--it operates *across and within* values and across *multiple* names rather than just across the values for a single name.
Third, the "<severity>=<name>" style is hard to inquire via the command line, and probably also incompatible with the simplified internal config API in git (and probably libgit2, JGit, etc). The problem is that determining a *single* setting requires *three* configuration variables be inquired, and that the settings for those three variables need to be processed in the correct order, including the correct order of interleavings. For example, how would you inquire about the configured severity level of "missingTaggerEntry" using the shell? It would be a mess that would necessarily have to involve "git config --get-regexp" and error-prone parsing of comma-separated values. It would be so much easier to type
$ git config receive.fsck.missingtaggerentry
Fourth, the "<severity>=<name>" style would cause config files to get cluttered up with unused values. Suppose you have earlier run
$ git config receive.fsck.warn A,B,C
$ git config receive.fsck.ignore D,Eand now you want to demote "B" to "ignore". You can do
$ git config --add receive.fsck.ignore B
(don't forget "--add" or you've silently erased other, unrelated settings!) This gives the behavior that you want. But now your config file looks like
[receive "fsck"]
warn = A,B,C
ignore = D,E
ignore = B
The "B" on the first line is now just being carried along for no reason, but it would be quite awkward to clean it up programmatically. Effectively, these settings can only be added to but never removed because of the way multiple properties are mashed into a single setting.
I believe that one of the main arguments for the "<severity>=<name>" style of configuration is that it carries over more easily into convenient command-line options. But I think it will be unusual to want to configure these options by hand on the command line, let alone adjust many settings at the same time. The idea isn't to make it easy to work with repositories that have a level of breakage that fluctuates over time. It is to make it possible to work with *specific* repositories that have known breakage in their history. For such a repo you would configure one or two "ignore" options one time and then never adjust them again. (And it will also allow us to make our checks stricter in the future without breaking existing repositories, and even to add optional "policy" checks, like "forbid Windows-incompatible filenames".)
I would even go so far as to say that we don't *need* command-line option versions of these settings; if somebody really needs that they can type
$ git -c receive.fsck.missingtaggerentry=ignore fsck
(which also has the advantage of passing the setting through to any child processes). But *if* command-line options are considered necessary, I don't think that using a "<name>=<severity>" style within the config needs to rule out allowing command-line options in the form "--<severity>=<name>,<name>" as Junio has suggested.
Looking back at this email, I guess that I'm more strongly against the "<name>=<severity>" configuration style than I thought :-/
Michael
[1] I prefer to think that I just offered a little gentle discussion that informed Johannes's independent decision :-)
[2] But even on these terms, it is anomalous. The usual git way to configure a set in git would be
$ git config receive.fsck.warn A
$ git config --add receive.fsck.warn B
$ git config --add receive.fsck.warn C
$ git config receive.fsck.error C
$ git config --add receive.fsck.error D
$ git config --add receive.fsck.error E, which in fact has fewer of the disadvantages listed in this email.
Signature · 2 lines
Michael Haggerty [email protected]
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Michael,
Quoted 17 lines · Michael Haggerty
Quoted 16 lines · Junio C Hamano
Quoted 9 lines · Johannes Schindelin
Quoted 4 lines · Junio C Hamano
I suspect that it would be much better if the configuration variables were organized the other way around, e.g.
$ git config fsck.warn missingTagger,someOtherKindOfErrorI had something similar in an earlier version of my patch series, but it was shot down rightfully: if you want to allow inheriting defaults from $HOME/.gitconfig, you have to configure the severity levels individually.
Hmmm. What's wrong with "fsck.warn -missingTagger" that overrides the earlier one, or even "fsck.info missingTagger" after having "fsck.warn other,missingTagger,yetanother", with the usual "last one wins" rule?
Quoted 4 lines
Quoted 1 line
Whoever shot it down "rightfully" is wrong here, I would think.
Sorry I didn't notice this earlier; Johannes, please CC me on these series, especially the ones that I commented on earlier.
Very sorry, this is my fault. It can only be explained by my switching around some tools for other tools to work with email-based patch submission (which I had not done in a long time). But still, my mistake.
Quoted 2 lines
[1] I prefer to think that I just offered a little gentle discussion that informed Johannes's independent decision :-)
You did convince me back then. I just did not want to put up a fight against Junio because I was more interested in getting this feature merged before the holidays (it does feel awkward for me to leave work unwrapped-up before leaving for an extended amount of time, but I guess I am getting more used to that).
So now I cannot avoid discussing this issue properly...
In essence, I agreed with Junio from the point of view of an elegant implementation. But then, Michael is correct that it does not really matter as much how complicated the code is, but that it is much more important that the feature is elegant to use.
Now let's step back a bit and think about the users which is supposed to be supported by this patch series: Git repository hosters -- such as GitHub -- need to ensure a certain cleanliness of the repositories they host (for a range of reasons, including the prevention of malicious attacks, or helping users publish their code in a correct form).
And the scenario in which the feature needs to be used is most likely started by some Git user pushing some commits, and git receive-pack triggering an error. Then the user files a trouble ticket and GitHubber needs to inspect the error and the respective object. Now, in the vast number of cases I imagine that the objects *are* faulty. However, on occasion the problem should not prevent the push, e.g. when somebody crafted a commit object with two authors, forgetting that the tools usually cannot handle such commits. Then the GitHubber has to decide on a case by case basis whether to demote that error to a warning and allow the object to be pushed *into that specific repository*.
I do see the need for this feature to be simple and robust, from the users' point of view. In other words, I agree with Michael that we need to avoid confusing settings such as
```
[receive.fsck]
warn = missing-tagger-entry
error = missing-tagger-entry
```This feature will be used rarely enough that the poor soul stuck with interpreting the above config section won't remember that a very specific version of "last setting wins" is in effect.
If I remember correctly, Peff suggested that there needs to be a way to handle these settings in the /etc/gitconfig $HOME/.gitconfig $XDG../gitconfig .git/config cascade, but now I am puzzled whether it is even desirable to demote fsck errors globally, i.e. whether we really need to pay attention to that config cascade.
And finally, in the course of preparing this patch series, we came up with an alternative solution to the problem: the receive.fsck.skiplist (i.e. a file that contains a sorted list of SHA-1s of objects that should be skipped from fsck'ing). I am more and more convinced that this is the most convenient tool for the scenario described above: manual inspection of individual objects will tell whether it is safe to allow them onto the server or not.
However, others might disagree and prefer the explicit approach, e.g. when some source generates a consistent stream of objects triggering fsck errors.
Summary: I have no preference how to specify the severity levels of fsck messages, but I will gladly change my code to whatever you (meaning Junio and Michael in particular) want to see implemented.
Thanks for helping me with this feature,
Dscho
Re: [PATCH 16/18] fsck: support demoting errors to warnings
Hi Michael & Junio,
Quoted 7 lines · Johannes Schindelin
[...] we need to avoid confusing settings such as
``` [receive.fsck] warn = missing-tagger-entry error = missing-tagger-entry ```
I *think* I found a solution.
Please let me recapitulate quickly the problem Michael brought up: if we support receive.fsck.warn to override receive.fsck.error and vice versa, with comma-separated lists, then it can be quite confusing to the user, and actually quite difficult to figure out on the command-line which setting is in effect (because it really depends on the *order* of the receive.fsck.* lines, *plus* the fact that the values are comma-separated lists).
On the other hand, Junio pointed out two shortcomings with my original implementation (i.e. to support receive.fsck.<id> = (error|warn|ignore)), however: it is tedious to set multiple severity levels, and it violates the config file convention that the config variable names are CamelCased (the message IDs are dashed-lowercase instead).
The solution I just implemented (and will send out shortly in v4 of the patch series) is the following: the config variable is called receive.fsck.severity and it accepts comma-separated settings. Example:
```
[receive "fsck"]
severity = multiple-authors=ignore,missing-tagger=error
```Now, it is *still* not the easiest to figure out the setting from the command-line:
```sh
$ git config --get-all receive.fsck.severity |
tr "," "\n" |
grep ^multiple-authors= |
tail -n 1
```But I hope this is good enough, Michael?
Ciao,
Dscho
v4 cover Introduce an internal API to interact with the fsck machinery
In reply to Junio C HamanoAt the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.
This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.
I am proud to report that this work has been sponsored by GitHub.
Changes vs v3: address Junio's concern regarding repeated patterns, heed Peff's advice to avoid that pesky clang warning re: unsigned enums, use the fsck.skiplist setting in builtin/fsck.c (not receive.fsck.skiplist), and switch to fsck.severity to address Michael's concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially; interdiff below the diffstat.
Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings
fsck: Allow demoting errors to warnings
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.severity
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.severity options.
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --quick
fsck: git receive-pack: support excluding objects from fsck'ing
fsck: support ignoring objects in git fsck via fsck.skiplist
Documentation/config.txt | 41 ++++ Documentation/git-fsck.txt | 7 +- builtin/fsck.c | 73 ++++-- builtin/index-pack.c | 13 +- builtin/receive-pack.c | 21 +- builtin/unpack-objects.c | 16 +- fsck.c | 532 +++++++++++++++++++++++++++++++--------- fsck.h | 27 +- t/t1450-fsck.sh | 37 ++- t/t5302-pack-index.sh | 2 +- t/t5504-fetch-receive-strict.sh | 49 ++++ 11 files changed, 656 insertions(+), 162 deletions(-)
Documentation/config.txt +13 -29
@@ -1208,17 +1208,14 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. -fsck.error:: -fsck.warn:: -fsck.ignore:: - The `fsck.error`, `fsck.warn` and `fsck.ignore` settings specify - comma-separated lists of fsck message IDs which should trigger - fsck to error out, to print the message and continue, or to ignore - said messages, respectively. +fsck.severity:: + A comma-separated lists of of the form `<id>=<level>` where `<id>` + denotes a fsck message ID such as `missing-email` and `<level>` is + one of `error`, `warn` and `ignore`. + -For convenience, fsck prefixes the error/warning with the name of the option, +For convenience, fsck prefixes the error/warning with the message ID, e.g. "missing-email: invalid author/committer line - missing email" means -that setting `fsck.ignore = missing-email` will hide that issue. +that setting `fsck.severity = missing-email=ignore` will hide that issue. + This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes.
@@ -2152,28 +2149,15 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. -receive.fsck.error:: -receive.fsck.warn:: -receive.fsck.ignore:: +receive.fsck.severity:: When `receive.fsckObjects` is set to true, errors can be switched - to warnings and vice versa by configuring the `receive.fsck.*` - settings. These settings contain comma-separated lists of fsck - message IDs. For convenience, fsck prefixes the error/warning with - the message ID, e.g. "missing-email: invalid + to warnings and vice versa by configuring the `receive.fsck.severity` + setting. These settings contain comma-separated lists of the form + `<id>=<level>` where the `<id>` is the fsck message ID and the level + is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes + the error/warning with the message ID, e.g. "missing-email: invalid author/committer line - missing email" means that setting - `receive.fsck.ignore = missing-email` will hide that issue. -+ --- -error;; - a comma-separated list of fsck message IDs that should be - trigger fsck to error out. -warn;; - a comma-separated list of fsck message IDs that should be - displayed, but fsck should continue to error out. -ignore;; - a comma-separated list of fsck message IDs that should be - ignored completely. --- + `receive.fsck.severity = missing-email=ignore` will hide that issue. + This feature is intended to support working with legacy repositories which would not pass pushing when `receive.fsckObjects = true`, allowing
builtin/fsck.c +6 -9
@@ -49,7 +49,12 @@ static int show_dangling = 1;static int fsck_config (const char *var,const char *value,void *cb) { -if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) { +if (strcmp (var,"fsck.severity" ) ==0 ) { +fsck_set_severity (&fsck_obj_options, value); +return 0 ; + } + +if (strcmp (var,"fsck.skiplist" ) ==0 ) {const char *path =is_absolute_path (value) ? value :git_path ("%s" , value);struct strbuf sb =STRBUF_INIT ;
@@ -59,14 +64,6 @@ static int fsck_config(const char *var, const char *value, void *cb)return 0 ; } -if (skip_prefix (var,"fsck." , &var)) { -struct strbuf sb =STRBUF_INIT ; -strbuf_addf (&sb,"%s=%s" , var, value); -fsck_set_severity (&fsck_obj_options, sb.buf); -strbuf_release (&sb); -return 0 ; - } -return git_default_config (var, value, cb); }
builtin/receive-pack.c +10 -13
@@ -116,18 +116,17 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"receive.fsck.severity" ) ==0 ) { +strbuf_addf (&fsck_severity,"%c%s" , + fsck_severity.len ?',' :'=' , value); +return 0 ; + } +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) {const char *path =is_absolute_path (value) ? value :git_path ("%s" , value); -if (fsck_severity.len) -strbuf_addch (&fsck_severity,',' ); -strbuf_addf (&fsck_severity,"skiplist=%s" , path); -return 0 ; - } - -if (skip_prefix (var,"receive.fsck." , &var)) { -strbuf_addf (&fsck_severity,"%s%s=%s" , - fsck_severity.len ?"," :"" , var, value); +strbuf_addf (&fsck_severity,"%cskiplist=%s" , + fsck_severity.len ?',' :'=' , path);return 0 ; }
@@ -1487,8 +1486,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)if (quiet)argv_array_push (&child.args,"-q" );if (fsck_objects) -argv_array_pushf (&child.args,"--strict%s%s" , - fsck_severity.len ?"=" :"" , +argv_array_pushf (&child.args,"--strict%s" , fsck_severity.buf); child.no_stdout =1 ; child.err = err_fd;
@@ -1507,8 +1505,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL );if (fsck_objects) -argv_array_pushf (&child.args,"--strict%s%s" , - fsck_severity.len ?"=" :"" , +argv_array_pushf (&child.args,"--strict%s" , fsck_severity.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" );
fsck.c +28 -21
70 lines not on this page · raw message
t/t1450-fsck.sh +1 -1
@@ -295,7 +295,7 @@ test_expect_success 'force fsck to ignore double author' ' git update-ref refs/heads/bogus "$new" && test_when_finished "git update-ref -d refs/heads/bogus" && test_must_fail git fsck && - git -c fsck.ignore=multiple-authors fsck + git -c fsck.severity=multiple-authors=ignore fsck ' _bz='\0'
t/t5504-fetch-receive-strict.sh +9 -6
@@ -135,28 +135,31 @@ test_expect_success 'push with receive.fsck.skiplist' ' git push --porcelain dst bogus ' -test_expect_success 'push with receive.fsck.warn = missing-email' ' +test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus && rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && test_must_fail git push --porcelain dst bogus && - git --git-dir=dst/.git config receive.fsck.warn missing-email && + git --git-dir=dst/.git config \ + receive.fsck.severity missing-email=warn && git push --porcelain dst bogus >act 2>&1 && grep "missing-email" act && git --git-dir=dst/.git branch -D bogus && - git --git-dir=dst/.git config receive.fsck.ignore missing-email && - git --git-dir=dst/.git config receive.fsck.warn bad-date && + git --git-dir=dst/.git config --add \ + receive.fsck.severity missing-email=ignore,bad-date=warn && git push --porcelain dst bogus >act 2>&1 && test_must_fail grep "missing-email" act ' -test_expect_success 'receive.fsck.warn = unterminated-header triggers error' ' +test_expect_success \ + 'receive.fsck.severity = unterminated-header=warn triggers error' ' rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && - git --git-dir=dst/.git config receive.fsck.warn unterminated-header && + git --git-dir=dst/.git config \ + receive.fsck.severity unterminated-header=warn && test_must_fail git push --porcelain dst HEAD >act 2>&1 && grep "Cannot demote unterminated-header" act '
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 1/19 fsck: Introduce fsck options
Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.
--- builtin/fsck.c | 20 +++++-- builtin/index-pack.c | 9 +-- builtin/unpack-objects.c | 11 ++-- fsck.c | 150 +++++++++++++++++++++++------------------------ fsck.h | 17 +++++- 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
@@ -25,6 +25,8 @@ static int include_reflogs = 1;static int check_full =1 ;static int check_strict;static int keep_cache_objects; +static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ; +static struct fsck_options fsck_obj_options =FSCK_OPTIONS_DEFAULT ;static unsigned char head_sha1[20 ];static const char *head_points_at;static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)static struct object_array pending; -static int mark_object (struct object *obj,int type,void *data) +static int mark_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct object *parent = data;
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)static void mark_object_reachable (struct object *obj) { -mark_object (obj,OBJ_ANY ,NULL ); +mark_object (obj,OBJ_ANY ,NULL ,NULL ); }static int traverse_one_object (struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)if (parse_tree (tree) <0 )return 1 ;/* error already displayed */ } - result =fsck_walk (obj, mark_object, obj); + result =fsck_walk (obj, obj, &fsck_walk_options);if (tree)free_tree_buffer (tree);return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,int type,void *data) +static int mark_used (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return 1 ;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)fprintf (stderr,"Checking %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); -if (fsck_walk (obj, mark_used,NULL )) +if (fsck_walk (obj,NULL , &fsck_obj_options))objerror (obj,"broken links" ); -if (fsck_object (obj,NULL ,0 , check_strict, fsck_error_func)) +if (fsck_object (obj,NULL ,0 , &fsck_obj_options))return -1 ;if (obj->type ==OBJ_TREE ) {
@@ -630,6 +632,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, fsck_opts, fsck_usage,0 ); + fsck_walk_options.walk = mark_object; + fsck_obj_options.walk = mark_used; + fsck_obj_options.error_func = fsck_error_func; +if (check_strict) + fsck_obj_options.strict =1 ; +if (show_progress ==-1 ) show_progress =isatty (2 );if (verbose)
builtin/index-pack.c +5 -4
@@ -74,6 +74,7 @@ static int nr_threads;static int from_stdin;static int strict;static int do_fsck_object; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;static int verbose;static int show_stat;static int check_self_contained_and_connected;
@@ -191,7 +192,7 @@ static void cleanup_thread(void)#endif -static int mark_link (struct object *obj,int type,void *data) +static int mark_link (struct object *obj,int type,void *data,struct fsck_options *options) {if (!obj)return -1 ;
@@ -782,10 +783,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,if (!obj)die (_ ("invalid %s" ),typename (type));if (do_fsck_object && -fsck_object (obj, buf, size,1 , - fsck_error_function)) +fsck_object (obj, buf, size, &fsck_options))die (_ ("Error in object" )); -if (fsck_walk (obj, mark_link,NULL )) + fsck_options.walk = mark_link; +if (fsck_walk (obj,NULL , &fsck_options))die (_ ("Not all child objects of %s are reachable" ),sha1_to_hex (obj->sha1));if (obj->type ==OBJ_TREE ) {
builtin/unpack-objects.c +6 -5
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];static unsigned int offset, len;static off_t consumed_bytes;static git_SHA_CTX ctx; +static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ;/* * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object (struct object *obj,int type,void *data) +static int check_object (struct object *obj,int type,void *data,struct fsck_options *options) {struct obj_buffer *obj_buf;
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data) obj_buf =lookup_object_buffer (obj);if (!obj_buf)die ("Whoops! Cannot find object '%s'" ,sha1_to_hex (obj->sha1)); -if (fsck_object (obj, obj_buf->buffer, obj_buf->size,1 , - fsck_error_function)) +if (fsck_object (obj, obj_buf->buffer, obj_buf->size, &fsck_options))die ("Error in object" ); -if (fsck_walk (obj, check_object,NULL )) + fsck_options.walk = check_object; +if (fsck_walk (obj,NULL , &fsck_options))die ("Error on reachable objects of %s" ,sha1_to_hex (obj->sha1));write_cached_object (obj, obj_buf);return 0 ;
@@ -217,7 +218,7 @@ static void write_rest(void)unsigned i;for (i =0 ; i < nr_objects; i++) {if (obj_list[i].obj) -check_object (obj_list[i].obj,OBJ_ANY ,NULL ); +check_object (obj_list[i].obj,OBJ_ANY ,NULL ,NULL ); } }
fsck.c +75 -75
392 lines not on this page · raw message
fsck.h +14 -3
@@ -4,6 +4,8 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +struct fsck_options ; +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@* <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func )(struct object *obj,int type,void *data); +typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...); __attribute__((format (printf,3 ,4 )))int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +struct fsck_options { +fsck_walk_func walk; +fsck_error error_func; +unsigned strict:1 ; +}; + +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +/* descend in all linked child objects * the return value is: * -1 error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);* >0 return value of the first signaled error >0 (in the case of no other errors) * 0 everything OK */ -int fsck_walk (struct object *obj,fsck_walk_func walk,void *data); +int fsck_walk (struct object *obj,void *data,struct fsck_options *options);/* If NULL is passed for data, we assume the object is local and read it. */ int fsck_object (struct object *obj,void *data,unsigned long size, -int strict,fsck_error error_func); +struct fsck_options *options);#endif
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 2/19 fsck: Introduce identifiers for fsck messages
In reply to Johannes SchindelinInstead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.
In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.
We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate severity levels. Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.
--- builtin/fsck.c | 24 ++----- fsck.c | 201 +++++++++++++++++++++++++++++++++++++++++---------------- fsck.h | 5 +- 3 files changed, 153 insertions(+), 77 deletions(-)
builtin/fsck.c +7 -17
@@ -47,32 +47,22 @@ static int show_dangling = 1;#endif static void objreport (struct object *obj,const char *severity, -const char *err,va_list params) +const char *err) { -fprintf (stderr,"%s in %s %s: " , - severity,typename (obj->type),sha1_to_hex (obj->sha1)); -vfprintf (stderr, err, params); -fputs ("\n" , stderr); +fprintf (stderr,"%s in %s %s: %s\n" , + severity,typename (obj->type),sha1_to_hex (obj->sha1), err); } -__attribute__((format (printf,2 ,3 ))) -static int objerror (struct object *obj,const char *err, ...) +static int objerror (struct object *obj,const char *err) { -va_list params; -va_start (params, err); errors_found |=ERROR_OBJECT ; -objreport (obj,"error" , err, params); -va_end (params); +objreport (obj,"error" , err);return -1 ; } -__attribute__((format (printf,3 ,4 ))) -static int fsck_error_func (struct object *obj,int type,const char *err, ...) +static int fsck_error_func (struct object *obj,int type,const char *message) { -va_list params; -va_start (params, err); -objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , err, params); -va_end (params); +objreport (obj, (type ==FSCK_WARN ) ?"warning" :"error" , message);return (type ==FSCK_WARN ) ?0 :1 ; }
fsck.c +144 -57
356 lines not on this page · raw message
fsck.h +2 -3
@@ -17,10 +17,9 @@ struct fsck_options;typedef int (*fsck_walk_func )(struct object *obj,int type,void *data,struct fsck_options *options);/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ -typedef int (*fsck_error )(struct object *obj,int type,const char *err, ...); +typedef int (*fsck_error )(struct object *obj,int type,const char *message); -__attribute__((format (printf,3 ,4 ))) -int fsck_error_function (struct object *obj,int type,const char *fmt, ...); +int fsck_error_function (struct object *obj,int type,const char *message);struct fsck_options {fsck_walk_func walk;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 3/19 fsck: Provide a function to parse fsck message IDs
In reply to Johannes SchindelinThis function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, 'missing-email,missing-tagger-entry' command lines.
To make the parsing robust, we generate strings from the enum keys, and using these keys, we will map lower-case, dash-separated strings values to the corresponding enum values.
--- fsck.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
fsck.c +25 -2
@@ -63,15 +63,38 @@ enum fsck_msg_id { };#undef MSG_ID -#define MSG_ID (id, severity) { FSCK_##severity }, +#define STR (x) #x +#define MSG_ID (id, severity) { STR(id), FSCK_##severity },static struct { +const char *id_string;int severity; } msg_id_info[FSCK_MSG_MAX +1 ] = { FOREACH_MSG_ID(MSG_ID) - {-1 } + {NULL ,-1 } };#undef MSG_ID +static int parse_msg_id (const char *text,int len) +{ +int i, j; + +for (i =0 ; i <FSCK_MSG_MAX ; i++) { +const char *key = msg_id_info[i].id_string; +/* id_string is upper-case, with underscores */ +for (j =0 ; j < len; j++) { +char c = *(key++); +if (c =='_' ) + c ='-' ; +if (text[j] !=tolower (c)) +break ; + } +if (j == len && !*key) +return i; + } + +die ("Unhandled message id: %.*s" , len, text); +} +static int fsck_msg_severity (enum fsck_msg_id msg_id,struct fsck_options *options) {
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 4/19 fsck: Offer a function to demote fsck errors to warnings
In reply to Johannes SchindelinThere are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.
Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.
The function added by this commit parses a list of settings in the form:
missing-email=warn,bad-name=warn,...
Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to default to all FSCK_ERROR in those cases.
--- fsck.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- fsck.h | 7 +++++-- 2 files changed, 72 insertions(+), 5 deletions(-)
fsck.c +67 -3
@@ -100,13 +100,73 @@ static int fsck_msg_severity(enum fsck_msg_id msg_id, {int severity; - severity = msg_id_info[msg_id].severity; -if (options->strict && severity ==FSCK_WARN ) - severity =FSCK_ERROR ; +assert (msg_id >=0 && msg_id <FSCK_MSG_MAX ); + +if (options->msg_severity) + severity = options->msg_severity[msg_id]; +else { + severity = msg_id_info[msg_id].severity; +if (options->strict && severity ==FSCK_WARN ) + severity =FSCK_ERROR ; + }return severity; } +static inline int substrcmp (const char *string,int len,const char *match) +{ +int match_len =strlen (match); +if (match_len != len) +return -1 ; +return memcmp (string, match, len); +} + +void fsck_set_severity (struct fsck_options *options,const char *mode) +{ +int severity =FSCK_ERROR ; + +if (!options->msg_severity) { +int i; +int *msg_severity =xmalloc (sizeof (int ) *FSCK_MSG_MAX ); +for (i =0 ; i <FSCK_MSG_MAX ; i++) + msg_severity[i] =fsck_msg_severity (i, options); + options->msg_severity = msg_severity; + } + +while (*mode) { +int len =strcspn (mode," ,|" ), equal, msg_id; + +if (!len) { + mode++; +continue ; + } + +for (equal =0 ; equal < len; equal++) +if (mode[equal] =='=' || mode[equal] ==':' ) +break ; + + msg_id =parse_msg_id (mode, equal); + +if (equal == len) + severity =FSCK_ERROR ; +else { +const char *p = mode + equal +1 ; +int len2 = len - equal -1 ; + +if (!substrcmp (p, len2,"error" )) + severity =FSCK_ERROR ; +else if (!substrcmp (p, len2,"warn" )) + severity =FSCK_WARN ; +else +die ("Unknown fsck message severity: '%.*s'" , + len2, p); + } + + options->msg_severity[msg_id] = severity; + mode += len; + } +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -596,6 +656,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,int fsck_error_function (struct object *obj,int severity,const char *message) { +if (severity ==FSCK_WARN ) { +warning ("object %s: %s" ,sha1_to_hex (obj->sha1), message); +return 0 ; + }error ("object %s: %s" ,sha1_to_hex (obj->sha1), message);return 1 ; }
fsck.h +5 -2
@@ -6,6 +6,8 @@struct fsck_options ; +void fsck_set_severity (struct fsck_options *options,const char *mode); +/* * callback function for fsck_walk * type is the expected type of the object or OBJ_ANY
@@ -25,10 +27,11 @@ struct fsck_options {fsck_walk_func walk;fsck_error error_func; unsigned strict:1; +int *msg_severity; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 } +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL } +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }/* descend in all linked child objects * the return value is:
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 5/19 fsck: Allow demoting errors to warnings
In reply to Johannes SchindelinFor example, missing emails in commit and tag objects can be demoted to mere warnings with
git config receive.fsck.severity missing-email=warn
The value is actually a comma-separated list.
In case that the same key is listed in multiple receive.fsck.severity lines in the config, the latter configuration wins (this can happen for example when both $HOME/.gitconfig and .git/config contain severity 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.
--- builtin/index-pack.c | 4 ++++ builtin/receive-pack.c | 13 +++++++++++-- builtin/unpack-objects.c | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-)
builtin/index-pack.c +4 -0
@@ -1565,6 +1565,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (!strcmp (arg,"--strict" )) { strict =1 ; do_fsck_object =1 ; + }else if (skip_prefix (arg,"--strict=" , &arg)) { + strict =1 ; + do_fsck_object =1 ; +fsck_set_severity (&fsck_options, arg); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +11 -2
@@ -36,6 +36,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; +static struct strbuf fsck_severity =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int advertise_atomic_push =1 ;
@@ -115,6 +116,12 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"receive.fsck.severity" ) ==0 ) { +strbuf_addf (&fsck_severity,"%c%s" , + fsck_severity.len ?',' :'=' , value); +return 0 ; + } +if (strcmp (var,"receive.fsckobjects" ) ==0 ) { receive_fsck_objects =git_config_bool (var, value);return 0 ;
@@ -1471,7 +1478,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)if (quiet)argv_array_push (&child.args,"-q" );if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +argv_array_pushf (&child.args,"--strict%s" , + fsck_severity.buf); child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1489,7 +1497,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_pushl (&child.args,"index-pack" ,"--stdin" , hdr_arg, keep_arg,NULL );if (fsck_objects) -argv_array_push (&child.args,"--strict" ); +argv_array_pushf (&child.args,"--strict%s" , + fsck_severity.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +5 -0
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) strict =1 ;continue ; } +if (skip_prefix (arg,"--strict=" , &arg)) { + strict =1 ; +fsck_set_severity (&fsck_options, arg); +continue ; + }if (starts_with (arg,"--pack_header=" )) {struct pack_header *hdr;char *c;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 11/19 fsck: Add a simple test for receive.fsck.severity
In reply to Johannes Schindelin--- t/t5504-fetch-receive-strict.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
t/t5504-fetch-receive-strict.sh +21 -0
@@ -115,4 +115,25 @@ test_expect_success 'push with transfer.fsckobjects' ' test_cmp exp act ' +cat >bogus-commit <<\EOF +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 +author Bugs Bunny 1234567890 +0000 +committer Bugs Bunny <[email protected]> 1234567890 +0000 + +This commit object intentionally broken +EOF + +test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config \ + receive.fsck.severity missing-email=warn && + git push --porcelain dst bogus >act 2>&1 && + grep "missing-email" act +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 6/19 fsck: Report the ID of the error/warning
In reply to Johannes SchindelinSome legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missing-email", the user might want to call git config --add receive.fsck.severity missing-email=warn).
--- fsck.c | 19 +++++++++++++++++++ t/t1450-fsck.sh | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-)
fsck.c +19 -0
@@ -167,6 +167,23 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) } } +static void append_msg_id (struct strbuf *sb,const char *msg_id) +{ +for (;;) { +char c = *(msg_id)++; + +if (!c) +break ; +if (c =='_' ) + c ='-' ; +else + c =tolower (c); +strbuf_addch (sb, c); + } + +strbuf_addstr (sb,": " ); +} + __attribute__((format (printf,4 ,5 )))static int report (struct fsck_options *options,struct object *object,enum fsck_msg_id id,const char *fmt, ...)
@@ -175,6 +192,8 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +append_msg_id (&sb, msg_id_info[id].id_string); +va_start (ap, fmt);strbuf_vaddf (&sb, fmt, ap); result = options->error_func (object, msg_severity, sb.buf);
t/t1450-fsck.sh +2 -2
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' git fsck --tags 2>out && cat >expect <<-EOF && - warning in tag $tag: invalid '\''tag'\'' name: wrong name format - warning in tag $tag: invalid format - expected '\''tagger'\'' line + warning in tag $tag: invalid-tag-name: invalid '\''tag'\'' name: wrong name format + warning in tag $tag: missing-tagger-entry: invalid format - expected '\''tagger'\'' line EOF test_cmp expect out '
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 7/19 fsck: Make fsck_ident() warn-friendly
In reply to Johannes SchindelinWhen fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.
--- fsck.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
@@ -459,40 +459,45 @@ static int require_end_of_header(const void *data, unsigned long size,static int fsck_ident (const char **ident,struct object *obj,struct fsck_options *options) { +const char *p = *ident;char *end; -if (**ident =='<' ) + *ident =strchrnul (*ident,'\n' ); +if (**ident =='\n' ) + (*ident)++; + +if (*p =='<' )return report (options, obj,FSCK_MSG_MISSING_NAME_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - *ident +=strcspn (*ident,"<>\n" ); -if (**ident =='>' ) + p +=strcspn (p,"<>\n" ); +if (*p =='>' )return report (options, obj,FSCK_MSG_BAD_NAME ,"invalid author/committer line - bad name" ); -if (**ident !='<' ) +if (*p !='<' )return report (options, obj,FSCK_MSG_MISSING_EMAIL ,"invalid author/committer line - missing email" ); -if ((*ident)[-1 ] !=' ' ) +if (p[-1 ] !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL ,"invalid author/committer line - missing space before email" ); - (*ident)++; - *ident +=strcspn (*ident,"<>\n" ); -if (**ident !='>' ) + p++; + p +=strcspn (p,"<>\n" ); +if (*p !='>' )return report (options, obj,FSCK_MSG_BAD_EMAIL ,"invalid author/committer line - bad email" ); - (*ident)++; -if (**ident !=' ' ) + p++; +if (*p !=' ' )return report (options, obj,FSCK_MSG_MISSING_SPACE_BEFORE_DATE ,"invalid author/committer line - missing space before date" ); - (*ident)++; -if (**ident =='0' && (*ident)[1 ] !=' ' ) + p++; +if (*p =='0' && p[1 ] !=' ' )return report (options, obj,FSCK_MSG_ZERO_PADDED_DATE ,"invalid author/committer line - zero-padded date" ); -if (date_overflows (strtoul (*ident, &end,10 ))) +if (date_overflows (strtoul (p, &end,10 )))return report (options, obj,FSCK_MSG_DATE_OVERFLOW ,"invalid author/committer line - date causes integer overflow" ); -if (end == *ident || *end !=' ' ) +if ((end == p || *end !=' ' ))return report (options, obj,FSCK_MSG_BAD_DATE ,"invalid author/committer line - bad date" ); - *ident = end +1 ; -if ((**ident !='+' && **ident !='-' ) || - !isdigit ((*ident)[1 ]) || - !isdigit ((*ident)[2 ]) || - !isdigit ((*ident)[3 ]) || - !isdigit ((*ident)[4 ]) || - ((*ident)[5 ] !='\n' )) + p = end +1 ; +if ((*p !='+' && *p !='-' ) || + !isdigit (p[1 ]) || + !isdigit (p[2 ]) || + !isdigit (p[3 ]) || + !isdigit (p[4 ]) || + (p[5 ] !='\n' ))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - (*ident) +=6 ; + p +=6 ;return 0 ; }
Signature · 1 line
2.2.0.33.gc18b867
Hi all (in particular Junio),
Quoted 3 lines · Johannes Schindelin
[...] switch to fsck.severity to address Michael's
concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially;
Having participated in the CodingStyle thread, I came to the conclusion that the fsck.severity solution favors syntax over intuitiveness.
Therefore, I would like to support the case for fsck.level.missingAuthor (note that there is an extra ".level." in contrast to earlier suggestions).
The benefits:
- it is very, very easy to understand
- cumulative settings are intuitively cumulative, i.e. setting fsck.level.missingAuthor will leave fsck.level.invalidEmail completely unaffected
- it is very easy to enquire and set the levels via existing git config calls
Now, there is one downside, but *only* if we ignore Postel's law.
Postel's law ("be lenient in what you accept as input, but strict in your output") would dictate that our message ID parser accept both "missing-author" and "missingAuthor" if we follow the inconsistent practice of using lowercase-dashed keys on the command-line but CamelCased ones in the config.
However, earlier Junio made very clear that the parser is required to fail to parse "missing-author" in the config, and to fail to parse "missingAuthor" on the command-line.
Therefore, the design I recommend above will require two, minimally different parsers for essentially the same thing.
IMHO this is a downside that is by far outweighed by the ease of use of the new feature, therefore I am willing to bear the burden of implementation.
Do you agree?
Ciao,
Dscho
Quoted 8 lines · Johannes Schindelin
Hi all (in particular Junio),
Quoted 3 lines · Johannes Schindelin
[...] switch to fsck.severity to address Michael's concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially;
Quoted 7 lines
Having participated in the CodingStyle thread, I came to the conclusion that the fsck.severity solution favors syntax over intuitiveness.
Therefore, I would like to support the case for
fsck.level.missingAuthor(note that there is an extra ".level." in contrast to earlier suggestions).
Why "level"?
Quoted 23 lines
The benefits:
- it is very, very easy to understand
- cumulative settings are intuitively cumulative, i.e. setting
fsck.level.missingAuthorwill leavefsck.level.invalidEmailcompletely unaffected- it is very easy to enquire and set the levels via existing
git configcallsNow, there is one downside, but *only* if we ignore Postel's law.
Postel's law ("be lenient in what you accept as input, but strict in your output") would dictate that our message ID parser accept both "missing-author" and "missingAuthor" if we follow the inconsistent practice of using lowercase-dashed keys on the command-line but CamelCased ones in the config.
However, earlier Junio made very clear that the parser is required to fail to parse "missing-author" in the config, and to fail to parse "missingAuthor" on the command-line.
Quoted 6 lines
Therefore, the design I recommend above will require two, minimally different parsers for essentially the same thing.
IMHO this is a downside that is by far outweighed by the ease of use of the new feature, therefore I am willing to bear the burden of implementation.
I again encourage you to consider skipping the implementation of command-line options entirely. It's not like users are going to want to use different options for different invocations. Let them use
git -c fsck.level.missingAuthor=ignore fsck
if they really want to play around, then
git config fsck.level.missingAuthor ignore
to make it permanent. After that they will never have to worry about that option again.
And Postel needn't be offended :-)
Michael
Signature · 2 lines
Michael Haggerty [email protected]
Hi Michael,
Quoted 13 lines · Michael Haggerty
Quoted 12 lines · Johannes Schindelin
Hi all (in particular Junio),
Quoted 3 lines · Johannes Schindelin
[...] switch to fsck.severity to address Michael's concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially;
Having participated in the CodingStyle thread, I came to the conclusion that the fsck.severity solution favors syntax over intuitiveness.
Quoted 5 lines
Quoted 3 lines
Therefore, I would like to support the case for
fsck.level.missingAuthor(note that there is an extra ".level." in contrast to earlier suggestions).Why "level"?
"Severity level", or "error level". Maybe ".severity." would be better?
Quoted 34 lines
Quoted 23 lines
The benefits:
- it is very, very easy to understand
- cumulative settings are intuitively cumulative, i.e. setting
fsck.level.missingAuthorwill leavefsck.level.invalidEmailcompletely unaffected- it is very easy to enquire and set the levels via existing
git configcallsNow, there is one downside, but *only* if we ignore Postel's law.
Postel's law ("be lenient in what you accept as input, but strict in your output") would dictate that our message ID parser accept both "missing-author" and "missingAuthor" if we follow the inconsistent practice of using lowercase-dashed keys on the command-line but CamelCased ones in the config.
However, earlier Junio made very clear that the parser is required to fail to parse "missing-author" in the config, and to fail to parse "missingAuthor" on the command-line.
Quoted 6 lines
Therefore, the design I recommend above will require two, minimally different parsers for essentially the same thing.
IMHO this is a downside that is by far outweighed by the ease of use of the new feature, therefore I am willing to bear the burden of implementation.
I again encourage you to consider skipping the implementation of command-line options entirely. It's not like users are going to want to use different options for different invocations. Let them use
Quoted 8 lines
git -c fsck.level.missingAuthor=ignore fsck
if they really want to play around, then
git config fsck.level.missingAuthor ignore
to make it permanent. After that they will never have to worry about that option again.
Unfortunately, I have to pass the receive.fsck.* settings from git-receive-pack to git-unpack-objects or git-index-pack via the command-line, because it is git-receive-pack that consumes the config setting, but it is one of git-unpack-objects and git-index-pack that has to act on it...
Quoted 1 line
And Postel needn't be offended :-)
;-)
Ciao,
Dscho
PATCH v4 8/19 fsck: Make fsck_commit() warn-friendly
In reply to Johannes SchindelinWhen fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missing-author error to a warning would hide a problematic committer line.
--- fsck.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
@@ -514,12 +514,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (!skip_prefix (buffer,"tree " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_TREE ,"invalid format - expected 'tree' line" ); -if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (get_sha1_hex (buffer, tree_sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_TREE_SHA1 ,"invalid 'tree' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ;while (skip_prefix (buffer,"parent " , &buffer)) { -if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) -return report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { + err =report (options, &commit->object,FSCK_MSG_BAD_PARENT_SHA1 ,"invalid 'parent' line format - bad sha1" ); +if (err) +return err; + } buffer +=41 ; parent_line_count++; }
@@ -528,11 +534,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if (graft) {if (graft->nr_parent ==-1 && !parent_count) ;/* shallow commit */ -else if (graft->nr_parent != parent_count) -return report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +else if (graft->nr_parent != parent_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_GRAFT ,"graft objects missing" ); +if (err) +return err; + } }else { -if (parent_count != parent_line_count) -return report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (parent_count != parent_line_count) { + err =report (options, &commit->object,FSCK_MSG_MISSING_PARENT ,"parent objects missing" ); +if (err) +return err; + } }if (!skip_prefix (buffer,"author " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_AUTHOR ,"invalid format - expected 'author' line" );
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 9/19 fsck: Handle multiple authors in commits specially
In reply to Johannes SchindelinThis problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.
Technically, we could handle such repositories by setting receive.fsck.severity to missing-committer=warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.
--- fsck.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fsck.c +9 -0
@@ -38,6 +38,7 @@ FUNC(MISSING_TREE, ERROR) \ FUNC(MISSING_TYPE, ERROR) \ FUNC(MISSING_TYPE_ENTRY, ERROR) \ + FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ FUNC(NUL_IN_HEADER, ERROR) \FUNC (TAG_OBJECT_NOT_TAG ,ERROR ) \
@@ -551,6 +552,14 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, err =fsck_ident (&buffer, &commit->object, options);if (err)return err; +while (skip_prefix (buffer,"author " , &buffer)) { + err =report (options, &commit->object,FSCK_MSG_MULTIPLE_AUTHORS ,"invalid format - multiple 'author' lines" ); +if (err) +return err; + err =fsck_ident (&buffer, &commit->object, options); +if (err) +return err; + }if (!skip_prefix (buffer,"committer " , &buffer))return report (options, &commit->object,FSCK_MSG_MISSING_COMMITTER ,"invalid format - expected 'committer' line" ); err =fsck_ident (&buffer, &commit->object, options);
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 10/19 fsck: Make fsck_tag() warn-friendly
In reply to Johannes SchindelinWhen fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.
Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.
--- fsck.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
@@ -620,7 +620,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, }if (get_sha1_hex (buffer, sha1) || buffer[40 ] !='\n' ) { ret =report (options, &tag->object,FSCK_MSG_INVALID_OBJECT_SHA1 ,"invalid 'object' line format - bad sha1" ); - goto done; +if (ret) + goto done; } buffer +=41 ;
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 12/19 fsck: Disallow demoting grave fsck errors to warnings
In reply to Johannes SchindelinSome kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.
--- fsck.c | 13 +++++++++++-- t/t5504-fetch-receive-strict.sh | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-)
fsck.c +11 -2
@@ -9,7 +9,12 @@#include "refs.h" #include "utf8.h" +#define FSCK_FATAL -1 +#define FOREACH_MSG_ID (FUNC ) \ +/* fatal errors */ \ + FUNC(NUL_IN_HEADER, FATAL) \ + FUNC(UNTERMINATED_HEADER, FATAL) \/* errors */ \ FUNC(BAD_DATE, ERROR) \FUNC (BAD_EMAIL ,ERROR ) \
@@ -40,10 +45,8 @@ FUNC(MISSING_TYPE_ENTRY, ERROR) \ FUNC(MULTIPLE_AUTHORS, ERROR) \ FUNC(NOT_SORTED, ERROR) \ - FUNC(NUL_IN_HEADER, ERROR) \ FUNC(TAG_OBJECT_NOT_TAG, ERROR) \ FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(UNTERMINATED_HEADER, ERROR) \FUNC (ZERO_PADDED_DATE ,ERROR ) \ /* warnings */ \FUNC (BAD_FILEMODE ,WARN ) \
@@ -163,6 +166,9 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) len2, p); } +if (severity !=FSCK_ERROR && + msg_id_info[msg_id].severity ==FSCK_FATAL ) +die ("Cannot demote %.*s" , len, mode); options->msg_severity[msg_id] = severity; mode += len; }
@@ -193,6 +199,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_FATAL ) + msg_severity =FSCK_ERROR ; +append_msg_id (&sb, msg_id_info[id].id_string);va_start (ap, fmt);
t/t5504-fetch-receive-strict.sh +11 -0
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' grep "missing-email" act ' +test_expect_success \ + 'receive.fsck.severity = unterminated-header=warn triggers error' ' + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + git --git-dir=dst/.git config \ + receive.fsck.severity unterminated-header=warn && + test_must_fail git push --porcelain dst HEAD >act 2>&1 && + grep "Cannot demote unterminated-header" act +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 13/19 fsck: Optionally ignore specific fsck issues completely
In reply to Johannes SchindelinAn fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective error to "ignore".
This change "abuses" the missing-email=warn test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).
--- fsck.c | 5 +++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
fsck.c +5 -0
@@ -161,6 +161,8 @@ void fsck_set_severity(struct fsck_options *options, const char *mode) severity =FSCK_ERROR ; else if (!substrcmp(p, len2, "warn")) severity =FSCK_WARN ; + else if (!substrcmp(p, len2, "ignore")) + severity =FSCK_IGNORE ; else die("Unknown fsck message severity: '%.*s'", len2, p);
@@ -199,6 +201,9 @@ static int report(struct fsck_options *options, struct object *object,struct strbuf sb =STRBUF_INIT ;int msg_severity =fsck_msg_severity (id, options), result; +if (msg_severity ==FSCK_IGNORE ) +return 0 ; +if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ;
fsck.h +1 -0
@@ -3,6 +3,7 @@#define FSCK_ERROR 1#define FSCK_WARN 2 +#define FSCK_IGNORE 3struct fsck_options ;
t/t5504-fetch-receive-strict.sh +6 -1
@@ -133,7 +133,12 @@ test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' git --git-dir=dst/.git config \ receive.fsck.severity missing-email=warn && git push --porcelain dst bogus >act 2>&1 && - grep "missing-email" act + grep "missing-email" act && + git --git-dir=dst/.git branch -D bogus && + git --git-dir=dst/.git config --add \ + receive.fsck.severity missing-email=ignore,bad-date=warn && + git push --porcelain dst bogus >act 2>&1 && + test_must_fail grep "missing-email" act ' test_expect_success \
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 14/19 fsck: Allow upgrading fsck warnings to errors
In reply to Johannes SchindelinThe 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalid-tag-name and missing-tagger-entry in the receive.fsck.severity config setting.
Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).
--- fsck.c | 24 +++++++++++++++++------- t/t5302-pack-index.sh | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
@@ -10,6 +10,7 @@#include "utf8.h" #define FSCK_FATAL -1 +#define FSCK_INFO -2#define FOREACH_MSG_ID (FUNC ) \/* fatal errors */ \
@@ -55,10 +56,11 @@ FUNC(HAS_DOT, WARN) \ FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTGIT, WARN) \ - FUNC(INVALID_TAG_NAME, WARN) \ - FUNC(MISSING_TAGGER_ENTRY, WARN) \ FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) +FUNC (ZERO_PADDED_FILEMODE ,WARN ) \ + /* infos (reported as warnings, but ignored by default) */ \ + FUNC(INVALID_TAG_NAME, INFO) \ + FUNC(MISSING_TAGGER_ENTRY, INFO)#define MSG_ID (id, severity) FSCK_MSG_##id,enum fsck_msg_id {
@@ -206,6 +208,8 @@ static int report(struct fsck_options *options, struct object *object,if (msg_severity ==FSCK_FATAL ) msg_severity =FSCK_ERROR ; +else if (msg_severity ==FSCK_INFO ) + msg_severity =FSCK_WARN ;append_msg_id (&sb, msg_id_info[id].id_string);
@@ -664,15 +668,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, goto done; }strbuf_addf (&sb,"refs/tags/%.*s" , (int )(eol - buffer), buffer); -if (check_refname_format (sb.buf,0 )) -report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME , +if (check_refname_format (sb.buf,0 )) { + ret =report (options, &tag->object,FSCK_MSG_INVALID_TAG_NAME ,"invalid 'tag' name: %.*s" , (int )(eol - buffer), buffer); +if (ret) + goto done; + } buffer = eol +1 ; -if (!skip_prefix (buffer,"tagger " , &buffer)) +if (!skip_prefix (buffer,"tagger " , &buffer)) {/* early tags do not contain 'tagger' lines; warn only */ -report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); + ret =report (options, &tag->object,FSCK_MSG_MISSING_TAGGER_ENTRY ,"invalid format - expected 'tagger' line" ); +if (ret) + goto done; + }else ret =fsck_ident (&buffer, &tag->object, options);
t/t5302-pack-index.sh +1 -1
@@ -259,7 +259,7 @@ EOF thirtyeight=${tag#??} && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^error:.* expected .tagger. line" err + grep "^warning:.* expected .tagger. line" err ' test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 15/19 fsck: Document the new receive.fsck.severity options.
In reply to Johannes Schindelin--- Documentation/config.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Documentation/config.txt +15 -0
@@ -2130,6 +2130,21 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. +receive.fsck.severity:: + When `receive.fsckObjects` is set to true, errors can be switched + to warnings and vice versa by configuring the `receive.fsck.severity` + setting. These settings contain comma-separated lists of the form + `<id>=<level>` where the `<id>` is the fsck message ID and the level + is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes + the error/warning with the message ID, e.g. "missing-email: invalid + author/committer line - missing email" means that setting + `receive.fsck.severity = missing-email=ignore` will hide that issue. ++ +This feature is intended to support working with legacy repositories +which would not pass pushing when `receive.fsckObjects = true`, allowing +the host to accept repositories with certain known issues but still catch +other issues. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 16/19 fsck: Support demoting errors to warnings
In reply to Johannes SchindelinWe already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.
Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.
Example: git -c fsck.severity=missing-email=ignore fsck would hide problems with missing emails in author, committer and tagger lines.
In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.severity from the receive.fsck.severity settings.
--- Documentation/config.txt | 12 ++++++++++++ builtin/fsck.c | 12 ++++++++++++ t/t1450-fsck.sh | 11 +++++++++++ 3 files changed, 35 insertions(+)
Documentation/config.txt +12 -0
@@ -1208,6 +1208,18 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. +fsck.severity:: + A comma-separated lists of of the form `<id>=<level>` where `<id>` + denotes a fsck message ID such as `missing-email` and `<level>` is + one of `error`, `warn` and `ignore`. ++ +For convenience, fsck prefixes the error/warning with the message ID, +e.g. "missing-email: invalid author/committer line - missing email" means +that setting `fsck.severity = missing-email=ignore` will hide that issue. ++ +This feature is intended to support working with legacy repositories +which cannot be repaired without disruptive changes. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +12 -0
@@ -46,6 +46,16 @@ static int show_dangling = 1;#define DIRENT_SORT_HINT (de) ((de)->d_ino)#endif +static int fsck_config (const char *var,const char *value,void *cb) +{ +if (strcmp (var,"fsck.severity" ) ==0 ) { +fsck_set_severity (&fsck_obj_options, value); +return 0 ; + } + +return git_default_config (var, value, cb); +} +static void objreport (struct object *obj,const char *severity,const char *err) {
@@ -638,6 +648,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) include_reflogs =0 ; } +git_config (fsck_config,NULL ); +fsck_head_link ();fsck_object_dir (get_object_directory ());
t/t1450-fsck.sh +11 -0
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' ' grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out ' +test_expect_success 'force fsck to ignore double author' ' + git cat-file commit HEAD >basis && + sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && + new=$(git hash-object -t commit -w --stdin <multiple-authors) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + test_must_fail git fsck && + git -c fsck.severity=multiple-authors=ignore fsck +' + _bz='\0' _bz5="$_bz$_bz$_bz$_bz$_bz" _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 17/19 fsck: Introduce `git fsck --quick`
In reply to Johannes SchindelinThis option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.
--- Documentation/git-fsck.txt | 7 ++++++- builtin/fsck.c | 7 ++++++- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found] [--[no-]dangling] [--[no-]progress] [<object>*] DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs object pools. This is now default; you can turn it off with --no-full. +--quick:: + Check only the connectivity of tags, commits and tree objects. By + avoiding to unpack blobs, this speeds up the operation, at the + expense of missing corrupt objects. + --strict:: Enable more strict checking, namely to catch a file mode recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
@@ -23,6 +23,7 @@ static int show_tags;static int show_unreachable;static int include_reflogs =1 ;static int check_full =1 ; +static int quick;static int check_strict;static int keep_cache_objects;static struct fsck_options fsck_walk_options =FSCK_OPTIONS_DEFAULT ;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)if (!(obj->flags &HAS_OBJ )) {if (has_sha1_pack (obj->sha1))return ;/* it is in pack - forget about it */ +if (quick &&has_sha1_file (obj->sha1)) +return ;printf ("missing %s %s\n" ,typename (obj->type),sha1_to_hex (obj->sha1)); errors_found |=ERROR_REACHABLE ;return ;
@@ -615,6 +618,7 @@ static struct option fsck_opts[] = {OPT_BOOL (0 ,"cache" , &keep_cache_objects,N_ ("make index objects head nodes" )),OPT_BOOL (0 ,"reflogs" , &include_reflogs,N_ ("make reflogs head nodes (default)" )),OPT_BOOL (0 ,"full" , &check_full,N_ ("also consider packs and alternate objects" )), +OPT_BOOL (0 ,"quick" , &quick,N_ ("check only connectivity" )),OPT_BOOL (0 ,"strict" , &check_strict,N_ ("enable more strict checking" )),OPT_BOOL (0 ,"lost-found" , &write_lost_and_found, N_("write dangling objects in .git/lost-found")),
@@ -651,7 +655,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)git_config (fsck_config,NULL );fsck_head_link (); -fsck_object_dir (get_object_directory ()); +if (!quick) +fsck_object_dir (get_object_directory ());prepare_alt_odb ();for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' ' test_must_fail git -C missing fsck ' +test_expect_success 'fsck --quick' ' + rm -rf quick && + git init quick && + ( + cd quick && + touch empty && + git add empty && + test_commit empty && + empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 && + rm -f $empty && + echo invalid >$empty && + test_must_fail git fsck --strict && + git fsck --strict --quick && + tree=$(git rev-parse HEAD:) && + suffix=${tree#??} && + tree=.git/objects/${tree%$suffix}/$suffix && + rm -f $tree && + echo invalid >$tree && + test_must_fail git fsck --strict --quick + ) +' + test_done
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 18/19 fsck: git receive-pack: support excluding objects from fsck'ing
In reply to Johannes SchindelinThe optional new config option receive.fsck.skiplist specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.
--- Documentation/config.txt | 7 ++++++ builtin/receive-pack.c | 8 ++++++ fsck.c | 54 +++++++++++++++++++++++++++++++++++++++++ fsck.h | 1 + t/t5504-fetch-receive-strict.sh | 12 +++++++++ 5 files changed, 82 insertions(+)
Documentation/config.txt +7 -0
@@ -2157,6 +2157,13 @@ which would not pass pushing when `receive.fsckObjects = true`, allowing the host to accept repositories with certain known issues but still catch other issues. +receive.fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + receive.unpackLimit:: If the number of objects received in a push is below this limit then the objects will be unpacked into loose object
builtin/receive-pack.c +8 -0
@@ -122,6 +122,14 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +strbuf_addf (&fsck_severity,"%cskiplist=%s" , + fsck_severity.len ?',' :'=' , path); +return 0 ; + } +if (strcmp (var,"receive.fsckobjects" ) ==0 ) { receive_fsck_objects =git_config_bool (var, value);return 0 ;
fsck.c +54 -0
78 lines not on this page · raw message
fsck.h +1 -0
@@ -29,6 +29,7 @@ struct fsck_options {fsck_error error_func; unsigned strict:1;int *msg_severity; +struct sha1_array *skiplist; };#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000 This commit object intentionally broken EOF +test_expect_success 'push with receive.fsck.skiplist' ' + commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + git push . $commit:refs/heads/bogus && + rm -rf dst && + git init dst && + git --git-dir=dst/.git config receive.fsckobjects true && + test_must_fail git push --porcelain dst bogus && + git --git-dir=dst/.git config receive.fsck.skiplist SKIP && + echo $commit > dst/.git/SKIP && + git push --porcelain dst bogus +' + test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.2.0.33.gc18b867
PATCH v4 19/19 fsck: support ignoring objects in `git fsck` via fsck.skiplist
In reply to Johannes SchindelinIdentical to support in git receive-pack for the config option receive.fsck.skiplist, we now support ignoring given objects in git fsck via fsck.skiplist` altogether.
This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).
--- Documentation/config.txt | 7 +++++++ builtin/fsck.c | 10 ++++++++++ 2 files changed, 17 insertions(+)
Documentation/config.txt +7 -0
@@ -1220,6 +1220,13 @@ that setting `fsck.severity = missing-email=ignore` will hide that issue. This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes. +fsck.skipList:: + The path to a sorted list of object names (i.e. one SHA-1 per + line) that are known to be broken in a non-fatal way and should + be ignored. This feature is useful when an established project + should be accepted despite early commits containing errors that + can be safely ignored such as invalid committer email addresses. + gc.aggressiveDepth:: The depth parameter used in the delta compression algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c +10 -0
@@ -54,6 +54,16 @@ static int fsck_config(const char *var, const char *value, void *cb)return 0 ; } +if (strcmp (var,"fsck.skiplist" ) ==0 ) { +const char *path =is_absolute_path (value) ? + value :git_path ("%s" , value); +struct strbuf sb =STRBUF_INIT ; +strbuf_addf (&sb,"skiplist=%s" , path); +fsck_set_severity (&fsck_obj_options, sb.buf); +strbuf_release (&sb); +return 0 ; + } +return git_default_config (var, value, cb); }
Signature · 1 line
2.2.0.33.gc18b867
Quoted 14 lines · Johannes Schindelin
Quoted 13 lines · Michael Haggerty
Quoted 12 lines · Johannes Schindelin
Hi all (in particular Junio),
Quoted 3 lines · Johannes Schindelin
[...] switch to fsck.severity to address Michael's concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially;
Having participated in the CodingStyle thread, I came to the conclusion that the fsck.severity solution favors syntax over intuitiveness.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Therefore, I would like to support the case for
fsck.level.missingAuthor(note that there is an extra ".level." in contrast to earlier suggestions).Why "level"?
"Severity level", or "error level". Maybe ".severity." would be better?
Sorry, I should have been clearer. I understand why the word "level" makes sense, as opposed to, say, "peanut-butter". What I don't understand is why a middle word is needed at all. In the config file it will look like
[fsck "level"]
missingAuthor = error
, which looks funny. "level" is a constant, so it seems superfluous.
If anything, it might be more useful to allow an optional middle word to allow the strictness level to be adjusted based on which command encounters the problem. For example, if you want to tolerate existing commits that have missing authors, but not allow any new ones to be pushed, you could set
[strictness]
missingAuthor = ignore
[strictness "receive-pack"]
missingAuthor = error
(There's probably a better word than "strictness", but you get the idea.)
Quoted 40 lines
Quoted 40 lines
Quoted 23 lines
The benefits:
- it is very, very easy to understand
- cumulative settings are intuitively cumulative, i.e. setting
fsck.level.missingAuthorwill leavefsck.level.invalidEmailcompletely unaffected- it is very easy to enquire and set the levels via existing
git configcallsNow, there is one downside, but *only* if we ignore Postel's law.
Postel's law ("be lenient in what you accept as input, but strict in your output") would dictate that our message ID parser accept both "missing-author" and "missingAuthor" if we follow the inconsistent practice of using lowercase-dashed keys on the command-line but CamelCased ones in the config.
However, earlier Junio made very clear that the parser is required to fail to parse "missing-author" in the config, and to fail to parse "missingAuthor" on the command-line.
Quoted 6 lines
Therefore, the design I recommend above will require two, minimally different parsers for essentially the same thing.
IMHO this is a downside that is by far outweighed by the ease of use of the new feature, therefore I am willing to bear the burden of implementation.
I again encourage you to consider skipping the implementation of command-line options entirely. It's not like users are going to want to use different options for different invocations. Let them use
git -c fsck.level.missingAuthor=ignore fsck
if they really want to play around, then
git config fsck.level.missingAuthor ignore
Quoted 8 lines
Quoted 2 lines
to make it permanent. After that they will never have to worry about that option again.
Unfortunately, I have to pass the
receive.fsck.*settings fromgit-receive-packtogit-unpack-objectsorgit-index-packvia the command-line, because it isgit-receive-packthat consumes the config setting, but it is one ofgit-unpack-objectsandgit-index-packthat has to act on it...
Wouldn't that work automatically via the GIT_CONFIG_PARAMETERS mechanism? If I run
git -c foo.bar=baz $CMD
, then git-$CMD is invoked with GIT_CONFIG_PARAMETERS set to "'foo.bar=baz'", which causes child processes to treat that value as a configuration setting. I don't have a lot of experience with this but I think it should do what you need.
Michael
Signature · 2 lines
Michael Haggerty [email protected]
Hi Michael,
Quoted 39 lines · Michael Haggerty
Quoted 14 lines · Johannes Schindelin
Quoted 13 lines · Michael Haggerty
Quoted 12 lines · Johannes Schindelin
Hi all (in particular Junio),
Quoted 3 lines · Johannes Schindelin
[...] switch to fsck.severity to address Michael's concerns that letting fsck.(error|warn|ignore)'s comma-separated lists possibly overriding each other partially;
Having participated in the CodingStyle thread, I came to the conclusion that the fsck.severity solution favors syntax over intuitiveness.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Therefore, I would like to support the case for
fsck.level.missingAuthor(note that there is an extra ".level." in contrast to earlier suggestions).Why "level"?
"Severity level", or "error level". Maybe ".severity." would be better?
Sorry, I should have been clearer. I understand why the word "level" makes sense, as opposed to, say, "peanut-butter". What I don't understand is why a middle word is needed at all. In the config file it will look like
[fsck "level"]
missingAuthor = error, which looks funny. "level" is a constant, so it seems superfluous.
If anything, it might be more useful to allow an optional middle word to allow the strictness level to be adjusted based on which command encounters the problem. For example, if you want to tolerate existing commits that have missing authors, but not allow any new ones to be pushed, you could set
Quoted 6 lines
[strictness]
missingAuthor = ignore
[strictness "receive-pack"]
missingAuthor = error(There's probably a better word than "strictness", but you get the idea.)
Ah. Well, the idea of the middle constant is to separate the severity levels from all other fsck (or receive.fsck) settings. The 'fsck.skiplist' setting that I introduce in this patch series, for example, looks pretty much the same as 'fsck.missingauthor', but they have different roles.
This becomes important when I want to catch obvious problems such as 'fsck.missingautor': if I have an extra '.level', I can be certain that it is a typo rather than a config setting unrelated to the severity levels.
Quoted 52 lines
Quoted 40 lines
Quoted 40 lines
Quoted 23 lines
The benefits:
- it is very, very easy to understand
- cumulative settings are intuitively cumulative, i.e. setting
fsck.level.missingAuthorwill leavefsck.level.invalidEmailcompletely unaffected- it is very easy to enquire and set the levels via existing
git configcallsNow, there is one downside, but *only* if we ignore Postel's law.
Postel's law ("be lenient in what you accept as input, but strict in your output") would dictate that our message ID parser accept both "missing-author" and "missingAuthor" if we follow the inconsistent practice of using lowercase-dashed keys on the command-line but CamelCased ones in the config.
However, earlier Junio made very clear that the parser is required to fail to parse "missing-author" in the config, and to fail to parse "missingAuthor" on the command-line.
Quoted 6 lines
Therefore, the design I recommend above will require two, minimally different parsers for essentially the same thing.
IMHO this is a downside that is by far outweighed by the ease of use of the new feature, therefore I am willing to bear the burden of implementation.
I again encourage you to consider skipping the implementation of command-line options entirely. It's not like users are going to want to use different options for different invocations. Let them use
git -c fsck.level.missingAuthor=ignore fsck
if they really want to play around, then
git config fsck.level.missingAuthor ignore
Quoted 8 lines
Quoted 2 lines
to make it permanent. After that they will never have to worry about that option again.
Unfortunately, I have to pass the
receive.fsck.*settings fromgit-receive-packtogit-unpack-objectsorgit-index-packvia the command-line, because it isgit-receive-packthat consumes the config setting, but it is one ofgit-unpack-objectsandgit-index-packthat has to act on it...Wouldn't that work automatically via the
GIT_CONFIG_PARAMETERSmechanism? If I run
Quoted 6 lines
git -c foo.bar=baz $CMD
, then git-$CMD is invoked with
GIT_CONFIG_PARAMETERSset to "'foo.bar=baz'", which causes child processes to treat that value as a configuration setting. I don't have a lot of experience with this but I think it should do what you need.
This is true, but please remember that the receive.fsck.* settings should be heeded by index-pack/unpack-objects *only* if one of the latter programs is called by receive-pack. It would therefore be a little funny (or wrong, depending on your point of view) if, say, index-pack would respect the receive.fsck.* settings.
That is why receive-pack adds a --strict command-line option when receive.fsckobjects is set to true instead of letting index-pack (or unpack-objects) look at the config variable receive.fsckobjects itself.
In the same spirit, I extend the --strict command-line option with an optional list of severity level overrides (e.g. --strict=missing-author=ignore,...) if receive-pack was configured to override those levels.
Now, as this optional argument is intended for internal use only, we could declare that it is okay to pass CamelCased stuff there, even if it disagrees with our command-line option conventions. If it is not okay, I will have to write a rewriter that consumes the CamelCased config settings and rewrites them as lowercase-dashed settings, to be passed to index-pack or unpack-objects, which in turn parses the lowercase-dashed settings.
It might be seen as unnecessarily complicated, which is why I argued in favor of letting the parser accept both forms (which incidentally would heed Postel's law, too). But I understand if Junio does not want that, because it technically violates the conventions he wants to see established. I just need a definitive statement which way to go so I can implement it.
Ciao,
Dscho
Quoted 4 lines · Johannes Schindelin
Quoted 4 lines
[fsck "level"]
missingAuthor = error, which looks funny. "level" is a constant, so it seems superfluous.
Yes, it is superfluous, but is one way to avoid the ambiguity with "skiplist". Structuring it like this would not be so bad, either, though.
[fsck]
error = missingAuthor[, other kinds of errors...]A small set like {ignore, warn, error} is easily maintainable not to conflict with "skiplist" and others.
So that "avoid ambiguity with skiplist" does not favor either choice in any significant way.
Quoted 4 lines
This becomes important when I want to catch obvious problems such as fsck.missingautor': if I have an extra '.level', I can be certain that it is a typo rather than a config setting unrelated to the severity levels.
"[fsck] error = missingAutor" would let you catch the typo in a similar way with the same context clue, so this does not decide which is better, either.
One clear benefit I can see in it is that you can do
git config fsck.level.missingAuthor
in scripts that wants to learn the current setting for a single variable. With "fsck.error=missingAuthor[,other kinds]", you would instead have to do a bit more silly post-processing
git config -l | sed -ne '
/^fsck\./{
# make it "var=,token1,token2,token3,"
s/=/=,/
s/$/,/
s/[ ]*//g
s|^fsck\.\([^=]*\)=.*,missingAuthor,.*|\1|p
}
' | tail -n 1to grab the last fsck.{error,ignore,...}= thing that has the token (I personally do not think the latter is so bad, though).
I wonder if
[fsckError]
missingAuthor = error
missingTagger = warn
wouldn't be a better way, though. We'd keep the easier scripting
git config fsckError.missingTagger
There is nothing that says that the top-level grouping must match the Git subcommand name. Nothing says that one Git subcommand can own at most one namespace, either. Nothing stops us from reserving fsckError top-level namespace for variable name collision avoidance with other fsck.* variables, if that gives us a better system.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Unfortunately, I have to pass the
receive.fsck.*settings fromgit-receive-packtogit-unpack-objectsorgit-index-packvia the command-line, because it isgit-receive-packthat consumes the config setting, but it is one ofgit-unpack-objectsandgit-index-packthat has to act on it...
But receive-pack at some point decides what, if anything, needs to be passed when invoking unpack-objects, or index-pack, no? Why is it hard to pass "-c var=val" at the beginning where it would have passed "--strictness=var=val" at the end?
Quoted 10 lines
Quoted 9 lines
Wouldn't that work automatically via the
GIT_CONFIG_PARAMETERSmechanism? If I rungit -c foo.bar=baz $CMD
, then git-$CMD is invoked with
GIT_CONFIG_PARAMETERSset to "'foo.bar=baz'", which causes child processes to treat that value as a configuration setting. I don't have a lot of experience with this but I think it should do what you need.
Quoted 5 lines
This is true, but please remember that the receive.fsck.* settings should be heeded by index-pack/unpack-objects *only* if one of the latter programs is called by receive-pack. It would therefore be a little funny (or wrong, depending on your point of view) if, say, index-pack would respect the receive.fsck.* settings.
That means it would be fine if receive-pack invokes (when it sees receive.fsck.severity=missingAuthor=error,missingTagger=warn config meant for it and was told with receive.fsckObjects to check the incoming objects) a command line like this:
git -c fsckError.missingAuthor=error \
-c fsckError.missingTagger=warn \
index-pack $args...(or whatever variable names and name structure we settle on). And the index-pack command does not have to even know there are receive.fsck.* variables at all, no?
Another way to do that may be for receive-pack to invoke
git index-pack --use-fsck-severity=receive.fsck $args...
to instruct it to look at receive.fsck.* variables, again when and only when receive-pack wants to do so. I think either way would be fine, as this communication is an internal implementation detail between receive-pack and index-pack and is not meant to be exposed to the end users anyway.
Hi Junio,
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Quoted 4 lines
[fsck "level"]
missingAuthor = error, which looks funny. "level" is a constant, so it seems superfluous.
Yes, it is superfluous, but is one way to avoid the ambiguity with "skiplist". Structuring it like this would not be so bad, either, though.
Quoted 5 lines
[fsck] error = missingAuthor[, other kinds of errors...]A small set like {ignore, warn, error} is easily maintainable not to conflict with "skiplist" and others.
But you augmented the case against the {ignore, warn, error} structure with this yourself:
Quoted 12 lines
With "fsck.error=missingAuthor[,other kinds]", you would instead have to do a bit more silly post-processing
git config -l | sed -ne ' /^fsck\./{ # make it "var=,token1,token2,token3," s/=/=,/ s/$/,/ s/[ ]*//g s|^fsck\.\([^=]*\)=.*,missingAuthor,.*|\1|p } ' | tail -n 1
If a script to determine the current state of affairs is already convoluted, how complicated would it be for users of this feature? No, let's go with Michael's suggestion and have a much more elegant (read: easy to grasp) configuration.
I see that the extra ".level." is universally frowned on, and therefore am convinced that it would be bad to add it.
As to the conflict with "skiplist", by your own argument ("small set ... is easily maintainable") it is not a problem at all.
Quoted 8 lines
Quoted 4 lines
This becomes important when I want to catch obvious problems such as fsck.missingautor': if I have an extra '.level', I can be certain that it is a typo rather than a config setting unrelated to the severity levels.
"[fsck] error = missingAutor" would let you catch the typo in a similar way with the same context clue, so this does not decide which is better, either.
No, you are correct, this does not decide it. What decides it that fsck.missingAuthor = error is better than fsck.error = missingAuthor is that the user does not need to wrap her head around the significance of the order of mutually overriding error, warn and ignore settings in the former.
As to the typo handling, you are absolutely correct that it is easy to handle "skiplist" first and then expect all other fsck.* settings (or receive.fsck.* settings) to match a message ID. To make things even smoother, I think it would make most sense to only *warn* about typos instead of *erroring out*.
Quoted 5 lines
I wonder if
[fsckError]
missingAuthor = error
missingTagger = warn
Hmm. I am not so sure that fsckError is the correct term. After all, we can also upgrade warnings to errors, not only demote errors to warnings. So I guess the fsck.* naming scheme is not so bad after all!
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Unfortunately, I have to pass the
receive.fsck.*settings fromgit-receive-packtogit-unpack-objectsorgit-index-packvia the command-line, because it isgit-receive-packthat consumes the config setting, but it is one ofgit-unpack-objectsandgit-index-packthat has to act on it...But receive-pack at some point decides what, if anything, needs to be passed when invoking unpack-objects, or index-pack, no? Why is it hard to pass "-c var=val" at the beginning where it would have passed "--strictness=var=val" at the end?
It is not hard, it is just inelegant: 1) we would have to introduce a new function to handle the config settings in unpack-objects, 2) the command-line would be longer (for what benefit?), and 3) index-pack uses run_command() to launch the children [*1*] and wouldn't you find it super-ugly if that argv started with a "-c", "..."? I would.
We already have command-line handling in both index-pack and unpack-objects (and config handling only in the former), we already have --strict handling in particular, and arguably the severity levels are tightly connected to that --strict option that at least in my opinion it makes sense to understand that the severity levels are optional parameters to that command-line option.
So in short, I maintain that passing the options via the config mechanism would just make things more complicated, and in no way better.
Quoted 21 lines
Quoted 10 lines
Quoted 9 lines
Wouldn't that work automatically via the
GIT_CONFIG_PARAMETERSmechanism? If I rungit -c foo.bar=baz $CMD
, then git-$CMD is invoked with
GIT_CONFIG_PARAMETERSset to "'foo.bar=baz'", which causes child processes to treat that value as a configuration setting. I don't have a lot of experience with this but I think it should do what you need.Quoted 5 lines
This is true, but please remember that the receive.fsck.* settings should be heeded by index-pack/unpack-objects *only* if one of the latter programs is called by receive-pack. It would therefore be a little funny (or wrong, depending on your point of view) if, say, index-pack would respect the receive.fsck.* settings.
That means it would be fine if receive-pack invokes (when it sees receive.fsck.severity=missingAuthor=error,missingTagger=warn config meant for it and was told with receive.fsckObjects to check the incoming objects) a command line like this:
Quoted 7 lines
git -c fsckError.missingAuthor=error \ -c fsckError.missingTagger=warn \ index-pack $args...(or whatever variable names and name structure we settle on). And the index-pack command does not have to even know there are receive.fsck.* variables at all, no?
It does not know that at all already, so yes: I agree. It does not even need to know that those settings were config variables. Even better: it should not let config settings interfere with the settings receive-pack wants index-pack to use.
So there you have it, another reason why passing the levels via command-line options is conceptually much more sound than passing them via fake config settings.
Quoted 1 line
I think either way would be fine, as this communication is an internal implementation detail between receive-pack and index-pack and is not meant to be exposed to the end users anyway.
Yeah, I think we really used enough time to discuss something as unimportant as this detail.
Just to make sure: are you okay with passing CamelCased settings (e.g. --strict=missingAuthor=warn,...) as part of that internal communication between receive-pack and index-pack/unpack-objects? That is my preference by now.
Ciao,
Dscho
Footnote *1*: https://github.com/msysgit/git/blob/c47d6ec67188cec2a782bc245aa7df4e3cbdbc01/builtin/receive-pack.c#L992-L1001
v5 cover Introduce an internal API to interact with the fsck machinery
In reply to Johannes SchindelinAt the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.
Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.
This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.
I am proud to report that this work has been sponsored by GitHub.
Changes since v4 (sorry for the long delay):
- the config settings' convention changed as discussed. Example:
fsck.severity.warn = missing-author is now fsck.missingAuthor = warn (or fsck.missingauthor = warn because config settings are traditionally case-insensitive). As a consequence, the command-line parameter passed on to index-pack and unpack-objects also uses camelCased values.
- previously, we errored out when encountering an unknown message id, now we warn instead.
- I now use msg_type consistently where I used severity before because it appears clearer to me
- the skiplist handling is now done only in the error case, for enhanced performance. While at it, a potential segmentation fault was fixed when a NULL object was dereferenced to be looked up in the skiplist.
Interdiff below the diffstat. It's huge. Sorry.
Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings fsck (receive-pack): Allow demoting errors to warnings
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.<msg-id>
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.<msg-id> options
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --quick
fsck: git receive-pack: support excluding objects from fsck'ing
fsck: support ignoring objects in git fsck via fsck.skiplist
Documentation/config.txt | 39 +++ Documentation/git-fsck.txt | 7 +- builtin/fsck.c | 75 ++++-- builtin/index-pack.c | 13 +- builtin/receive-pack.c | 25 +- builtin/unpack-objects.c | 16 +- fsck.c | 553 +++++++++++++++++++++++++++++++--------- fsck.h | 31 ++- t/t1450-fsck.sh | 37 ++- t/t5302-pack-index.sh | 2 +- t/t5504-fetch-receive-strict.sh | 51 ++++ 11 files changed, 686 insertions(+), 163 deletions(-)
Documentation/config.txt +10 -12
@@ -1250,14 +1250,13 @@ filter.<driver>.smudge:: object to a worktree file upon checkout. See linkgit:gitattributes[5] for details. -fsck.severity:: - A comma-separated lists of of the form `<id>=<level>` where `<id>` - denotes a fsck message ID such as `missing-email` and `<level>` is - one of `error`, `warn` and `ignore`. +fsck.<msg-id>:: + Allows overriding the message type (error, warn or ignore) of a + specific message ID such as `missingemail`. + For convenience, fsck prefixes the error/warning with the message ID, -e.g. "missing-email: invalid author/committer line - missing email" means -that setting `fsck.severity = missing-email=ignore` will hide that issue. +e.g. "missingemail: invalid author/committer line - missing email" means +that setting `fsck.missingemail = ignore` will hide that issue. + This feature is intended to support working with legacy repositories which cannot be repaired without disruptive changes.
@@ -2224,15 +2223,14 @@ receive.fsckObjects:: Defaults to false. If not set, the value of `transfer.fsckObjects` is used instead. -receive.fsck.severity:: +receive.fsck.<msg-id>:: When `receive.fsckObjects` is set to true, errors can be switched - to warnings and vice versa by configuring the `receive.fsck.severity` - setting. These settings contain comma-separated lists of the form - `<id>=<level>` where the `<id>` is the fsck message ID and the level + to warnings and vice versa by configuring the `receive.fsck.<msg-id>` + setting where the `<msg-id>` is the fsck message ID and the value is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes - the error/warning with the message ID, e.g. "missing-email: invalid + the error/warning with the message ID, e.g. "missingemail: invalid author/committer line - missing email" means that setting - `receive.fsck.severity = missing-email=ignore` will hide that issue. + `receive.fsck.missingemail = ignore` will hide that issue. + This feature is intended to support working with legacy repositories which would not pass pushing when `receive.fsckObjects = true`, allowing
builtin/fsck.c +6 -6
@@ -49,8 +49,8 @@ static int show_dangling = 1;static int fsck_config (const char *var,const char *value,void *cb) { -if (strcmp (var,"fsck.severity" ) ==0 ) { -fsck_set_severity (&fsck_obj_options, value); +if (skip_prefix (var,"fsck." , &var)) { +fsck_set_msg_type (&fsck_obj_options, var,-1 , value,-1 );return 0 ; }
@@ -59,7 +59,7 @@ static int fsck_config(const char *var, const char *value, void *cb) value :git_path ("%s" , value);struct strbuf sb =STRBUF_INIT ;strbuf_addf (&sb,"skiplist=%s" , path); -fsck_set_severity (&fsck_obj_options, sb.buf); +fsck_set_msg_types (&fsck_obj_options, sb.buf);strbuf_release (&sb);return 0 ; }
@@ -67,11 +67,11 @@ static int fsck_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } -static void objreport (struct object *obj,const char *severity, -const char *err) +static void objreport (struct object *obj,const char *msg_type, +const char *err) {fprintf (stderr,"%s in %s %s: %s\n" , - severity,typename (obj->type),sha1_to_hex (obj->sha1), err); + msg_type,typename (obj->type),sha1_to_hex (obj->sha1), err); }static int objerror (struct object *obj,const char *err)
builtin/index-pack.c +1 -1
@@ -1636,7 +1636,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) }else if (skip_prefix (arg,"--strict=" , &arg)) { strict =1 ; do_fsck_object =1 ; -fsck_set_severity (&fsck_options, arg); +fsck_set_msg_types (&fsck_options, arg); }else if (!strcmp (arg,"--check-self-contained-and-connected" )) { strict =1 ; check_self_contained_and_connected =1 ;
builtin/receive-pack.c +15 -11
@@ -19,6 +19,7 @@#include "tag.h" #include "gpg-interface.h" #include "sigchain.h" +#include "fsck.h" static const char receive_pack_usage[] ="git receive-pack <git-dir>" ;
@@ -36,7 +37,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;static enum deny_action deny_delete_current =DENY_UNCONFIGURED ;static int receive_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ; -static struct strbuf fsck_severity =STRBUF_INIT ; +static struct strbuf fsck_msg_types =STRBUF_INIT ;static int receive_unpack_limit =-1 ;static int transfer_unpack_limit =-1 ;static int advertise_atomic_push =1 ;
@@ -116,17 +117,20 @@ static int receive_pack_config(const char *var, const char *value, void *cb)return 0 ; } -if (strcmp (var,"receive.fsck.severity" ) ==0 ) { -strbuf_addf (&fsck_severity,"%c%s" , - fsck_severity.len ?',' :'=' , value); -return 0 ; - } -if (strcmp (var,"receive.fsck.skiplist" ) ==0 ) {const char *path =is_absolute_path (value) ? value :git_path ("%s" , value); -strbuf_addf (&fsck_severity,"%cskiplist=%s" , - fsck_severity.len ?',' :'=' , path); +strbuf_addf (&fsck_msg_types,"%cskiplist=%s" , + fsck_msg_types.len ?',' :'=' , path); +return 0 ; + } + +if (skip_prefix (var,"receive.fsck." , &var)) { +if (is_valid_msg_type (var, value)) +strbuf_addf (&fsck_msg_types,"%c%s=%s" , + fsck_msg_types.len ?',' :'=' , var, value); +else +warning ("Skipping unknown msg id '%s'" , var);return 0 ; }
@@ -1506,7 +1510,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)argv_array_push (&child.args,"-q" );if (fsck_objects)argv_array_pushf (&child.args,"--strict%s" , - fsck_severity.buf); + fsck_msg_types.buf); child.no_stdout =1 ; child.err = err_fd; child.git_cmd =1 ;
@@ -1525,7 +1529,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) "--stdin", hdr_arg, keep_arg, NULL);if (fsck_objects)argv_array_pushf (&child.args,"--strict%s" , - fsck_severity.buf); + fsck_msg_types.buf);if (fix_thin)argv_array_push (&child.args,"--fix-thin" ); child.out =-1 ;
builtin/unpack-objects.c +1 -1
@@ -532,7 +532,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) }if (skip_prefix (arg,"--strict=" , &arg)) { strict =1 ; -fsck_set_severity (&fsck_options, arg); +fsck_set_msg_types (&fsck_options, arg);continue ; }if (starts_with (arg,"--pack_header=" )) {
fsck.c +89 -68
262 lines not on this page · raw message
fsck.h +6 -2
@@ -7,7 +7,11 @@struct fsck_options ; -void fsck_set_severity (struct fsck_options *options,const char *mode); +void fsck_set_msg_type (struct fsck_options *options, +const char *msg_id,int msg_id_len, +const char *msg_type,int msg_type_len); +void fsck_set_msg_types (struct fsck_options *options,const char *values); +int is_valid_msg_type (const char *msg_id,const char *msg_type);/* * callback function for fsck_walk
@@ -28,7 +32,7 @@ struct fsck_options {fsck_walk_func walk;fsck_error error_func; unsigned strict:1; -int *msg_severity; +int *msg_type;struct sha1_array *skiplist; };
t/t1450-fsck.sh +3 -3
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' git fsck --tags 2>out && cat >expect <<-EOF && - warning in tag $tag: invalid-tag-name: invalid '\''tag'\'' name: wrong name format - warning in tag $tag: missing-tagger-entry: invalid format - expected '\''tagger'\'' line + warning in tag $tag: invalidtagname: invalid '\''tag'\'' name: wrong name format + warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line EOF test_cmp expect out '
@@ -295,7 +295,7 @@ test_expect_success 'force fsck to ignore double author' ' git update-ref refs/heads/bogus "$new" && test_when_finished "git update-ref -d refs/heads/bogus" && test_must_fail git fsck && - git -c fsck.severity=multiple-authors=ignore fsck + git -c fsck.multipleauthors=ignore fsck ' _bz='\0'
t/t5504-fetch-receive-strict.sh +13 -11
@@ -124,44 +124,46 @@ This commit object intentionally broken EOF test_expect_success 'push with receive.fsck.skiplist' ' - commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && + commit="$(git hash-object -t commit -w --stdin <bogus-commit)" && git push . $commit:refs/heads/bogus && rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config receive.fsck.skiplist SKIP && - echo $commit > dst/.git/SKIP && + echo $commit >dst/.git/SKIP && git push --porcelain dst bogus ' -test_expect_success 'push with receive.fsck.severity = missing-email=warn' ' - commit="$(git hash-object -t commit -w --stdin < bogus-commit)" && +test_expect_success 'push with receive.fsck.missingemail=warn' ' + commit="$(git hash-object -t commit -w --stdin <bogus-commit)" && git push . $commit:refs/heads/bogus && rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config \ - receive.fsck.severity missing-email=warn && + receive.fsck.missingemail warn && git push --porcelain dst bogus >act 2>&1 && - grep "missing-email" act && + grep "missingemail" act && git --git-dir=dst/.git branch -D bogus && git --git-dir=dst/.git config --add \ - receive.fsck.severity missing-email=ignore,bad-date=warn && + receive.fsck.missingemail ignore && + git --git-dir=dst/.git config --add \ + receive.fsck.baddate warn && git push --porcelain dst bogus >act 2>&1 && - test_must_fail grep "missing-email" act + test_must_fail grep "missingemail" act ' test_expect_success \ - 'receive.fsck.severity = unterminated-header=warn triggers error' ' + 'receive.fsck.unterminatedheader=warn triggers error' ' rm -rf dst && git init dst && git --git-dir=dst/.git config receive.fsckobjects true && git --git-dir=dst/.git config \ - receive.fsck.severity unterminated-header=warn && + receive.fsck.unterminatedheader warn && test_must_fail git push --porcelain dst HEAD >act 2>&1 && - grep "Cannot demote unterminated-header" act + grep "Cannot demote unterminatedheader" act ' test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4