* Re: [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen')
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
@ 2021-02-18 22:19 ` Junio C Hamano
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (22 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-02-18 22:19 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> As suggested in
> https://lore.kernel.org/git/87zh028ctp.fsf@evledraar.gmail.com/ a
> version of this that doesn't conflict with other in-flight topics. I
> can submit the rest later.
And a bystander does not have a clue what this thing is about,
beyond that it tweaks fsck API, how urgent it would be, what benefit
it brings to us?
That kind of things are expected to be described here.
The cover letter of v1 does not do much better job, either, but is
it fair to understand that this primarily is about allowing the
callback functions (which handle various problems fsck machinery
finds) to learn what error it encountered, so that things like
"enumerate missing .gitmodules blobs" 384c9d1c (fetch-pack: print
and use dangling .gitmodules, 2021-01-23) wants to do does not have
to be written by inserting a very narrow custom code into the
general error reporting codepath, but by customizing the error
reporting function?
If so, can we at least say something a bit more specific and
focused, than the overly broad "API improvements"?
THanks.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v3 00/22] fsck: API improvements
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
2021-02-18 22:19 ` Junio C Hamano
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-07 23:04 ` Junio C Hamano
` (23 more replies)
2021-03-06 11:04 ` [PATCH v3 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
` (21 subsequent siblings)
23 siblings, 24 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Now that jt/transfer-fsck-across-packs has been merged to master
here's a re-roll of v1[1]+v2[2] of this series. v2 was slimmed-down +
had a trivial typo fix, so I've done the range-diff against v1.
This makes the recent fetch-pack work use the fsck_msg_id API to
distinguish messages, and has other various cleanups and improvements
to make the fsck API easier to use in the future.
There's a an easy merge conflict here with other in-flight changes to
fsck. I figured it was better to send this now than wait for those to
land.
1. https://lore.kernel.org/git/20210217194246.25342-1-avarab@gmail.com/
2. https://lore.kernel.org/git/20210218105840.11989-1-avarab@gmail.com/
Ævar Arnfjörð Bjarmason (22):
fsck.h: update FSCK_OPTIONS_* for object_name
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
fsck.h: indent arguments to of fsck_set_msg_type
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion
fsck.c: move definition of msg_id into append_msg_id()
fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
fsck.h: re-order and re-assign "enum fsck_msg_type"
fsck.c: call parse_msg_type() early in fsck_set_msg_type()
fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name
fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
fsck.c: pass along the fsck_msg_id in the fsck_error callback
fsck.c: add an fsck_set_msg_type() API that takes enums
fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
Makefile | 1 +
builtin/fsck.c | 7 +-
builtin/index-pack.c | 30 ++-----
builtin/mktag.c | 7 +-
builtin/unpack-objects.c | 3 +-
fetch-pack.c | 6 +-
fsck-cb.c | 16 ++++
fsck.c | 175 ++++++++++++---------------------------
fsck.h | 132 ++++++++++++++++++++++++++---
9 files changed, 211 insertions(+), 166 deletions(-)
create mode 100644 fsck-cb.c
Range-diff:
13: 8de91fac068 = 1: 9d809466bd1 fsck.h: update FSCK_OPTIONS_* for object_name
-: ----------- > 2: 33e8b6d6545 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
-: ----------- > 3: c23f7ce9e4a fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
-: ----------- > 4: 5dde68df6c3 fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
1: 88b347b74ed = 5: 7ae35a6e9d2 fsck.h: indent arguments to of fsck_set_msg_type
2: 1a60d65d2ca ! 6: dfb5f754b37 fsck.h: use use "enum object_type" instead of "int"
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## Commit message ##
- fsck.h: use use "enum object_type" instead of "int"
+ fsck.h: use "enum object_type" instead of "int"
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
3: 24761f269b7 ! 7: fd58ec73c6b fsck.c: rename variables in fsck_set_msg_type() for less confusion
@@ Commit message
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
- Let's rename that to "tmp", and rename "id" to "msg_id" and "msg_id"
- to "msg_id_str" etc. This will make a follow-up change smaller.
+ Let's rename that to "severity", and rename "id" to "msg_id" and
+ "msg_id" to "msg_id_str" etc. This will make a follow-up change
+ smaller.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
-+ int *tmp;
-+ ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
++ int *severity;
++ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
-+ tmp[i] = fsck_msg_type(i, options);
-+ options->msg_type = tmp;
++ severity[i] = fsck_msg_type(i, options);
++ options->msg_type = severity;
}
- options->msg_type[id] = type;
4: fb4c66f9305 = 8: 48cb4d3bb70 fsck.c: move definition of msg_id into append_msg_id()
5: a129dbd9964 ! 9: 2c80ad32038 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
@@ Commit message
"msg_id". This change is relatively small, and is worth the churn for
a later change where we have different id's in the "report" function.
+ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
+
## fsck.c ##
@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
-: ----------- > 10: 92dfbdfb624 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
6: d9bee41072e ! 11: c1c476af69b fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
@@ Commit message
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors,
2015-06-22)
+ The reason these were defined in two different places is because we
+ use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
+ used by external callbacks.
+
+ Untangling that would take some more work, since we expose the new
+ "enum fsck_msg_type" to both. Similar to "enum object_type" it's not
+ worth structuring the API in such a way that only those who need
+ FSCK_{ERROR,WARN} pass around a different type.
+
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## builtin/fsck.c ##
@@ builtin/fsck.c: static int objerror(struct object *obj, const char *err)
switch (msg_type) {
case FSCK_WARN:
+ ## builtin/index-pack.c ##
+@@ builtin/index-pack.c: static void show_pack_info(int stat_only)
+ static int print_dangling_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+- int msg_type, const char *message)
++ enum fsck_msg_type msg_type,
++ const char *message)
+ {
+ /*
+ * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
+
## builtin/mktag.c ##
@@ builtin/mktag.c: static int mktag_config(const char *var, const char *value, void *cb)
static int mktag_fsck_error_func(struct fsck_options *o,
@@ fsck.c: void list_config_fsck_msg_ids(struct string_list *list, const char *pref
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
-- int msg_type;
-+ enum fsck_msg_type msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
+ if (!options->msg_type) {
+- int msg_type = msg_id_info[msg_id].msg_type;
++ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
+
+ if (options->strict && msg_type == FSCK_WARN)
+ msg_type = FSCK_ERROR;
@@ fsck.c: static int fsck_msg_type(enum fsck_msg_id msg_id,
- return msg_type;
+ return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
-- int *tmp;
-+ enum fsck_msg_type *tmp;
- ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
+- int *severity;
++ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- tmp[i] = fsck_msg_type(i, options);
+ severity[i] = fsck_msg_type(i, options);
@@ fsck.c: static int report(struct fsck_options *options,
{
va_list ap;
@@ fsck.h
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
--
+enum fsck_msg_type {
-+ FSCK_INFO = -2,
++ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
+
struct fsck_options;
struct object;
-
@@ fsck.h: typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
-: ----------- > 12: d55587719a5 fsck.h: re-order and re-assign "enum fsck_msg_type"
7: 423568026c3 = 13: 32828d1c78c fsck.c: call parse_msg_type() early in fsck_set_msg_type()
8: cb43e832738 = 14: 5c62066235c fsck.c: undefine temporary STR macro after use
9: 2cd14cb4e2a = 15: f8e50fbf7d3 fsck.c: give "FOREACH_MSG_ID" a more specific name
10: 1ada154ef23 ! 16: cd74dee8769 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
@@ fsck.c
## fsck.h ##
@@ fsck.h: enum fsck_msg_type {
FSCK_WARN,
- FSCK_IGNORE
};
-+
+
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \
11: c4179445f22 ! 17: 234e287d081 fsck.c: pass along the fsck_msg_id in the fsck_error callback
@@ builtin/fsck.c: static int objerror(struct object *obj, const char *err)
switch (msg_type) {
case FSCK_WARN:
+ ## builtin/index-pack.c ##
+@@ builtin/index-pack.c: static int print_dangling_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
++ enum fsck_msg_id msg_id,
+ const char *message)
+ {
+ /*
+@@ builtin/index-pack.c: static int print_dangling_gitmodules(struct fsck_options *o,
+ printf("%s\n", oid_to_hex(oid));
+ return 0;
+ }
+- return fsck_error_function(o, oid, object_type, msg_type, message);
++ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+ }
+
+ int cmd_index_pack(int argc, const char **argv, const char *prefix)
+
## builtin/mktag.c ##
@@ builtin/mktag.c: static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
12: c1fc724f0e8 ! 18: 8049dc07391 fsck.c: add an fsck_set_msg_type() API that takes enums
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
+{
+ if (!options->msg_type) {
+ int i;
-+ enum fsck_msg_type *tmp;
-+ ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
++ enum fsck_msg_type *severity;
++ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
-+ tmp[i] = fsck_msg_type(i, options);
-+ options->msg_type = tmp;
++ severity[i] = fsck_msg_type(i, options);
++ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
- if (!options->msg_type) {
- int i;
-- enum fsck_msg_type *tmp;
-- ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
+- enum fsck_msg_type *severity;
+- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
-- tmp[i] = fsck_msg_type(i, options);
-- options->msg_type = tmp;
+- severity[i] = fsck_msg_type(i, options);
+- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;
14: 29ff97856ff ! 19: 4224a29d15c fsck.c: move gitmodules_{found,done} into fsck_options
@@ Commit message
fsck_options struct. It makes sense to keep all the context in the
same place.
+ This requires changing the recently added register_found_gitmodules()
+ function added in 5476e1efde (fetch-pack: print and use dangling
+ .gitmodules, 2021-02-22) to take fsck_options. That function will be
+ removed in a subsequent commit, but as it'll require the new
+ gitmodules_found attribute of "fsck_options" we need this intermediate
+ step first.
+
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
+ ## fetch-pack.c ##
+@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+
+ oidset_iter_init(gitmodules_oids, &iter);
+ while ((oid = oidset_iter_next(&iter)))
+- register_found_gitmodules(oid);
++ register_found_gitmodules(&fo, oid);
+ if (fsck_finish(&fo))
+ die("fsck failed");
+ }
+
## fsck.c ##
@@
#include "credential.h"
@@ fsck.c: static int fsck_blob(const struct object_id *oid, const char *buf,
if (object_on_skiplist(options, oid))
return 0;
+@@ fsck.c: int fsck_error_function(struct fsck_options *o,
+ return 1;
+ }
+
+-void register_found_gitmodules(const struct object_id *oid)
++void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
+ {
+- oidset_insert(&gitmodules_found, oid);
++ oidset_insert(&options->gitmodules_found, oid);
+ }
+
+ int fsck_finish(struct fsck_options *options)
@@ fsck.c: int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
@@ fsck.h: struct fsck_options {
kh_oid_map_t *object_names;
};
--#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
--#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
-+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL }
-+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL }
+@@ fsck.h: struct fsck_options {
+ .walk = NULL, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
+ .object_names = NULL,
+ #define FSCK_OPTIONS_COMMON_ERROR_FUNC \
+ FSCK_OPTIONS_COMMON \
+@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
+ int fsck_object(struct object *obj, void *data, unsigned long size,
+ struct fsck_options *options);
+
+-void register_found_gitmodules(const struct object_id *oid);
++void register_found_gitmodules(struct fsck_options *options,
++ const struct object_id *oid);
- /* descend in all linked child objects
- * the return value is:
+ /*
+ * fsck a tag, and pass info about it back to the caller. This is
-: ----------- > 20: 40b13468129 fetch-pack: don't needlessly copy fsck_options
-: ----------- > 21: 8e418abfbd7 fetch-pack: use file-scope static struct for fsck_options
-: ----------- > 22: 113de190f7d fetch-pack: use new fsck API to printing dangling submodules
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v3 00/22] fsck: API improvements
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
@ 2021-03-07 23:04 ` Junio C Hamano
2021-03-08 9:16 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (22 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Junio C Hamano @ 2021-03-07 23:04 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Now that jt/transfer-fsck-across-packs has been merged to master
> here's a re-roll of v1[1]+v2[2] of this series.
It unfortunately is not a good time to review or helping any work on
this series, as the base topic introduced an unpleasant regression
and needs to either probably gain a band-aid (or reverted in the
worst case); of course, it would be appreciated to help resolve the
issues on that topic ;-)
Thanks.
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v3 00/22] fsck: API improvements
2021-03-07 23:04 ` Junio C Hamano
@ 2021-03-08 9:16 ` Ævar Arnfjörð Bjarmason
0 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-08 9:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
On Mon, Mar 08 2021, Junio C Hamano wrote:
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> Now that jt/transfer-fsck-across-packs has been merged to master
>> here's a re-roll of v1[1]+v2[2] of this series.
>
> It unfortunately is not a good time to review or helping any work on
> this series, as the base topic introduced an unpleasant regression
> and needs to either probably gain a band-aid (or reverted in the
> worst case); of course, it would be appreciated to help resolve the
> issues on that topic ;-)
I should have mentioned: I saw the bug & proposed fix thread for that.
I see that 2aec3bc4b64 (fetch-pack: do not mix --pack_header and
packfile uri, 2021-03-04) down into next is now merged down to next.
My reading of that thread is that the reported bug is solved, but
perhaps we're not 100% happy with the solution?
In any case, that patch does not conflict with this series, and all
tests pass with/without the two merged together.
I don't forese an issue with the two stepping on each other's toes,
since I'm just modifying the rather low-level fsck interface of spewing
out .gitmodules entries, not touching the logic of what's then done with
that information...
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 00/22] fsck: API improvements
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
2021-03-07 23:04 ` Junio C Hamano
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 19:35 ` Derrick Stolee
` (20 more replies)
2021-03-16 16:17 ` [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
` (21 subsequent siblings)
23 siblings, 21 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
A re-send of a rebased v3, which I sent at:
http://lore.kernel.org/git/20210306110439.27694-1-avarab@gmail.com as
seen in the range-diff there are no changes since v3. I'm just sending
this as a post-release bump of this, per
https://lore.kernel.org/git/xmqqy2etczqi.fsf@gitster.g/
Ævar Arnfjörð Bjarmason (22):
fsck.h: update FSCK_OPTIONS_* for object_name
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
fsck.h: indent arguments to of fsck_set_msg_type
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion
fsck.c: move definition of msg_id into append_msg_id()
fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
fsck.h: re-order and re-assign "enum fsck_msg_type"
fsck.c: call parse_msg_type() early in fsck_set_msg_type()
fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name
fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
fsck.c: pass along the fsck_msg_id in the fsck_error callback
fsck.c: add an fsck_set_msg_type() API that takes enums
fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
Makefile | 1 +
builtin/fsck.c | 7 +-
builtin/index-pack.c | 30 ++-----
builtin/mktag.c | 7 +-
builtin/unpack-objects.c | 3 +-
fetch-pack.c | 6 +-
fsck-cb.c | 16 ++++
fsck.c | 175 ++++++++++++---------------------------
fsck.h | 132 ++++++++++++++++++++++++++---
9 files changed, 211 insertions(+), 166 deletions(-)
create mode 100644 fsck-cb.c
Range-diff:
1: 9d809466bd = 1: 9cd942b526 fsck.h: update FSCK_OPTIONS_* for object_name
2: 33e8b6d654 = 2: d67966b838 fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
3: c23f7ce9e4 = 3: 211472e0c5 fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
4: 5dde68df6c = 4: 70afee988d fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
5: 7ae35a6e9d = 5: 1337d53352 fsck.h: indent arguments to of fsck_set_msg_type
6: dfb5f754b3 = 6: e4ef107bb4 fsck.h: use "enum object_type" instead of "int"
7: fd58ec73c6 = 7: 20bac3207e fsck.c: rename variables in fsck_set_msg_type() for less confusion
8: 48cb4d3bb7 = 8: 09c3bba9e9 fsck.c: move definition of msg_id into append_msg_id()
9: 2c80ad3203 = 9: 8067df53a2 fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
10: 92dfbdfb62 = 10: bdf5e13f3d fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
11: c1c476af69 = 11: b03caa237f fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
12: d55587719a = 12: 7b1d13b4cc fsck.h: re-order and re-assign "enum fsck_msg_type"
13: 32828d1c78 = 13: a8e4ca7b19 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
14: 5c62066235 = 14: 214c375a20 fsck.c: undefine temporary STR macro after use
15: f8e50fbf7d = 15: 19a2499a80 fsck.c: give "FOREACH_MSG_ID" a more specific name
16: cd74dee876 = 16: 6e1a7b6274 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
17: 234e287d08 = 17: 42af4e164c fsck.c: pass along the fsck_msg_id in the fsck_error callback
18: 8049dc0739 = 18: fa47f473a8 fsck.c: add an fsck_set_msg_type() API that takes enums
19: 4224a29d15 = 19: 4cc3880cc4 fsck.c: move gitmodules_{found,done} into fsck_options
20: 40b1346812 = 20: fd219d318a fetch-pack: don't needlessly copy fsck_options
21: 8e418abfbd = 21: e4cd8c250e fetch-pack: use file-scope static struct for fsck_options
22: 113de190f7 = 22: fdbc3c304c fetch-pack: use new fsck API to printing dangling submodules
--
2.31.0.260.g719c683c1d
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 00/22] fsck: API improvements
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
@ 2021-03-16 19:35 ` Derrick Stolee
2021-03-17 18:20 ` [PATCH v5 00/19] " Ævar Arnfjörð Bjarmason
` (19 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Derrick Stolee @ 2021-03-16 19:35 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason, git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
> A re-send of a rebased v3, which I sent at:
> http://lore.kernel.org/git/20210306110439.27694-1-avarab@gmail.com as
> seen in the range-diff there are no changes since v3. I'm just sending
> this as a post-release bump of this, per
> https://lore.kernel.org/git/xmqqy2etczqi.fsf@gitster.g/
>
> Ævar Arnfjörð Bjarmason (22):
> fsck.h: update FSCK_OPTIONS_* for object_name
> fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
> fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
> fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
> fsck.h: indent arguments to of fsck_set_msg_type
> fsck.h: use "enum object_type" instead of "int"
> fsck.c: rename variables in fsck_set_msg_type() for less confusion
> fsck.c: move definition of msg_id into append_msg_id()
> fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
> fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
> fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
> fsck.h: re-order and re-assign "enum fsck_msg_type"
> fsck.c: call parse_msg_type() early in fsck_set_msg_type()
> fsck.c: undefine temporary STR macro after use
> fsck.c: give "FOREACH_MSG_ID" a more specific name
> fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
> fsck.c: pass along the fsck_msg_id in the fsck_error callback
> fsck.c: add an fsck_set_msg_type() API that takes enums
> fsck.c: move gitmodules_{found,done} into fsck_options
> fetch-pack: don't needlessly copy fsck_options
> fetch-pack: use file-scope static struct for fsck_options
> fetch-pack: use new fsck API to printing dangling submodules
This series is carefully organized and motivated. It was quite
easy to read.
My complaints were minor. One was that patches 1-4 seemed to be
unnecessarily granular. I'm not sure that having four patches
like that will be more helpful for inspecting the history in
the future. But, I don't care enough to say this should be
re-rolled.
Finally, the last issue is that fsck-cb.c is loosely justified
with only one method inside. If you have plans in the near
future to add similar methods there, then I think that is fine.
Otherwise, it would be simpler to avoid the extra file and
code move.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v5 00/19] fsck: API improvements
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2021-03-16 19:35 ` Derrick Stolee
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 20:30 ` Derrick Stolee
` (2 more replies)
2021-03-17 18:20 ` [PATCH v5 01/19] fsck.c: refactor and rename common config callback Ævar Arnfjörð Bjarmason
` (18 subsequent siblings)
20 siblings, 3 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
A v5 with changes suggested by Derrick Stolee. Link to v4:
https://lore.kernel.org/git/20210316161738.30254-1-avarab@gmail.com/
Changes:
* 1/19 is new, it's a simple refactoring of some git_config() code in
fsck.c code I changed recently.
* Squashed the first 4x patches of incrementally redefining two
macros into one.
* Squashed a whitespace-only change into another patch that changed
the same code.
* Got rid of fsck-cb.c, that one function just lives at the bottom of
fsck.c now.
Ævar Arnfjörð Bjarmason (19):
fsck.c: refactor and rename common config callback
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion
fsck.c: move definition of msg_id into append_msg_id()
fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
fsck.h: re-order and re-assign "enum fsck_msg_type"
fsck.c: call parse_msg_type() early in fsck_set_msg_type()
fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name
fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
fsck.c: pass along the fsck_msg_id in the fsck_error callback
fsck.c: add an fsck_set_msg_type() API that takes enums
fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
builtin/fsck.c | 14 ++-
builtin/index-pack.c | 30 +-----
builtin/mktag.c | 14 ++-
builtin/unpack-objects.c | 3 +-
fetch-pack.c | 6 +-
fsck.c | 197 +++++++++++++++------------------------
fsck.h | 131 +++++++++++++++++++++++---
7 files changed, 213 insertions(+), 182 deletions(-)
Range-diff:
1: 9cd942b526 < -: ---------- fsck.h: update FSCK_OPTIONS_* for object_name
2: d67966b838 < -: ---------- fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
3: 211472e0c5 < -: ---------- fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
4: 70afee988d < -: ---------- fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
5: 1337d53352 < -: ---------- fsck.h: indent arguments to of fsck_set_msg_type
-: ---------- > 1: fe33015e0d fsck.c: refactor and rename common config callback
-: ---------- > 2: 72f2e53afa fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
6: e4ef107bb4 = 3: 237a280686 fsck.h: use "enum object_type" instead of "int"
7: 20bac3207e ! 4: 13b76c73dd fsck.c: rename variables in fsck_set_msg_type() for less confusion
@@ Commit message
"msg_id" to "msg_id_str" etc. This will make a follow-up change
smaller.
+ While I'm at it properly indent the fsck_set_msg_type() argument list.
+
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## fsck.c ##
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
-+ const char *msg_id_str, const char *msg_type_str)
++ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
+
+ ## fsck.h ##
+@@ fsck.h: struct fsck_options;
+ struct object;
+
+ void fsck_set_msg_type(struct fsck_options *options,
+- const char *msg_id, const char *msg_type);
++ const char *msg_id, const char *msg_type);
+ 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);
+
8: 09c3bba9e9 = 5: 4ae83403b7 fsck.c: move definition of msg_id into append_msg_id()
9: 8067df53a2 = 6: 82107f1dac fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
10: bdf5e13f3d = 7: 796096bf73 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
11: b03caa237f ! 8: 3664abb23d fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
@@ builtin/index-pack.c: static void show_pack_info(int stat_only)
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
## builtin/mktag.c ##
-@@ builtin/mktag.c: static int mktag_config(const char *var, const char *value, void *cb)
+@@ builtin/mktag.c: static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
@@ fsck.c: static int fsck_msg_type(enum fsck_msg_id msg_id,
return FSCK_ERROR;
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
12: 7b1d13b4cc = 9: 81e6d7ab45 fsck.h: re-order and re-assign "enum fsck_msg_type"
13: a8e4ca7b19 ! 10: 5c2e8e7b84 fsck.c: call parse_msg_type() early in fsck_set_msg_type()
@@ Commit message
## fsck.c ##
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
14: 214c375a20 = 11: 7ffbf9af3f fsck.c: undefine temporary STR macro after use
15: 19a2499a80 = 12: 12ff0f75eb fsck.c: give "FOREACH_MSG_ID" a more specific name
16: 6e1a7b6274 = 13: 0c49dd5164 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
17: 42af4e164c = 14: 900263f503 fsck.c: pass along the fsck_msg_id in the fsck_error callback
18: fa47f473a8 ! 15: 5f270e88a0 fsck.c: add an fsck_set_msg_type() API that takes enums
@@ builtin/mktag.c: int cmd_mktag(int argc, const char **argv, const char *prefix)
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
- git_config(mktag_config, NULL);
+ git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
## fsck.c ##
@@ fsck.c: int is_valid_msg_type(const char *msg_id, const char *msg_type)
+}
+
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id_str, const char *msg_type_str)
+ const char *msg_id_str, const char *msg_type_str)
{
@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
19: 4cc3880cc4 = 16: 539d019712 fsck.c: move gitmodules_{found,done} into fsck_options
20: fd219d318a = 17: 1acf744236 fetch-pack: don't needlessly copy fsck_options
21: e4cd8c250e = 18: b47c3d5ac6 fetch-pack: use file-scope static struct for fsck_options
22: fdbc3c304c ! 19: f05fa5c3ec fetch-pack: use new fsck API to printing dangling submodules
@@ Commit message
manipulating the "gitmodules_found" member. A recent commit moved it
into "fsck_options" so we could do this here.
- Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
- would be to either define this directly in fsck.c as a public API, or
- to create some library shared by fetch-pack.c ad builtin/index-pack.
+ I'm sticking this callback in fsck.c. Perhaps in the future we'd like
+ to accumulate such callbacks into another file (maybe fsck-cb.c,
+ similar to parse-options-cb.c?), but while we've got just the one
+ let's just put it into fsck.c.
- I expect that there won't be many of these fsck utility functions in
- the future, so just having a single fsck-cb.c makes sense.
+ A better alternative in this case would be some library some more
+ obvious library shared by fetch-pack.c ad builtin/index-pack.c, but
+ there isn't such a thing.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- ## Makefile ##
-@@ Makefile: LIB_OBJS += fetch-negotiator.o
- LIB_OBJS += fetch-pack.o
- LIB_OBJS += fmt-merge-msg.o
- LIB_OBJS += fsck.o
-+LIB_OBJS += fsck-cb.o
- LIB_OBJS += fsmonitor.o
- LIB_OBJS += gettext.o
- LIB_OBJS += gpg-interface.o
-
## builtin/index-pack.c ##
@@ builtin/index-pack.c: static int nr_threads;
static int from_stdin;
@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
die("fsck failed");
}
- ## fsck-cb.c (new) ##
-@@
-+#include "git-compat-util.h"
-+#include "fsck.h"
+ ## fsck.c ##
+@@ fsck.c: int fsck_error_function(struct fsck_options *o,
+ return 1;
+ }
+
+-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
+-{
+- oidset_insert(&options->gitmodules_found, oid);
+-}
+-
+ int fsck_finish(struct fsck_options *options)
+ {
+ int ret = 0;
+@@ fsck.c: int git_fsck_config(const char *var, const char *value, void *cb)
+
+ return git_default_config(var, value, cb);
+ }
++
++/*
++ * Custom error callbacks that are used in more than one place.
++ */
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
@@ fsck-cb.c (new)
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
- ## fsck.c ##
-@@ fsck.c: int fsck_error_function(struct fsck_options *o,
- return 1;
- }
-
--void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
--{
-- oidset_insert(&options->gitmodules_found, oid);
--}
--
- int fsck_finish(struct fsck_options *options)
- {
- int ret = 0;
-
## fsck.h ##
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *optio
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
@@ fsck.h: const char *fsck_describe_object(struct fsck_options *options,
- int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options);
+ */
+ int git_fsck_config(const char *var, const char *value, void *cb);
+/*
-+ * Initializations for callbacks in fsck-cb.c
++ * Custom error callbacks that are used in more than one place.
+ */
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ FSCK_OPTIONS_COMMON \
+}
-+
-+/*
-+ * Error callbacks in fsck-cb.c
-+ */
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
--
2.31.0.260.g719c683c1d
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v5 00/19] fsck: API improvements
2021-03-17 18:20 ` [PATCH v5 00/19] " Ævar Arnfjörð Bjarmason
@ 2021-03-17 20:30 ` Derrick Stolee
2021-03-17 21:06 ` Junio C Hamano
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2 siblings, 0 replies; 229+ messages in thread
From: Derrick Stolee @ 2021-03-17 20:30 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason, git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/17/2021 2:20 PM, Ævar Arnfjörð Bjarmason wrote:
> A v5 with changes suggested by Derrick Stolee. Link to v4:
> https://lore.kernel.org/git/20210316161738.30254-1-avarab@gmail.com/
>
> Changes:
>
> * 1/19 is new, it's a simple refactoring of some git_config() code in
> fsck.c code I changed recently.
This new patch is simple, as advertised.
> * Squashed the first 4x patches of incrementally redefining two
> macros into one.
Thanks.
> * Squashed a whitespace-only change into another patch that changed
> the same code.
>
> * Got rid of fsck-cb.c, that one function just lives at the bottom of
> fsck.c now.
I was late in giving you confirmation that fsck.c is a good place,
but you got there, anyway. Thanks!
This version LGTM.
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v5 00/19] fsck: API improvements
2021-03-17 18:20 ` [PATCH v5 00/19] " Ævar Arnfjörð Bjarmason
2021-03-17 20:30 ` Derrick Stolee
@ 2021-03-17 21:06 ` Junio C Hamano
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 21:06 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan, Derrick Stolee
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> A v5 with changes suggested by Derrick Stolee. Link to v4:
> https://lore.kernel.org/git/20210316161738.30254-1-avarab@gmail.com/
>
> Changes:
>
> * 1/19 is new, it's a simple refactoring of some git_config() code in
> fsck.c code I changed recently.
The new step makes sense. I think the series and my comment e-mails
crossed, and all of my comments on the previous round still applies
(including the fsck-cb.c thing, which I think should be added to its
sole user index-pack.c, not to fsck.c).
Thanks, will queue.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v6 00/19] fsck: API improvements
2021-03-17 18:20 ` [PATCH v5 00/19] " Ævar Arnfjörð Bjarmason
2021-03-17 20:30 ` Derrick Stolee
2021-03-17 21:06 ` Junio C Hamano
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 01/19] fsck.c: refactor and rename common config callback Ævar Arnfjörð Bjarmason
` (19 more replies)
2 siblings, 20 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
To recap on the goals in v1[1] this series gets rid of the need to
have the rececently added "print_dangling_gitmodules" function in
favor of a better fsck API to get at that information.
Changes since v5[2]:
* Addressed all outstanding feedback AFAICT
* The fields we init to 0/NULL in the new designated initializer are
gone
* There were comments on the refactoring of append_msg_id(), It turns
out that we can entirely remove that function. So a new commit go
added + one ejected to do that.
* Clarifications in commit messages.
* I'd still left behind a remnant of the old
"print_dangling_gitmodules" code in v5's last commit. I.e. we had
code that was accumulating its own list of gitmodules OIDs and then
injecting into the fsck state, now that the fsck state tracks those
itself we can that list directly instead.
1. https://lore.kernel.org/git/20210217194246.25342-1-avarab@gmail.com/
2. https://lore.kernel.org/git/20210317182054.5986-1-avarab@gmail.com/
Ævar Arnfjörð Bjarmason (19):
fsck.c: refactor and rename common config callback
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
fsck.h: use "enum object_type" instead of "int"
fsck.c: rename variables in fsck_set_msg_type() for less confusion
fsck.c: remove (mostly) redundant append_msg_id() function
fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
fsck.h: re-order and re-assign "enum fsck_msg_type"
fsck.c: call parse_msg_type() early in fsck_set_msg_type()
fsck.c: undefine temporary STR macro after use
fsck.c: give "FOREACH_MSG_ID" a more specific name
fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
fsck.c: pass along the fsck_msg_id in the fsck_error callback
fsck.c: add an fsck_set_msg_type() API that takes enums
fsck.c: move gitmodules_{found,done} into fsck_options
fetch-pack: don't needlessly copy fsck_options
fetch-pack: use file-scope static struct for fsck_options
fetch-pack: use new fsck API to printing dangling submodules
builtin/fsck.c | 14 ++-
builtin/index-pack.c | 30 +-----
builtin/mktag.c | 14 ++-
builtin/unpack-objects.c | 3 +-
fetch-pack.c | 31 ++----
fsck.c | 207 +++++++++++++--------------------------
fsck.h | 127 +++++++++++++++++++++---
7 files changed, 210 insertions(+), 216 deletions(-)
Range-diff:
1: fe33015e0d9 = 1: 579af32ab3e fsck.c: refactor and rename common config callback
2: 72f2e53afac ! 2: b17c982293e fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
@@ Commit message
fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
- designated initializers.
-
- While I'm at it add the "object_names" member to the
- initialization. This was omitted in 7b35efd734e (fsck_walk():
- optionally name objects on the go, 2016-07-17) when the field was
- added.
-
- I'm using a new FSCK_OPTIONS_COMMON and FSCK_OPTIONS_COMMON_ERROR_FUNC
- helper macros to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in
- common, and define the two in terms of those macro.
-
- The FSCK_OPTIONS_COMMON macro will be used in a subsequent commit to
- define other variants of common fsck initialization that wants to use
- a custom error function, but share the rest of the defaults.
+ designated initializers. This allows us to omit those fields that
+ aren't initialized to zero or NULL.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
@@ fsck.h: struct fsck_options {
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
-+#define FSCK_OPTIONS_COMMON \
-+ .walk = NULL, \
-+ .msg_type = NULL, \
++#define FSCK_OPTIONS_DEFAULT { \
+ .skiplist = OIDSET_INIT, \
-+ .object_names = NULL,
-+#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
-+ FSCK_OPTIONS_COMMON \
-+ .error_func = fsck_error_function
-+
-+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
-+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
++ .error_func = fsck_error_function \
++}
++#define FSCK_OPTIONS_STRICT { \
++ .strict = 1, \
++ .error_func = fsck_error_function, \
++}
/* descend in all linked child objects
* the return value is:
3: 237a2806865 = 3: a721c396c50 fsck.h: use "enum object_type" instead of "int"
4: 13b76c73dd7 = 4: fcdba2f8fe8 fsck.c: rename variables in fsck_set_msg_type() for less confusion
5: 4ae83403b73 ! 5: b07e8e026ac fsck.c: move definition of msg_id into append_msg_id()
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## Commit message ##
- fsck.c: move definition of msg_id into append_msg_id()
+ fsck.c: remove (mostly) redundant append_msg_id() function
- Refactor code added in 71ab8fa840f (fsck: report the ID of the
- error/warning, 2015-06-22) to resolve the msg_id to a string in the
- function that wants it, instead of doing it in report().
+ Remove the append_msg_id() function in favor of calling
+ prepare_msg_ids(). We already have code to compute the camel-cased
+ msg_id strings in msg_id_info, let's use it.
+
+ When the append_msg_id() function was added in 71ab8fa840f (fsck:
+ report the ID of the error/warning, 2015-06-22) the prepare_msg_ids()
+ function didn't exist. When prepare_msg_ids() was added in
+ a46baac61eb (fsck: factor out msg_id_info[] lazy initialization code,
+ 2018-05-26) this code wasn't moved over to lazy initialization.
+
+ This changes the behavior of the code to initialize all the messages
+ instead of just camel-casing the one we need on the fly. Since the
+ common case is that we're printing just one message this is mostly
+ redundant work.
+
+ But that's OK in this case, reporting this fsck issue to the user
+ isn't performance-sensitive. If we were somehow doing so in a tight
+ loop (in a hopelessly broken repository?) this would help, since we'd
+ save ourselves from re-doing this work for identical messages, we
+ could just grab the prepared string from msg_id_info after the first
+ invocation.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
-+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
+-{
+- for (;;) {
+- char c = *(msg_id)++;
+-
+- if (!c)
+- break;
+- if (c != '_')
+- strbuf_addch(sb, tolower(c));
+- else {
+- assert(*msg_id);
+- strbuf_addch(sb, *(msg_id)++);
+- }
+- }
+-
+- strbuf_addstr(sb, ": ");
+-}
+-
+ static int object_on_skiplist(struct fsck_options *opts,
+ const struct object_id *oid)
{
-+ const char *msg_id = msg_id_info[id].id_string;
- for (;;) {
- char c = *(msg_id)++;
-
@@ fsck.c: static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
-+ append_msg_id(&sb, id);
++ prepare_msg_ids();
++ strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
6: 82107f1dac0 ! 6: 321b0c652de fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
@@ Commit message
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## fsck.c ##
-@@ fsck.c: void fsck_set_msg_types(struct fsck_options *options, const char *values)
- free(to_free);
- }
-
--static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
-+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id)
- {
-- const char *msg_id = msg_id_info[id].id_string;
-+ const char *msg_id_str = msg_id_info[msg_id].id_string;
- for (;;) {
-- char c = *(msg_id)++;
-+ char c = *(msg_id_str)++;
-
- if (!c)
- break;
- if (c != '_')
- strbuf_addch(sb, tolower(c));
- else {
-- assert(*msg_id);
-- strbuf_addch(sb, *(msg_id)++);
-+ assert(*msg_id_str);
-+ strbuf_addch(sb, *(msg_id_str)++);
- }
- }
-
@@ fsck.c: static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
@@ fsck.c: static int object_on_skiplist(struct fsck_options *opts,
if (msg_type == FSCK_IGNORE)
return 0;
@@ fsck.c: static int report(struct fsck_options *options,
- else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
-- append_msg_id(&sb, id);
-+ append_msg_id(&sb, msg_id);
+ prepare_msg_ids();
+- strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
++ strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
7: 796096bf73e = 7: 948689ad5c8 fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
8: 3664abb23de = 8: 8ea468bf4d8 fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
9: 81e6d7ab450 ! 9: 9316b35cd3b fsck.h: re-order and re-assign "enum fsck_msg_type"
@@ Commit message
defined as "2".
I'm confident that nothing relies on these values, we always compare
- them explicitly. Let's not omit "0" so it won't be assumed that we're
- using these as a boolean somewhere.
+ them for equality. Let's not omit "0" so it won't be assumed that
+ we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are
"private" v.s. "public". See the preceding commit for a rationale for
10: 5c2e8e7b842 = 10: d7f1c5d37de fsck.c: call parse_msg_type() early in fsck_set_msg_type()
11: 7ffbf9af3fa = 11: ae5efd745cf fsck.c: undefine temporary STR macro after use
12: 12ff0f75ebf = 12: 96995244806 fsck.c: give "FOREACH_MSG_ID" a more specific name
13: 0c49dd5164f = 13: 1b42aea3a64 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
14: 900263f503a = 14: 563e6a0e5e6 fsck.c: pass along the fsck_msg_id in the fsck_error callback
15: 5f270e88a0a = 15: 5e504f25c51 fsck.c: add an fsck_set_msg_type() API that takes enums
16: 539d0197129 ! 16: 611631dd779 fsck.c: move gitmodules_{found,done} into fsck_options
@@ Commit message
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.
+ An earlier version of this patch removed the small amount of
+ duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a
+ FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth
+ it for this amount of copy/pasting.
+
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
## fetch-pack.c ##
@@ fsck.h: struct fsck_options {
kh_oid_map_t *object_names;
};
-@@ fsck.h: struct fsck_options {
- .walk = NULL, \
- .msg_type = NULL, \
+ #define FSCK_OPTIONS_DEFAULT { \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
- .object_names = NULL,
- #define FSCK_OPTIONS_COMMON_ERROR_FUNC \
- FSCK_OPTIONS_COMMON \
+ .error_func = fsck_error_function \
+ }
+ #define FSCK_OPTIONS_STRICT { \
+ .strict = 1, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
+ .error_func = fsck_error_function, \
+ }
+
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
17: 1acf7442365 = 17: 03d512c8448 fetch-pack: don't needlessly copy fsck_options
18: b47c3d5ac6f = 18: 581c87c63c6 fetch-pack: use file-scope static struct for fsck_options
19: f05fa5c3ec9 ! 19: 6a38cade8c3 fetch-pack: use new fsck API to printing dangling submodules
@@ fetch-pack.c: static int server_supports_filtering;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
-@@ fetch-pack.c: static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+@@ fetch-pack.c: static int cmp_ref_by_name(const void *a_, const void *b_)
+ return strcmp(a->name, b->name);
+ }
- oidset_iter_init(gitmodules_oids, &iter);
- while ((oid = oidset_iter_next(&iter)))
+-static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+-{
+- struct oidset_iter iter;
+- const struct object_id *oid;
+-
+- if (!oidset_size(gitmodules_oids))
+- return;
+-
+- oidset_iter_init(gitmodules_oids, &iter);
+- while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
-+ oidset_insert(&fsck_options.gitmodules_found, oid);
- if (fsck_finish(&fsck_options))
- die("fsck failed");
- }
+- if (fsck_finish(&fsck_options))
+- die("fsck failed");
+-}
+-
+ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ int fd[2],
+ const struct ref *orig_ref,
+@@ fetch-pack.c: static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ int agent_len;
+ struct fetch_negotiator negotiator_alloc;
+ struct fetch_negotiator *negotiator;
+- struct oidset gitmodules_oids = OIDSET_INIT;
+
+ negotiator = &negotiator_alloc;
+ fetch_negotiator_init(r, negotiator);
+@@ fetch-pack.c: static struct ref *do_fetch_pack(struct fetch_pack_args *args,
+ else
+ alternate_shallow_file = NULL;
+ if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
+- &gitmodules_oids))
++ &fsck_options.gitmodules_found))
+ die(_("git fetch-pack: fetch failed."));
+- fsck_gitmodules_oids(&gitmodules_oids);
++ if (fsck_finish(&fsck_options))
++ die("fsck failed");
+
+ all_done:
+ if (negotiator)
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ struct string_list packfile_uris = STRING_LIST_INIT_DUP;
+ int i;
+ struct strvec index_pack_args = STRVEC_INIT;
+- struct oidset gitmodules_oids = OIDSET_INIT;
+
+ negotiator = &negotiator_alloc;
+ fetch_negotiator_init(r, negotiator);
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ process_section_header(&reader, "packfile", 0);
+ if (get_pack(args, fd, pack_lockfiles,
+ packfile_uris.nr ? &index_pack_args : NULL,
+- sought, nr_sought, &gitmodules_oids))
++ sought, nr_sought, &fsck_options.gitmodules_found))
+ die(_("git fetch-pack: fetch failed."));
+ do_check_stateless_delimiter(args, &reader);
+
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+
+ packname[the_hash_algo->hexsz] = '\0';
+
+- parse_gitmodules_oids(cmd.out, &gitmodules_oids);
++ parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found);
+
+ close(cmd.out);
+
+@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
+ string_list_clear(&packfile_uris, 0);
+ strvec_clear(&index_pack_args);
+
+- fsck_gitmodules_oids(&gitmodules_oids);
++ if (fsck_finish(&fsck_options))
++ die("fsck failed");
+
+ if (negotiator)
+ negotiator->release(negotiator);
## fsck.c ##
@@ fsck.c: int fsck_error_function(struct fsck_options *o,
@@ fsck.c: int git_fsck_config(const char *var, const char *value, void *cb)
+}
## fsck.h ##
+@@ fsck.h: int fsck_error_function(struct fsck_options *o,
+ const struct object_id *oid, enum object_type object_type,
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
++int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
++ const struct object_id *oid,
++ enum object_type object_type,
++ enum fsck_msg_type msg_type,
++ enum fsck_msg_id msg_id,
++ const char *message);
+
+ struct fsck_options {
+ fsck_walk_func walk;
+@@ fsck.h: struct fsck_options {
+ .gitmodules_done = OIDSET_INIT, \
+ .error_func = fsck_error_function, \
+ }
++#define FSCK_OPTIONS_MISSING_GITMODULES { \
++ .strict = 1, \
++ .gitmodules_found = OIDSET_INIT, \
++ .gitmodules_done = OIDSET_INIT, \
++ .error_func = fsck_error_cb_print_missing_gitmodules, \
++}
+
+ /* descend in all linked child objects
+ * the return value is:
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
@@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *optio
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
-@@ fsck.h: const char *fsck_describe_object(struct fsck_options *options,
- */
- int git_fsck_config(const char *var, const char *value, void *cb);
-
-+/*
-+ * Custom error callbacks that are used in more than one place.
-+ */
-+#define FSCK_OPTIONS_MISSING_GITMODULES { \
-+ .strict = 1, \
-+ .error_func = fsck_error_cb_print_missing_gitmodules, \
-+ FSCK_OPTIONS_COMMON \
-+}
-+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
-+ const struct object_id *oid,
-+ enum object_type object_type,
-+ enum fsck_msg_type msg_type,
-+ enum fsck_msg_id msg_id,
-+ const char *message);
-+
- #endif
--
2.31.1.445.g087790d4945
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v6 01/19] fsck.c: refactor and rename common config callback
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (18 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor code I recently changed in 1f3299fda9 (fsck: make
fsck_config() re-usable, 2021-01-05) so that I could use fsck's config
callback in mktag in 1f3299fda9 (fsck: make fsck_config() re-usable,
2021-01-05).
I don't know what I was thinking in structuring the code this way, but
it clearly makes no sense to have an fsck_config_internal() at all
just so it can get a fsck_options when git_config() already supports
passing along some void* data.
Let's just make use of that instead, which gets us rid of the two
wrapper functions, and brings fsck's common config callback in line
with other such reusable config callbacks.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 7 +------
builtin/mktag.c | 7 +------
fsck.c | 4 ++--
fsck.h | 3 +--
4 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 821e7798c70..a56a2d0513a 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid,
return ret;
}
-static int fsck_config(const char *var, const char *value, void *cb)
-{
- return fsck_config_internal(var, value, cb, &fsck_obj_options);
-}
-
static int objerror(struct object *obj, const char *err)
{
errors_found |= ERROR_OBJECT;
@@ -803,7 +798,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
if (name_objects)
fsck_enable_object_names(&fsck_walk_options);
- git_config(fsck_config, NULL);
+ git_config(git_fsck_config, &fsck_obj_options);
if (connectivity_only) {
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 41a399a69e4..23c4b8763fa 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -14,11 +14,6 @@ static int option_strict = 1;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
-static int mktag_config(const char *var, const char *value, void *cb)
-{
- return fsck_config_internal(var, value, cb, &fsck_options);
-}
-
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
@@ -93,7 +88,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
fsck_options.error_func = mktag_fsck_error_func;
fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
/* config might set fsck.extraHeaderEntry=* again */
- git_config(mktag_config, NULL);
+ git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
&tagged_oid, &tagged_type))
die(_("tag on stdin did not pass our strict fsck check"));
diff --git a/fsck.c b/fsck.c
index e3030f3b358..5dfb99665ae 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1323,9 +1323,9 @@ int fsck_finish(struct fsck_options *options)
return ret;
}
-int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options)
+int git_fsck_config(const char *var, const char *value, void *cb)
{
+ struct fsck_options *options = cb;
if (strcmp(var, "fsck.skiplist") == 0) {
const char *path;
struct strbuf sb = STRBUF_INIT;
diff --git a/fsck.h b/fsck.h
index 733378f1260..f70d11c5594 100644
--- a/fsck.h
+++ b/fsck.h
@@ -109,7 +109,6 @@ const char *fsck_describe_object(struct fsck_options *options,
* git_config() callback for use by fsck-y tools that want to support
* fsck.<msg> fsck.skipList etc.
*/
-int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options);
+int git_fsck_config(const char *var, const char *value, void *cb);
#endif
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 01/19] fsck.c: refactor and rename common config callback Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 17:15 ` Ramsay Jones
2021-03-28 13:15 ` [PATCH v6 03/19] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
` (17 subsequent siblings)
19 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
designated initializers. This allows us to omit those fields that
aren't initialized to zero or NULL.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index f70d11c5594..73e8b9f3e4e 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,14 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
+#define FSCK_OPTIONS_DEFAULT { \
+ .skiplist = OIDSET_INIT, \
+ .error_func = fsck_error_function \
+}
+#define FSCK_OPTIONS_STRICT { \
+ .strict = 1, \
+ .error_func = fsck_error_function, \
+}
/* descend in all linked child objects
* the return value is:
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-28 13:15 ` [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-28 17:15 ` Ramsay Jones
2021-03-29 2:04 ` Junio C Hamano
0 siblings, 1 reply; 229+ messages in thread
From: Ramsay Jones @ 2021-03-28 17:15 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Junio C Hamano, Jeff King, Johannes Schindelin,
Jonathan Tan, Derrick Stolee
On Sun, Mar 28, 2021 at 03:15:34PM +0200, Ævar Arnfjörð Bjarmason wrote:
> Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
> designated initializers. This allows us to omit those fields that
> aren't initialized to zero or NULL.
s/aren't/are/
[I apologize in advance - I am using mutt for the first time to reply
to a ML post and I don't know if I should be using L-ist-reply or a
g-roup-reply! :D ]
ATB,
Ramsay Jones
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-28 17:15 ` Ramsay Jones
@ 2021-03-29 2:04 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-29 2:04 UTC (permalink / raw)
To: Ramsay Jones
Cc: Ævar Arnfjörð Bjarmason, git, Jeff King,
Johannes Schindelin, Jonathan Tan, Derrick Stolee
Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
> On Sun, Mar 28, 2021 at 03:15:34PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
>> designated initializers. This allows us to omit those fields that
>> aren't initialized to zero or NULL.
>
> s/aren't/are/
Thanks; tweak applied while queuing.
> [I apologize in advance - I am using mutt for the first time to reply
> to a ML post and I don't know if I should be using L-ist-reply or a
> g-roup-reply! :D ]
FWIW, on lore (reading via nntp), the message I am responding to
looks just fine.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v6 03/19] fsck.h: use "enum object_type" instead of "int"
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 01/19] fsck.c: refactor and rename common config callback Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
` (16 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
355885d5315 (add generic, type aware object chain walker, 2008-02-25)
we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is
concerned, it just gives the compiler more information and makes this
easier to read.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 3 ++-
builtin/index-pack.c | 3 ++-
builtin/unpack-objects.c | 3 ++-
fsck.h | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index a56a2d0513a..ed5f2af6b5c 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -192,7 +192,8 @@ static int traverse_reachable(void)
return !!result;
}
-static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_used(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return 1;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 21899687e2c..f6e1178df90 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -212,7 +212,8 @@ static void cleanup_thread(void)
free(thread_data);
}
-static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_link(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return -1;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index a4ba2ebac69..4a70b17f8fb 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -187,7 +187,8 @@ 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, struct fsck_options *options)
+static int check_object(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
struct obj_buffer *obj_buf;
diff --git a/fsck.h b/fsck.h
index 73e8b9f3e4e..f20f1259e84 100644
--- a/fsck.h
+++ b/fsck.h
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);
* <0 error signaled and abort
* >0 error signaled and do not abort
*/
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
+typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options);
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (2 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 03/19] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 05/19] fsck.c: remove (mostly) redundant append_msg_id() function Ævar Arnfjörð Bjarmason
` (15 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename variables in a function added in 0282f4dced0 (fsck: offer a
function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and
"msg_id" to "msg_id_str" etc. This will make a follow-up change
smaller.
While I'm at it properly indent the fsck_set_msg_type() argument list.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 24 ++++++++++++------------
fsck.h | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/fsck.c b/fsck.c
index 5dfb99665ae..7cc722a25cd 100644
--- a/fsck.c
+++ b/fsck.c
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
+ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
- if (id < 0)
- die("Unhandled message id: %s", msg_id);
- type = parse_msg_type(msg_type);
+ if (msg_id < 0)
+ die("Unhandled message id: %s", msg_id_str);
+ msg_type = parse_msg_type(msg_type_str);
- if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
- die("Cannot demote %s to %s", msg_id, msg_type);
+ if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
+ die("Cannot demote %s to %s", msg_id_str, msg_type_str);
if (!options->msg_type) {
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
+ int *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
}
- options->msg_type[id] = type;
+ options->msg_type[msg_id] = msg_type;
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index f20f1259e84..30a3acabc50 100644
--- a/fsck.h
+++ b/fsck.h
@@ -11,7 +11,7 @@ struct fsck_options;
struct object;
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type);
+ const char *msg_id, const char *msg_type);
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);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 05/19] fsck.c: remove (mostly) redundant append_msg_id() function
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (3 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
` (14 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Remove the append_msg_id() function in favor of calling
prepare_msg_ids(). We already have code to compute the camel-cased
msg_id strings in msg_id_info, let's use it.
When the append_msg_id() function was added in 71ab8fa840f (fsck:
report the ID of the error/warning, 2015-06-22) the prepare_msg_ids()
function didn't exist. When prepare_msg_ids() was added in
a46baac61eb (fsck: factor out msg_id_info[] lazy initialization code,
2018-05-26) this code wasn't moved over to lazy initialization.
This changes the behavior of the code to initialize all the messages
instead of just camel-casing the one we need on the fly. Since the
common case is that we're printing just one message this is mostly
redundant work.
But that's OK in this case, reporting this fsck issue to the user
isn't performance-sensitive. If we were somehow doing so in a tight
loop (in a hopelessly broken repository?) this would help, since we'd
save ourselves from re-doing this work for identical messages, we
could just grab the prepared string from msg_id_info after the first
invocation.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/fsck.c b/fsck.c
index 7cc722a25cd..25c697fa6a2 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,24 +264,6 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
-{
- for (;;) {
- char c = *(msg_id)++;
-
- if (!c)
- break;
- if (c != '_')
- strbuf_addch(sb, tolower(c));
- else {
- assert(*msg_id);
- strbuf_addch(sb, *(msg_id)++);
- }
- }
-
- strbuf_addstr(sb, ": ");
-}
-
static int object_on_skiplist(struct fsck_options *opts,
const struct object_id *oid)
{
@@ -308,7 +290,8 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
+ prepare_msg_ids();
+ strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (4 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 05/19] fsck.c: remove (mostly) redundant append_msg_id() function Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
` (13 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename the remaining variables of type fsck_msg_id from "id" to
"msg_id". This change is relatively small, and is worth the churn for
a later change where we have different id's in the "report" function.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fsck.c b/fsck.c
index 25c697fa6a2..a0463ea22cc 100644
--- a/fsck.c
+++ b/fsck.c
@@ -273,11 +273,11 @@ static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_id id, const char *fmt, ...)
+ enum fsck_msg_id msg_id, const char *fmt, ...)
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(id, options), result;
+ int msg_type = fsck_msg_type(msg_id, options), result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -291,7 +291,7 @@ static int report(struct fsck_options *options,
msg_type = FSCK_WARN;
prepare_msg_ids();
- strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
+ strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (5 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
` (12 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor "if options->msg_type" and other code added in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit,
only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type()
function (also added in 0282f4dced0), which does a similar check for
"!options->msg_type". Another minor benefit is getting rid of the
style violation of not having braces for the body of the "if".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fsck.c b/fsck.c
index a0463ea22cc..8614ee2c2a0 100644
--- a/fsck.c
+++ b/fsck.c
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
static int fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
- int msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
- if (options->msg_type)
- msg_type = options->msg_type[msg_id];
- else {
- msg_type = msg_id_info[msg_id].msg_type;
+ if (!options->msg_type) {
+ int msg_type = msg_id_info[msg_id].msg_type;
+
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
+ return msg_type;
}
- return msg_type;
+ return options->msg_type[msg_id];
}
static int parse_msg_type(const char *str)
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (6 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
` (11 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to
fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings,
2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues
completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors,
2015-06-22)
The reason these were defined in two different places is because we
use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
used by external callbacks.
Untangling that would take some more work, since we expose the new
"enum fsck_msg_type" to both. Similar to "enum object_type" it's not
worth structuring the API in such a way that only those who need
FSCK_{ERROR,WARN} pass around a different type.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 2 +-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 3 ++-
fsck.c | 21 ++++++++++-----------
fsck.h | 16 ++++++++++------
5 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ed5f2af6b5c..17940a4e24a 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index f6e1178df90..8338b832b63 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)
static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
/*
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 23c4b8763fa..052a510ad7f 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/fsck.c b/fsck.c
index 8614ee2c2a0..c5a81e4ff05 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,9 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FSCK_FATAL -1
-#define FSCK_INFO -2
-
#define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {
const char *id_string;
const char *downcased;
const char *camelcased;
- int msg_type;
+ enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
FOREACH_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
list_config_item(list, prefix, msg_id_info[i].camelcased);
}
-static int fsck_msg_type(enum fsck_msg_id msg_id,
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
if (!options->msg_type) {
- int msg_type = msg_id_info[msg_id].msg_type;
+ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
+static enum fsck_msg_type parse_msg_type(const char *str)
{
if (!strcmp(str, "error"))
return FSCK_ERROR;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
+ enum fsck_msg_type msg_type;
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
- int *severity;
+ enum fsck_msg_type *severity;
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
severity[i] = fsck_msg_type(i, options);
@@ -275,7 +273,8 @@ static int report(struct fsck_options *options,
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(msg_id, options), result;
+ enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
+ int result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -1247,7 +1246,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index 30a3acabc50..baf37620760 100644
--- a/fsck.h
+++ b/fsck.h
@@ -3,9 +3,13 @@
#include "oidset.h"
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
+enum fsck_msg_type {
+ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
struct fsck_options;
struct object;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
struct fsck_options {
fsck_walk_func walk;
fsck_error error_func;
unsigned strict:1;
- int *msg_type;
+ enum fsck_msg_type *msg_type;
struct oidset skiplist;
kh_oid_map_t *object_names;
};
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type"
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (7 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
` (10 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the values in the "enum fsck_msg_type" from being manually
assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously
defined as "2".
I'm confident that nothing relies on these values, we always compare
them for equality. Let's not omit "0" so it won't be assumed that
we're using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are
"private" v.s. "public". See the preceding commit for a rationale for
not simply splitting these into two enums, namely that this is used
for both the private and public fsck API.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fsck.h b/fsck.h
index baf37620760..a7e092d3fb4 100644
--- a/fsck.h
+++ b/fsck.h
@@ -4,11 +4,13 @@
#include "oidset.h"
enum fsck_msg_type {
- FSCK_INFO = -2,
- FSCK_FATAL = -1,
- FSCK_ERROR = 1,
+ /* for internal use only */
+ FSCK_IGNORE,
+ FSCK_INFO,
+ FSCK_FATAL,
+ /* "public", fed to e.g. error_func callbacks */
+ FSCK_ERROR,
FSCK_WARN,
- FSCK_IGNORE
};
struct fsck_options;
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type()
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (8 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 11/19] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
` (9 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
There's no reason to defer the calling of parse_msg_type() until after
we've checked if the "id < 0". This is not a hot codepath, and
parse_msg_type() itself may die on invalid input.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index c5a81e4ff05..80365e62842 100644
--- a/fsck.c
+++ b/fsck.c
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
+ enum fsck_msg_type msg_type = parse_msg_type(msg_type_str);
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
- msg_type = parse_msg_type(msg_type_str);
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 11/19] fsck.c: undefine temporary STR macro after use
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (9 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
` (8 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
In f417eed8cde (fsck: provide a function to parse fsck message IDs,
2015-06-22) the "STR" macro was introduced, but that short macro name
was not undefined after use as was done earlier in the same series for
the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck
messages, 2015-06-22).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fsck.c b/fsck.c
index 80365e62842..1b12e824ef6 100644
--- a/fsck.c
+++ b/fsck.c
@@ -100,6 +100,7 @@ static struct {
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
+#undef STR
static void prepare_msg_ids(void)
{
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (10 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 11/19] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
` (7 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation
for moving it over to fsck.h. It's good convention to name macros
in *.h files in such a way as to clearly not clash with any other
names in other files.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fsck.c b/fsck.c
index 1b12e824ef6..31c9088e3f7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,7 +22,7 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_MSG_ID(FUNC) \
+#define FOREACH_FSCK_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
#define MSG_ID(id, msg_type) FSCK_MSG_##id,
enum fsck_msg_id {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
FSCK_MSG_MAX
};
#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {
const char *camelcased;
enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (11 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
` (6 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps
define from fsck.c to fsck.h. This is in preparation for having
non-static functions take the fsck_msg_id as an argument.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 66 ----------------------------------------------------------
fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 66 deletions(-)
diff --git a/fsck.c b/fsck.c
index 31c9088e3f7..150fe467e43 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,72 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_FSCK_MSG_ID(FUNC) \
- /* fatal errors */ \
- FUNC(NUL_IN_HEADER, FATAL) \
- FUNC(UNTERMINATED_HEADER, FATAL) \
- /* errors */ \
- FUNC(BAD_DATE, ERROR) \
- FUNC(BAD_DATE_OVERFLOW, ERROR) \
- FUNC(BAD_EMAIL, ERROR) \
- FUNC(BAD_NAME, ERROR) \
- FUNC(BAD_OBJECT_SHA1, ERROR) \
- FUNC(BAD_PARENT_SHA1, ERROR) \
- FUNC(BAD_TAG_OBJECT, ERROR) \
- FUNC(BAD_TIMEZONE, ERROR) \
- FUNC(BAD_TREE, ERROR) \
- FUNC(BAD_TREE_SHA1, ERROR) \
- FUNC(BAD_TYPE, ERROR) \
- FUNC(DUPLICATE_ENTRIES, ERROR) \
- FUNC(MISSING_AUTHOR, ERROR) \
- FUNC(MISSING_COMMITTER, ERROR) \
- FUNC(MISSING_EMAIL, ERROR) \
- FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_OBJECT, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_TAG, ERROR) \
- FUNC(MISSING_TAG_ENTRY, ERROR) \
- FUNC(MISSING_TREE, ERROR) \
- FUNC(MISSING_TREE_OBJECT, ERROR) \
- FUNC(MISSING_TYPE, ERROR) \
- FUNC(MISSING_TYPE_ENTRY, ERROR) \
- FUNC(MULTIPLE_AUTHORS, ERROR) \
- FUNC(TREE_NOT_SORTED, ERROR) \
- FUNC(UNKNOWN_TYPE, ERROR) \
- FUNC(ZERO_PADDED_DATE, ERROR) \
- FUNC(GITMODULES_MISSING, ERROR) \
- FUNC(GITMODULES_BLOB, ERROR) \
- FUNC(GITMODULES_LARGE, ERROR) \
- FUNC(GITMODULES_NAME, ERROR) \
- FUNC(GITMODULES_SYMLINK, ERROR) \
- FUNC(GITMODULES_URL, ERROR) \
- FUNC(GITMODULES_PATH, ERROR) \
- FUNC(GITMODULES_UPDATE, ERROR) \
- /* warnings */ \
- FUNC(BAD_FILEMODE, WARN) \
- FUNC(EMPTY_NAME, WARN) \
- FUNC(FULL_PATHNAME, WARN) \
- FUNC(HAS_DOT, WARN) \
- FUNC(HAS_DOTDOT, WARN) \
- FUNC(HAS_DOTGIT, WARN) \
- FUNC(NULL_SHA1, WARN) \
- FUNC(ZERO_PADDED_FILEMODE, WARN) \
- FUNC(NUL_IN_COMMIT, WARN) \
- /* infos (reported as warnings, but ignored by default) */ \
- FUNC(GITMODULES_PARSE, INFO) \
- FUNC(BAD_TAG_NAME, INFO) \
- FUNC(MISSING_TAGGER_ENTRY, INFO) \
- /* ignored (elevated when requested) */ \
- FUNC(EXTRA_HEADER_ENTRY, IGNORE)
-
-#define MSG_ID(id, msg_type) FSCK_MSG_##id,
-enum fsck_msg_id {
- FOREACH_FSCK_MSG_ID(MSG_ID)
- FSCK_MSG_MAX
-};
-#undef MSG_ID
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
diff --git a/fsck.h b/fsck.h
index a7e092d3fb4..66c4a71139a 100644
--- a/fsck.h
+++ b/fsck.h
@@ -13,6 +13,72 @@ enum fsck_msg_type {
FSCK_WARN,
};
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \
+ FUNC(UNTERMINATED_HEADER, FATAL) \
+ /* errors */ \
+ FUNC(BAD_DATE, ERROR) \
+ FUNC(BAD_DATE_OVERFLOW, ERROR) \
+ FUNC(BAD_EMAIL, ERROR) \
+ FUNC(BAD_NAME, ERROR) \
+ FUNC(BAD_OBJECT_SHA1, ERROR) \
+ FUNC(BAD_PARENT_SHA1, ERROR) \
+ FUNC(BAD_TAG_OBJECT, ERROR) \
+ FUNC(BAD_TIMEZONE, ERROR) \
+ FUNC(BAD_TREE, ERROR) \
+ FUNC(BAD_TREE_SHA1, ERROR) \
+ FUNC(BAD_TYPE, ERROR) \
+ FUNC(DUPLICATE_ENTRIES, ERROR) \
+ FUNC(MISSING_AUTHOR, ERROR) \
+ FUNC(MISSING_COMMITTER, ERROR) \
+ FUNC(MISSING_EMAIL, ERROR) \
+ FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_OBJECT, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_TAG, ERROR) \
+ FUNC(MISSING_TAG_ENTRY, ERROR) \
+ FUNC(MISSING_TREE, ERROR) \
+ FUNC(MISSING_TREE_OBJECT, ERROR) \
+ FUNC(MISSING_TYPE, ERROR) \
+ FUNC(MISSING_TYPE_ENTRY, ERROR) \
+ FUNC(MULTIPLE_AUTHORS, ERROR) \
+ FUNC(TREE_NOT_SORTED, ERROR) \
+ FUNC(UNKNOWN_TYPE, ERROR) \
+ FUNC(ZERO_PADDED_DATE, ERROR) \
+ FUNC(GITMODULES_MISSING, ERROR) \
+ FUNC(GITMODULES_BLOB, ERROR) \
+ FUNC(GITMODULES_LARGE, ERROR) \
+ FUNC(GITMODULES_NAME, ERROR) \
+ FUNC(GITMODULES_SYMLINK, ERROR) \
+ FUNC(GITMODULES_URL, ERROR) \
+ FUNC(GITMODULES_PATH, ERROR) \
+ FUNC(GITMODULES_UPDATE, ERROR) \
+ /* warnings */ \
+ FUNC(BAD_FILEMODE, WARN) \
+ FUNC(EMPTY_NAME, WARN) \
+ FUNC(FULL_PATHNAME, WARN) \
+ FUNC(HAS_DOT, WARN) \
+ FUNC(HAS_DOTDOT, WARN) \
+ FUNC(HAS_DOTGIT, WARN) \
+ FUNC(NULL_SHA1, WARN) \
+ FUNC(ZERO_PADDED_FILEMODE, WARN) \
+ FUNC(NUL_IN_COMMIT, WARN) \
+ /* infos (reported as warnings, but ignored by default) */ \
+ FUNC(GITMODULES_PARSE, INFO) \
+ FUNC(BAD_TAG_NAME, INFO) \
+ FUNC(MISSING_TAGGER_ENTRY, INFO) \
+ /* ignored (elevated when requested) */ \
+ FUNC(EXTRA_HEADER_ENTRY, IGNORE)
+
+#define MSG_ID(id, msg_type) FSCK_MSG_##id,
+enum fsck_msg_id {
+ FOREACH_FSCK_MSG_ID(MSG_ID)
+ FSCK_MSG_MAX
+};
+#undef MSG_ID
+
struct fsck_options;
struct object;
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (12 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
` (5 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the fsck_error callback to also pass along the
fsck_msg_id. Before this change the only way to get the message id was
to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might
want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back
from the msg_id, but I'm not changing that convention. It's really
common to need the msg_type, and the report() function itself (which
calls "fsck_error") needs to call fsck_msg_type() to discover
it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 4 +++-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 1 +
fsck.c | 6 ++++--
fsck.h | 6 ++++--
5 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 17940a4e24a..70ff95837ae 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8338b832b63..2f93957fb5e 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
printf("%s\n", oid_to_hex(oid));
return 0;
}
- return fsck_error_function(o, oid, object_type, msg_type, message);
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
}
int cmd_index_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 052a510ad7f..96e63bc772a 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
switch (msg_type) {
diff --git a/fsck.c b/fsck.c
index 150fe467e43..23a77fe2e0f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -227,7 +227,7 @@ static int report(struct fsck_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(options, oid, object_type,
- msg_type, sb.buf);
+ msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -1180,7 +1180,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index 66c4a71139a..fa2d4955ab3 100644
--- a/fsck.h
+++ b/fsck.h
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
struct fsck_options {
fsck_walk_func walk;
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (13 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
` (4 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change code I added in acf9de4c94e (mktag: use fsck instead of custom
verify_tag(), 2021-01-05) to make use of a new API function that takes
the fsck_msg_{id,type} types, instead of arbitrary strings that
we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) it was only intended to be used to parse user-supplied
data.
For things that are purely internal to the C code it makes sense to
have the compiler check these arguments, and to skip the sanity
checking of the data in fsck_set_msg_type() which is redundant to
checks we get from the compiler.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/mktag.c | 3 ++-
fsck.c | 27 +++++++++++++++++----------
fsck.h | 3 +++
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 96e63bc772a..dddcccdd368 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
die_errno(_("could not read from stdin"));
fsck_options.error_func = mktag_fsck_error_func;
- fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
diff --git a/fsck.c b/fsck.c
index 23a77fe2e0f..a59832a1650 100644
--- a/fsck.c
+++ b/fsck.c
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
return 1;
}
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type)
+{
+ if (!options->msg_type) {
+ int i;
+ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
+}
+
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
- if (!options->msg_type) {
- int i;
- enum fsck_msg_type *severity;
- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
- severity[i] = fsck_msg_type(i, options);
- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;
+ fsck_set_msg_type_from_ids(options, msg_id, msg_type);
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index fa2d4955ab3..d284bac3614 100644
--- a/fsck.h
+++ b/fsck.h
@@ -82,6 +82,9 @@ enum fsck_msg_id {
struct fsck_options;
struct object;
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type);
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id, const char *msg_type);
void fsck_set_msg_types(struct fsck_options *options, const char *values);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 16/19] fsck.c: move gitmodules_{found,done} into fsck_options
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (14 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 17/19] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
` (3 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the gitmodules_{found,done} static variables added in
159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the
fsck_options struct. It makes sense to keep all the context in the
same place.
This requires changing the recently added register_found_gitmodules()
function added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) to take fsck_options. That function will be
removed in a subsequent commit, but as it'll require the new
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.
An earlier version of this patch removed the small amount of
duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a
FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth
it for this amount of copy/pasting.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 2 +-
fsck.c | 23 ++++++++++-------------
fsck.h | 9 ++++++++-
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index fb04a76ca26..0f898a5ae14 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(oid);
+ register_found_gitmodules(&fo, oid);
if (fsck_finish(&fo))
die("fsck failed");
}
diff --git a/fsck.c b/fsck.c
index a59832a1650..642bd2ef9da 100644
--- a/fsck.c
+++ b/fsck.c
@@ -19,9 +19,6 @@
#include "credential.h"
#include "help.h"
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
@@ -606,7 +603,7 @@ static int fsck_tree(const struct object_id *oid,
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options,
oid, OBJ_TREE,
@@ -620,7 +617,7 @@ static int fsck_tree(const struct object_id *oid,
has_dotgit |= is_ntfs_dotgit(backslash);
if (is_ntfs_dotgitmodules(backslash)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options, oid, OBJ_TREE,
FSCK_MSG_GITMODULES_SYMLINK,
@@ -1132,9 +1129,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
struct fsck_gitmodules_data data;
struct config_options config_opts = { 0 };
- if (!oidset_contains(&gitmodules_found, oid))
+ if (!oidset_contains(&options->gitmodules_found, oid))
return 0;
- oidset_insert(&gitmodules_done, oid);
+ oidset_insert(&options->gitmodules_done, oid);
if (object_on_skiplist(options, oid))
return 0;
@@ -1199,9 +1196,9 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(const struct object_id *oid)
+void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
{
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
}
int fsck_finish(struct fsck_options *options)
@@ -1210,13 +1207,13 @@ int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
- oidset_iter_init(&gitmodules_found, &iter);
+ oidset_iter_init(&options->gitmodules_found, &iter);
while ((oid = oidset_iter_next(&iter))) {
enum object_type type;
unsigned long size;
char *buf;
- if (oidset_contains(&gitmodules_done, oid))
+ if (oidset_contains(&options->gitmodules_done, oid))
continue;
buf = read_object_file(oid, &type, &size);
@@ -1241,8 +1238,8 @@ int fsck_finish(struct fsck_options *options)
}
- oidset_clear(&gitmodules_found);
- oidset_clear(&gitmodules_done);
+ oidset_clear(&options->gitmodules_found);
+ oidset_clear(&options->gitmodules_done);
return ret;
}
diff --git a/fsck.h b/fsck.h
index d284bac3614..e20f9bcb394 100644
--- a/fsck.h
+++ b/fsck.h
@@ -118,15 +118,21 @@ struct fsck_options {
unsigned strict:1;
enum fsck_msg_type *msg_type;
struct oidset skiplist;
+ struct oidset gitmodules_found;
+ struct oidset gitmodules_done;
kh_oid_map_t *object_names;
};
#define FSCK_OPTIONS_DEFAULT { \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
.error_func = fsck_error_function \
}
#define FSCK_OPTIONS_STRICT { \
.strict = 1, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
.error_func = fsck_error_function, \
}
@@ -146,7 +152,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(const struct object_id *oid);
+void register_found_gitmodules(struct fsck_options *options,
+ const struct object_id *oid);
/*
* fsck a tag, and pass info about it back to the caller. This is
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 17/19] fetch-pack: don't needlessly copy fsck_options
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (15 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 18/19] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
` (2 subsequent siblings)
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the behavior of the .gitmodules validation added in
5476e1efde (fetch-pack: print and use dangling .gitmodules,
2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting
up the error_func earlier means that we're relying on the "error_func"
not being set in some code in between the two hunks being modified
here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is
further setup by calling fsck_set_msg_types(), and assigning to
do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the
fsck_options struct before setting error_func. Let's just do this
setup at the top of the function, along with the "walk" assignment.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2f93957fb5e..5b7bc3c8947 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
+ fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
else
close(input_fd);
- if (do_fsck_object) {
- struct fsck_options fo = fsck_options;
-
- fo.error_func = print_dangling_gitmodules;
- if (fsck_finish(&fo))
- die(_("fsck error in pack objects"));
- }
+ if (do_fsck_object && fsck_finish(&fsck_options))
+ die(_("fsck error in pack objects"));
free(objects);
strbuf_release(&index_name_buf);
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 18/19] fetch-pack: use file-scope static struct for fsck_options
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (16 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 17/19] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-28 13:15 ` [PATCH v6 19/19] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
2021-03-29 2:06 ` [PATCH v6 00/19] fsck: API improvements Junio C Hamano
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change code added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) so that we use a file-scoped "static struct
fsck_options" instead of defining one in the "fsck_gitmodules_oids()"
function.
We use this pattern in all of
builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see
fetch-pack be the odd one out. One might think that we're using other
fsck_options structs in fetch-pack, or doing on fsck twice there, but
we're not.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f898a5ae14..4ec10a15852 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,6 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
{
struct oidset_iter iter;
const struct object_id *oid;
- struct fsck_options fo = FSCK_OPTIONS_STRICT;
if (!oidset_size(gitmodules_oids))
return;
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fo, oid);
- if (fsck_finish(&fo))
+ register_found_gitmodules(&fsck_options, oid);
+ if (fsck_finish(&fsck_options))
die("fsck failed");
}
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v6 19/19] fetch-pack: use new fsck API to printing dangling submodules
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (17 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 18/19] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-28 13:15 ` Ævar Arnfjörð Bjarmason
2021-03-29 2:06 ` [PATCH v6 00/19] fsck: API improvements Junio C Hamano
19 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-28 13:15 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor the check added in 5476e1efde (fetch-pack: print and use
dangling .gitmodules, 2021-02-22) to make use of us now passing the
"msg_id" to the user defined "error_func". We can now compare against
the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
message.
Let's also replace register_found_gitmodules() with directly
manipulating the "gitmodules_found" member. A recent commit moved it
into "fsck_options" so we could do this here.
I'm sticking this callback in fsck.c. Perhaps in the future we'd like
to accumulate such callbacks into another file (maybe fsck-cb.c,
similar to parse-options-cb.c?), but while we've got just the one
let's just put it into fsck.c.
A better alternative in this case would be some library some more
obvious library shared by fetch-pack.c ad builtin/index-pack.c, but
there isn't such a thing.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 21 +--------------------
fetch-pack.c | 31 ++++++++-----------------------
fsck.c | 23 ++++++++++++++++++-----
fsck.h | 15 ++++++++++++---
4 files changed, 39 insertions(+), 51 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5b7bc3c8947..15507b5cff0 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -120,7 +120,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 struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static int verbose;
static int show_resolving_progress;
static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only)
}
}
-static int print_dangling_gitmodules(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
- const char *message)
-{
- /*
- * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
- * instead of relying on this string check.
- */
- if (starts_with(message, "gitmodulesMissing")) {
- printf("%s\n", oid_to_hex(oid));
- return 0;
- }
- return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
-}
-
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
- fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
diff --git a/fetch-pack.c b/fetch-pack.c
index 4ec10a15852..c80eaee7694 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,7 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -988,21 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
return strcmp(a->name, b->name);
}
-static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
-{
- struct oidset_iter iter;
- const struct object_id *oid;
-
- if (!oidset_size(gitmodules_oids))
- return;
-
- oidset_iter_init(gitmodules_oids, &iter);
- while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
- if (fsck_finish(&fsck_options))
- die("fsck failed");
-}
-
static struct ref *do_fetch_pack(struct fetch_pack_args *args,
int fd[2],
const struct ref *orig_ref,
@@ -1017,7 +1002,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
int agent_len;
struct fetch_negotiator negotiator_alloc;
struct fetch_negotiator *negotiator;
- struct oidset gitmodules_oids = OIDSET_INIT;
negotiator = &negotiator_alloc;
fetch_negotiator_init(r, negotiator);
@@ -1134,9 +1118,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
else
alternate_shallow_file = NULL;
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
- &gitmodules_oids))
+ &fsck_options.gitmodules_found))
die(_("git fetch-pack: fetch failed."));
- fsck_gitmodules_oids(&gitmodules_oids);
+ if (fsck_finish(&fsck_options))
+ die("fsck failed");
all_done:
if (negotiator)
@@ -1587,7 +1572,6 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
int i;
struct strvec index_pack_args = STRVEC_INIT;
- struct oidset gitmodules_oids = OIDSET_INIT;
negotiator = &negotiator_alloc;
fetch_negotiator_init(r, negotiator);
@@ -1678,7 +1662,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
process_section_header(&reader, "packfile", 0);
if (get_pack(args, fd, pack_lockfiles,
packfile_uris.nr ? &index_pack_args : NULL,
- sought, nr_sought, &gitmodules_oids))
+ sought, nr_sought, &fsck_options.gitmodules_found))
die(_("git fetch-pack: fetch failed."));
do_check_stateless_delimiter(args, &reader);
@@ -1721,7 +1705,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
packname[the_hash_algo->hexsz] = '\0';
- parse_gitmodules_oids(cmd.out, &gitmodules_oids);
+ parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found);
close(cmd.out);
@@ -1742,7 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
string_list_clear(&packfile_uris, 0);
strvec_clear(&index_pack_args);
- fsck_gitmodules_oids(&gitmodules_oids);
+ if (fsck_finish(&fsck_options))
+ die("fsck failed");
if (negotiator)
negotiator->release(negotiator);
diff --git a/fsck.c b/fsck.c
index 642bd2ef9da..f5ed6a26358 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1196,11 +1196,6 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
-{
- oidset_insert(&options->gitmodules_found, oid);
-}
-
int fsck_finish(struct fsck_options *options)
{
int ret = 0;
@@ -1266,3 +1261,21 @@ int git_fsck_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
+
+/*
+ * Custom error callbacks that are used in more than one place.
+ */
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
+{
+ if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
+ puts(oid_to_hex(oid));
+ return 0;
+ }
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
diff --git a/fsck.h b/fsck.h
index e20f9bcb394..7202c3c87e8 100644
--- a/fsck.h
+++ b/fsck.h
@@ -111,6 +111,12 @@ int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
const char *message);
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message);
struct fsck_options {
fsck_walk_func walk;
@@ -135,6 +141,12 @@ struct fsck_options {
.gitmodules_done = OIDSET_INIT, \
.error_func = fsck_error_function, \
}
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+}
/* descend in all linked child objects
* the return value is:
@@ -152,9 +164,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(struct fsck_options *options,
- const struct object_id *oid);
-
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
--
2.31.1.445.g087790d4945
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v6 00/19] fsck: API improvements
2021-03-28 13:15 ` [PATCH v6 " Ævar Arnfjörð Bjarmason
` (18 preceding siblings ...)
2021-03-28 13:15 ` [PATCH v6 19/19] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
@ 2021-03-29 2:06 ` Junio C Hamano
19 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-29 2:06 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan, Derrick Stolee
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> To recap on the goals in v1[1] this series gets rid of the need to
> have the rececently added "print_dangling_gitmodules" function in
> favor of a better fsck API to get at that information.
Read the whole series afresh, as well as "git diff @{1}" after
replacing to see what changed since the previous round. Didn't find
anything iffy.
Unless somebody finds improvement opportunities in the coming couple
of days, let's declare it is good enough and merge to 'next',
polishing incrementally if needed.
Thanks.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v5 01/19] fsck.c: refactor and rename common config callback
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2021-03-16 19:35 ` Derrick Stolee
2021-03-17 18:20 ` [PATCH v5 00/19] " Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (17 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor code I recently changed in 1f3299fda9 (fsck: make
fsck_config() re-usable, 2021-01-05) so that I could use fsck's config
callback in mktag in 1f3299fda9 (fsck: make fsck_config() re-usable,
2021-01-05).
I don't know what I was thinking in structuring the code this way, but
it clearly makes no sense to have an fsck_config_internal() at all
just so it can get a fsck_options when git_config() already supports
passing along some void* data.
Let's just make use of that instead, which gets us rid of the two
wrapper functions, and brings fsck's common config callback in line
with other such reusable config callbacks.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 7 +------
builtin/mktag.c | 7 +------
fsck.c | 4 ++--
fsck.h | 3 +--
4 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 821e7798c7..a56a2d0513 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid,
return ret;
}
-static int fsck_config(const char *var, const char *value, void *cb)
-{
- return fsck_config_internal(var, value, cb, &fsck_obj_options);
-}
-
static int objerror(struct object *obj, const char *err)
{
errors_found |= ERROR_OBJECT;
@@ -803,7 +798,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
if (name_objects)
fsck_enable_object_names(&fsck_walk_options);
- git_config(fsck_config, NULL);
+ git_config(git_fsck_config, &fsck_obj_options);
if (connectivity_only) {
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 41a399a69e..23c4b8763f 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -14,11 +14,6 @@ static int option_strict = 1;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
-static int mktag_config(const char *var, const char *value, void *cb)
-{
- return fsck_config_internal(var, value, cb, &fsck_options);
-}
-
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
@@ -93,7 +88,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
fsck_options.error_func = mktag_fsck_error_func;
fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
/* config might set fsck.extraHeaderEntry=* again */
- git_config(mktag_config, NULL);
+ git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
&tagged_oid, &tagged_type))
die(_("tag on stdin did not pass our strict fsck check"));
diff --git a/fsck.c b/fsck.c
index e3030f3b35..5dfb99665a 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1323,9 +1323,9 @@ int fsck_finish(struct fsck_options *options)
return ret;
}
-int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options)
+int git_fsck_config(const char *var, const char *value, void *cb)
{
+ struct fsck_options *options = cb;
if (strcmp(var, "fsck.skiplist") == 0) {
const char *path;
struct strbuf sb = STRBUF_INIT;
diff --git a/fsck.h b/fsck.h
index 733378f126..f70d11c559 100644
--- a/fsck.h
+++ b/fsck.h
@@ -109,7 +109,6 @@ const char *fsck_describe_object(struct fsck_options *options,
* git_config() callback for use by fsck-y tools that want to support
* fsck.<msg> fsck.skipList etc.
*/
-int fsck_config_internal(const char *var, const char *value, void *cb,
- struct fsck_options *options);
+int git_fsck_config(const char *var, const char *value, void *cb);
#endif
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (2 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 01/19] fsck.c: refactor and rename common config callback Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 03/19] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
` (16 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use
designated initializers.
While I'm at it add the "object_names" member to the
initialization. This was omitted in 7b35efd734e (fsck_walk():
optionally name objects on the go, 2016-07-17) when the field was
added.
I'm using a new FSCK_OPTIONS_COMMON and FSCK_OPTIONS_COMMON_ERROR_FUNC
helper macros to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in
common, and define the two in terms of those macro.
The FSCK_OPTIONS_COMMON macro will be used in a subsequent commit to
define other variants of common fsck initialization that wants to use
a custom error function, but share the rest of the defaults.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index f70d11c559..15e12f292f 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,17 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
+#define FSCK_OPTIONS_COMMON \
+ .walk = NULL, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
+ .object_names = NULL,
+#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
+ FSCK_OPTIONS_COMMON \
+ .error_func = fsck_error_function
+
+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
/* descend in all linked child objects
* the return value is:
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 03/19] fsck.h: use "enum object_type" instead of "int"
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (3 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
` (15 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
355885d5315 (add generic, type aware object chain walker, 2008-02-25)
we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is
concerned, it just gives the compiler more information and makes this
easier to read.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 3 ++-
builtin/index-pack.c | 3 ++-
builtin/unpack-objects.c | 3 ++-
fsck.h | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index a56a2d0513..ed5f2af6b5 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -192,7 +192,8 @@ static int traverse_reachable(void)
return !!result;
}
-static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_used(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return 1;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bad5748807..69f24fe9f7 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -212,7 +212,8 @@ static void cleanup_thread(void)
free(thread_data);
}
-static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_link(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return -1;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index dd4a75e030..ca54fd1668 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -187,7 +187,8 @@ 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, struct fsck_options *options)
+static int check_object(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
struct obj_buffer *obj_buf;
diff --git a/fsck.h b/fsck.h
index 15e12f292f..e3edaff8e7 100644
--- a/fsck.h
+++ b/fsck.h
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);
* <0 error signaled and abort
* >0 error signaled and do not abort
*/
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
+typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options);
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (4 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 03/19] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 05/19] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
` (14 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename variables in a function added in 0282f4dced0 (fsck: offer a
function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and
"msg_id" to "msg_id_str" etc. This will make a follow-up change
smaller.
While I'm at it properly indent the fsck_set_msg_type() argument list.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 24 ++++++++++++------------
fsck.h | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/fsck.c b/fsck.c
index 5dfb99665a..7cc722a25c 100644
--- a/fsck.c
+++ b/fsck.c
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
+ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
- if (id < 0)
- die("Unhandled message id: %s", msg_id);
- type = parse_msg_type(msg_type);
+ if (msg_id < 0)
+ die("Unhandled message id: %s", msg_id_str);
+ msg_type = parse_msg_type(msg_type_str);
- if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
- die("Cannot demote %s to %s", msg_id, msg_type);
+ if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
+ die("Cannot demote %s to %s", msg_id_str, msg_type_str);
if (!options->msg_type) {
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
+ int *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
}
- options->msg_type[id] = type;
+ options->msg_type[msg_id] = msg_type;
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index e3edaff8e7..12ff99b56e 100644
--- a/fsck.h
+++ b/fsck.h
@@ -11,7 +11,7 @@ struct fsck_options;
struct object;
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type);
+ const char *msg_id, const char *msg_type);
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);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 05/19] fsck.c: move definition of msg_id into append_msg_id()
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (5 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
` (13 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor code added in 71ab8fa840f (fsck: report the ID of the
error/warning, 2015-06-22) to resolve the msg_id to a string in the
function that wants it, instead of doing it in report().
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index 7cc722a25c..ffb9115ddb 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
{
+ const char *msg_id = msg_id_info[id].id_string;
for (;;) {
char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
+ append_msg_id(&sb, id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (6 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 05/19] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
` (12 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename the remaining variables of type fsck_msg_id from "id" to
"msg_id". This change is relatively small, and is worth the churn for
a later change where we have different id's in the "report" function.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fsck.c b/fsck.c
index ffb9115ddb..a9a8783aeb 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id)
{
- const char *msg_id = msg_id_info[id].id_string;
+ const char *msg_id_str = msg_id_info[msg_id].id_string;
for (;;) {
- char c = *(msg_id)++;
+ char c = *(msg_id_str)++;
if (!c)
break;
if (c != '_')
strbuf_addch(sb, tolower(c));
else {
- assert(*msg_id);
- strbuf_addch(sb, *(msg_id)++);
+ assert(*msg_id_str);
+ strbuf_addch(sb, *(msg_id_str)++);
}
}
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_id id, const char *fmt, ...)
+ enum fsck_msg_id msg_id, const char *fmt, ...)
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(id, options), result;
+ int msg_type = fsck_msg_type(msg_id, options), result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, id);
+ append_msg_id(&sb, msg_id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (7 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
` (11 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor "if options->msg_type" and other code added in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit,
only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type()
function (also added in 0282f4dced0), which does a similar check for
"!options->msg_type". Another minor benefit is getting rid of the
style violation of not having braces for the body of the "if".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fsck.c b/fsck.c
index a9a8783aeb..2f23255f99 100644
--- a/fsck.c
+++ b/fsck.c
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
static int fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
- int msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
- if (options->msg_type)
- msg_type = options->msg_type[msg_id];
- else {
- msg_type = msg_id_info[msg_id].msg_type;
+ if (!options->msg_type) {
+ int msg_type = msg_id_info[msg_id].msg_type;
+
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
+ return msg_type;
}
- return msg_type;
+ return options->msg_type[msg_id];
}
static int parse_msg_type(const char *str)
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (8 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
` (10 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to
fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings,
2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues
completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors,
2015-06-22)
The reason these were defined in two different places is because we
use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
used by external callbacks.
Untangling that would take some more work, since we expose the new
"enum fsck_msg_type" to both. Similar to "enum object_type" it's not
worth structuring the API in such a way that only those who need
FSCK_{ERROR,WARN} pass around a different type.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 2 +-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 3 ++-
fsck.c | 21 ++++++++++-----------
fsck.h | 16 ++++++++++------
5 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ed5f2af6b5..17940a4e24 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 69f24fe9f7..56b8efaa89 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)
static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
/*
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 23c4b8763f..052a510ad7 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/fsck.c b/fsck.c
index 2f23255f99..e1e942821d 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,9 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FSCK_FATAL -1
-#define FSCK_INFO -2
-
#define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {
const char *id_string;
const char *downcased;
const char *camelcased;
- int msg_type;
+ enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
FOREACH_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
list_config_item(list, prefix, msg_id_info[i].camelcased);
}
-static int fsck_msg_type(enum fsck_msg_id msg_id,
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
if (!options->msg_type) {
- int msg_type = msg_id_info[msg_id].msg_type;
+ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
+static enum fsck_msg_type parse_msg_type(const char *str)
{
if (!strcmp(str, "error"))
return FSCK_ERROR;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
+ enum fsck_msg_type msg_type;
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
- int *severity;
+ enum fsck_msg_type *severity;
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
severity[i] = fsck_msg_type(i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options,
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(msg_id, options), result;
+ enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
+ int result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index 12ff99b56e..0fff04373e 100644
--- a/fsck.h
+++ b/fsck.h
@@ -3,9 +3,13 @@
#include "oidset.h"
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
+enum fsck_msg_type {
+ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
struct fsck_options;
struct object;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
struct fsck_options {
fsck_walk_func walk;
fsck_error error_func;
unsigned strict:1;
- int *msg_type;
+ enum fsck_msg_type *msg_type;
struct oidset skiplist;
kh_oid_map_t *object_names;
};
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type"
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (9 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
` (9 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the values in the "enum fsck_msg_type" from being manually
assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously
defined as "2".
I'm confident that nothing relies on these values, we always compare
them explicitly. Let's not omit "0" so it won't be assumed that we're
using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are
"private" v.s. "public". See the preceding commit for a rationale for
not simply splitting these into two enums, namely that this is used
for both the private and public fsck API.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fsck.h b/fsck.h
index 0fff04373e..25c456bbd3 100644
--- a/fsck.h
+++ b/fsck.h
@@ -4,11 +4,13 @@
#include "oidset.h"
enum fsck_msg_type {
- FSCK_INFO = -2,
- FSCK_FATAL = -1,
- FSCK_ERROR = 1,
+ /* for internal use only */
+ FSCK_IGNORE,
+ FSCK_INFO,
+ FSCK_FATAL,
+ /* "public", fed to e.g. error_func callbacks */
+ FSCK_ERROR,
FSCK_WARN,
- FSCK_IGNORE
};
struct fsck_options;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type()
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (10 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 11/19] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
` (8 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
There's no reason to defer the calling of parse_msg_type() until after
we've checked if the "id < 0". This is not a hot codepath, and
parse_msg_type() itself may die on invalid input.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index e1e942821d..341c482fed 100644
--- a/fsck.c
+++ b/fsck.c
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
+ enum fsck_msg_type msg_type = parse_msg_type(msg_type_str);
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
- msg_type = parse_msg_type(msg_type_str);
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 11/19] fsck.c: undefine temporary STR macro after use
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (11 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
` (7 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
In f417eed8cde (fsck: provide a function to parse fsck message IDs,
2015-06-22) the "STR" macro was introduced, but that short macro name
was not undefined after use as was done earlier in the same series for
the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck
messages, 2015-06-22).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fsck.c b/fsck.c
index 341c482fed..e657636a6f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -100,6 +100,7 @@ static struct {
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
+#undef STR
static void prepare_msg_ids(void)
{
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (12 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 11/19] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
` (6 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Rename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation
for moving it over to fsck.h. It's good convention to name macros
in *.h files in such a way as to clearly not clash with any other
names in other files.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fsck.c b/fsck.c
index e657636a6f..b64526ea35 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,7 +22,7 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_MSG_ID(FUNC) \
+#define FOREACH_FSCK_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
#define MSG_ID(id, msg_type) FSCK_MSG_##id,
enum fsck_msg_id {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
FSCK_MSG_MAX
};
#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {
const char *camelcased;
enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (13 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
` (5 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps
define from fsck.c to fsck.h. This is in preparation for having
non-static functions take the fsck_msg_id as an argument.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 66 ----------------------------------------------------------
fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 66 deletions(-)
diff --git a/fsck.c b/fsck.c
index b64526ea35..49208ec636 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,72 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_FSCK_MSG_ID(FUNC) \
- /* fatal errors */ \
- FUNC(NUL_IN_HEADER, FATAL) \
- FUNC(UNTERMINATED_HEADER, FATAL) \
- /* errors */ \
- FUNC(BAD_DATE, ERROR) \
- FUNC(BAD_DATE_OVERFLOW, ERROR) \
- FUNC(BAD_EMAIL, ERROR) \
- FUNC(BAD_NAME, ERROR) \
- FUNC(BAD_OBJECT_SHA1, ERROR) \
- FUNC(BAD_PARENT_SHA1, ERROR) \
- FUNC(BAD_TAG_OBJECT, ERROR) \
- FUNC(BAD_TIMEZONE, ERROR) \
- FUNC(BAD_TREE, ERROR) \
- FUNC(BAD_TREE_SHA1, ERROR) \
- FUNC(BAD_TYPE, ERROR) \
- FUNC(DUPLICATE_ENTRIES, ERROR) \
- FUNC(MISSING_AUTHOR, ERROR) \
- FUNC(MISSING_COMMITTER, ERROR) \
- FUNC(MISSING_EMAIL, ERROR) \
- FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_OBJECT, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_TAG, ERROR) \
- FUNC(MISSING_TAG_ENTRY, ERROR) \
- FUNC(MISSING_TREE, ERROR) \
- FUNC(MISSING_TREE_OBJECT, ERROR) \
- FUNC(MISSING_TYPE, ERROR) \
- FUNC(MISSING_TYPE_ENTRY, ERROR) \
- FUNC(MULTIPLE_AUTHORS, ERROR) \
- FUNC(TREE_NOT_SORTED, ERROR) \
- FUNC(UNKNOWN_TYPE, ERROR) \
- FUNC(ZERO_PADDED_DATE, ERROR) \
- FUNC(GITMODULES_MISSING, ERROR) \
- FUNC(GITMODULES_BLOB, ERROR) \
- FUNC(GITMODULES_LARGE, ERROR) \
- FUNC(GITMODULES_NAME, ERROR) \
- FUNC(GITMODULES_SYMLINK, ERROR) \
- FUNC(GITMODULES_URL, ERROR) \
- FUNC(GITMODULES_PATH, ERROR) \
- FUNC(GITMODULES_UPDATE, ERROR) \
- /* warnings */ \
- FUNC(BAD_FILEMODE, WARN) \
- FUNC(EMPTY_NAME, WARN) \
- FUNC(FULL_PATHNAME, WARN) \
- FUNC(HAS_DOT, WARN) \
- FUNC(HAS_DOTDOT, WARN) \
- FUNC(HAS_DOTGIT, WARN) \
- FUNC(NULL_SHA1, WARN) \
- FUNC(ZERO_PADDED_FILEMODE, WARN) \
- FUNC(NUL_IN_COMMIT, WARN) \
- /* infos (reported as warnings, but ignored by default) */ \
- FUNC(GITMODULES_PARSE, INFO) \
- FUNC(BAD_TAG_NAME, INFO) \
- FUNC(MISSING_TAGGER_ENTRY, INFO) \
- /* ignored (elevated when requested) */ \
- FUNC(EXTRA_HEADER_ENTRY, IGNORE)
-
-#define MSG_ID(id, msg_type) FSCK_MSG_##id,
-enum fsck_msg_id {
- FOREACH_FSCK_MSG_ID(MSG_ID)
- FSCK_MSG_MAX
-};
-#undef MSG_ID
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
diff --git a/fsck.h b/fsck.h
index 25c456bbd3..7c868410eb 100644
--- a/fsck.h
+++ b/fsck.h
@@ -13,6 +13,72 @@ enum fsck_msg_type {
FSCK_WARN,
};
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \
+ FUNC(UNTERMINATED_HEADER, FATAL) \
+ /* errors */ \
+ FUNC(BAD_DATE, ERROR) \
+ FUNC(BAD_DATE_OVERFLOW, ERROR) \
+ FUNC(BAD_EMAIL, ERROR) \
+ FUNC(BAD_NAME, ERROR) \
+ FUNC(BAD_OBJECT_SHA1, ERROR) \
+ FUNC(BAD_PARENT_SHA1, ERROR) \
+ FUNC(BAD_TAG_OBJECT, ERROR) \
+ FUNC(BAD_TIMEZONE, ERROR) \
+ FUNC(BAD_TREE, ERROR) \
+ FUNC(BAD_TREE_SHA1, ERROR) \
+ FUNC(BAD_TYPE, ERROR) \
+ FUNC(DUPLICATE_ENTRIES, ERROR) \
+ FUNC(MISSING_AUTHOR, ERROR) \
+ FUNC(MISSING_COMMITTER, ERROR) \
+ FUNC(MISSING_EMAIL, ERROR) \
+ FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_OBJECT, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_TAG, ERROR) \
+ FUNC(MISSING_TAG_ENTRY, ERROR) \
+ FUNC(MISSING_TREE, ERROR) \
+ FUNC(MISSING_TREE_OBJECT, ERROR) \
+ FUNC(MISSING_TYPE, ERROR) \
+ FUNC(MISSING_TYPE_ENTRY, ERROR) \
+ FUNC(MULTIPLE_AUTHORS, ERROR) \
+ FUNC(TREE_NOT_SORTED, ERROR) \
+ FUNC(UNKNOWN_TYPE, ERROR) \
+ FUNC(ZERO_PADDED_DATE, ERROR) \
+ FUNC(GITMODULES_MISSING, ERROR) \
+ FUNC(GITMODULES_BLOB, ERROR) \
+ FUNC(GITMODULES_LARGE, ERROR) \
+ FUNC(GITMODULES_NAME, ERROR) \
+ FUNC(GITMODULES_SYMLINK, ERROR) \
+ FUNC(GITMODULES_URL, ERROR) \
+ FUNC(GITMODULES_PATH, ERROR) \
+ FUNC(GITMODULES_UPDATE, ERROR) \
+ /* warnings */ \
+ FUNC(BAD_FILEMODE, WARN) \
+ FUNC(EMPTY_NAME, WARN) \
+ FUNC(FULL_PATHNAME, WARN) \
+ FUNC(HAS_DOT, WARN) \
+ FUNC(HAS_DOTDOT, WARN) \
+ FUNC(HAS_DOTGIT, WARN) \
+ FUNC(NULL_SHA1, WARN) \
+ FUNC(ZERO_PADDED_FILEMODE, WARN) \
+ FUNC(NUL_IN_COMMIT, WARN) \
+ /* infos (reported as warnings, but ignored by default) */ \
+ FUNC(GITMODULES_PARSE, INFO) \
+ FUNC(BAD_TAG_NAME, INFO) \
+ FUNC(MISSING_TAGGER_ENTRY, INFO) \
+ /* ignored (elevated when requested) */ \
+ FUNC(EXTRA_HEADER_ENTRY, IGNORE)
+
+#define MSG_ID(id, msg_type) FSCK_MSG_##id,
+enum fsck_msg_id {
+ FOREACH_FSCK_MSG_ID(MSG_ID)
+ FSCK_MSG_MAX
+};
+#undef MSG_ID
+
struct fsck_options;
struct object;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (14 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
` (4 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the fsck_error callback to also pass along the
fsck_msg_id. Before this change the only way to get the message id was
to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might
want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back
from the msg_id, but I'm not changing that convention. It's really
common to need the msg_type, and the report() function itself (which
calls "fsck_error") needs to call fsck_msg_type() to discover
it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 4 +++-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 1 +
fsck.c | 6 ++++--
fsck.h | 6 ++++--
5 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 17940a4e24..70ff95837a 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 56b8efaa89..2b2266a4b7 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
printf("%s\n", oid_to_hex(oid));
return 0;
}
- return fsck_error_function(o, oid, object_type, msg_type, message);
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
}
int cmd_index_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 052a510ad7..96e63bc772 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
switch (msg_type) {
diff --git a/fsck.c b/fsck.c
index 49208ec636..01b2724ac0 100644
--- a/fsck.c
+++ b/fsck.c
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(options, oid, object_type,
- msg_type, sb.buf);
+ msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index 7c868410eb..80b1984f34 100644
--- a/fsck.h
+++ b/fsck.h
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
struct fsck_options {
fsck_walk_func walk;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (15 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
` (3 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change code I added in acf9de4c94e (mktag: use fsck instead of custom
verify_tag(), 2021-01-05) to make use of a new API function that takes
the fsck_msg_{id,type} types, instead of arbitrary strings that
we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) it was only intended to be used to parse user-supplied
data.
For things that are purely internal to the C code it makes sense to
have the compiler check these arguments, and to skip the sanity
checking of the data in fsck_set_msg_type() which is redundant to
checks we get from the compiler.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/mktag.c | 3 ++-
fsck.c | 27 +++++++++++++++++----------
fsck.h | 3 +++
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 96e63bc772..dddcccdd36 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
die_errno(_("could not read from stdin"));
fsck_options.error_func = mktag_fsck_error_func;
- fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
git_config(git_fsck_config, &fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
diff --git a/fsck.c b/fsck.c
index 01b2724ac0..307d454d92 100644
--- a/fsck.c
+++ b/fsck.c
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
return 1;
}
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type)
+{
+ if (!options->msg_type) {
+ int i;
+ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
+}
+
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
- if (!options->msg_type) {
- int i;
- enum fsck_msg_type *severity;
- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
- severity[i] = fsck_msg_type(i, options);
- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;
+ fsck_set_msg_type_from_ids(options, msg_id, msg_type);
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index 80b1984f34..344c3ddc74 100644
--- a/fsck.h
+++ b/fsck.h
@@ -82,6 +82,9 @@ enum fsck_msg_id {
struct fsck_options;
struct object;
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type);
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id, const char *msg_type);
void fsck_set_msg_types(struct fsck_options *options, const char *values);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 16/19] fsck.c: move gitmodules_{found,done} into fsck_options
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (16 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 17/19] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
` (2 subsequent siblings)
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Move the gitmodules_{found,done} static variables added in
159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the
fsck_options struct. It makes sense to keep all the context in the
same place.
This requires changing the recently added register_found_gitmodules()
function added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) to take fsck_options. That function will be
removed in a subsequent commit, but as it'll require the new
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 2 +-
fsck.c | 23 ++++++++++-------------
fsck.h | 7 ++++++-
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 6a61a46428..82c3c2c043 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(oid);
+ register_found_gitmodules(&fo, oid);
if (fsck_finish(&fo))
die("fsck failed");
}
diff --git a/fsck.c b/fsck.c
index 307d454d92..00760b1f42 100644
--- a/fsck.c
+++ b/fsck.c
@@ -19,9 +19,6 @@
#include "credential.h"
#include "help.h"
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options,
oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid,
has_dotgit |= is_ntfs_dotgit(backslash);
if (is_ntfs_dotgitmodules(backslash)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options, oid, OBJ_TREE,
FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
struct fsck_gitmodules_data data;
struct config_options config_opts = { 0 };
- if (!oidset_contains(&gitmodules_found, oid))
+ if (!oidset_contains(&options->gitmodules_found, oid))
return 0;
- oidset_insert(&gitmodules_done, oid);
+ oidset_insert(&options->gitmodules_done, oid);
if (object_on_skiplist(options, oid))
return 0;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(const struct object_id *oid)
+void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
{
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
}
int fsck_finish(struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
- oidset_iter_init(&gitmodules_found, &iter);
+ oidset_iter_init(&options->gitmodules_found, &iter);
while ((oid = oidset_iter_next(&iter))) {
enum object_type type;
unsigned long size;
char *buf;
- if (oidset_contains(&gitmodules_done, oid))
+ if (oidset_contains(&options->gitmodules_done, oid))
continue;
buf = read_object_file(oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options)
}
- oidset_clear(&gitmodules_found);
- oidset_clear(&gitmodules_done);
+ oidset_clear(&options->gitmodules_found);
+ oidset_clear(&options->gitmodules_done);
return ret;
}
diff --git a/fsck.h b/fsck.h
index 344c3ddc74..b25ae9d8b9 100644
--- a/fsck.h
+++ b/fsck.h
@@ -118,6 +118,8 @@ struct fsck_options {
unsigned strict:1;
enum fsck_msg_type *msg_type;
struct oidset skiplist;
+ struct oidset gitmodules_found;
+ struct oidset gitmodules_done;
kh_oid_map_t *object_names;
};
@@ -125,6 +127,8 @@ struct fsck_options {
.walk = NULL, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
.object_names = NULL,
#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(const struct object_id *oid);
+void register_found_gitmodules(struct fsck_options *options,
+ const struct object_id *oid);
/*
* fsck a tag, and pass info about it back to the caller. This is
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 17/19] fetch-pack: don't needlessly copy fsck_options
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (17 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 18/19] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 19/19] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change the behavior of the .gitmodules validation added in
5476e1efde (fetch-pack: print and use dangling .gitmodules,
2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting
up the error_func earlier means that we're relying on the "error_func"
not being set in some code in between the two hunks being modified
here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is
further setup by calling fsck_set_msg_types(), and assigning to
do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the
fsck_options struct before setting error_func. Let's just do this
setup at the top of the function, along with the "walk" assignment.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2b2266a4b7..5ad80b85b4 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
+ fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
else
close(input_fd);
- if (do_fsck_object) {
- struct fsck_options fo = fsck_options;
-
- fo.error_func = print_dangling_gitmodules;
- if (fsck_finish(&fo))
- die(_("fsck error in pack objects"));
- }
+ if (do_fsck_object && fsck_finish(&fsck_options))
+ die(_("fsck error in pack objects"));
free(objects);
strbuf_release(&index_name_buf);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 18/19] fetch-pack: use file-scope static struct for fsck_options
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (18 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 17/19] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:20 ` [PATCH v5 19/19] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Change code added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) so that we use a file-scoped "static struct
fsck_options" instead of defining one in the "fsck_gitmodules_oids()"
function.
We use this pattern in all of
builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see
fetch-pack be the odd one out. One might think that we're using other
fsck_options structs in fetch-pack, or doing on fsck twice there, but
we're not.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 82c3c2c043..229fd8e2c2 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,6 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
{
struct oidset_iter iter;
const struct object_id *oid;
- struct fsck_options fo = FSCK_OPTIONS_STRICT;
if (!oidset_size(gitmodules_oids))
return;
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fo, oid);
- if (fsck_finish(&fo))
+ register_found_gitmodules(&fsck_options, oid);
+ if (fsck_finish(&fsck_options))
die("fsck failed");
}
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v5 19/19] fetch-pack: use new fsck API to printing dangling submodules
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
` (19 preceding siblings ...)
2021-03-17 18:20 ` [PATCH v5 18/19] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:20 ` Ævar Arnfjörð Bjarmason
20 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 18:20 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Derrick Stolee, Ævar Arnfjörð Bjarmason
Refactor the check added in 5476e1efde (fetch-pack: print and use
dangling .gitmodules, 2021-02-22) to make use of us now passing the
"msg_id" to the user defined "error_func". We can now compare against
the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
message.
Let's also replace register_found_gitmodules() with directly
manipulating the "gitmodules_found" member. A recent commit moved it
into "fsck_options" so we could do this here.
I'm sticking this callback in fsck.c. Perhaps in the future we'd like
to accumulate such callbacks into another file (maybe fsck-cb.c,
similar to parse-options-cb.c?), but while we've got just the one
let's just put it into fsck.c.
A better alternative in this case would be some library some more
obvious library shared by fetch-pack.c ad builtin/index-pack.c, but
there isn't such a thing.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 21 +--------------------
fetch-pack.c | 4 ++--
fsck.c | 23 ++++++++++++++++++-----
fsck.h | 18 +++++++++++++++---
4 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5ad80b85b4..11f0fafd33 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -120,7 +120,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 struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static int verbose;
static int show_resolving_progress;
static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only)
}
}
-static int print_dangling_gitmodules(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
- const char *message)
-{
- /*
- * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
- * instead of relying on this string check.
- */
- if (starts_with(message, "gitmodulesMissing")) {
- printf("%s\n", oid_to_hex(oid));
- return 0;
- }
- return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
-}
-
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
- fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
diff --git a/fetch-pack.c b/fetch-pack.c
index 229fd8e2c2..008a3facd4 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,7 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
+ oidset_insert(&fsck_options.gitmodules_found, oid);
if (fsck_finish(&fsck_options))
die("fsck failed");
}
diff --git a/fsck.c b/fsck.c
index 00760b1f42..048cf81937 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
-{
- oidset_insert(&options->gitmodules_found, oid);
-}
-
int fsck_finish(struct fsck_options *options)
{
int ret = 0;
@@ -1284,3 +1279,21 @@ int git_fsck_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
+
+/*
+ * Custom error callbacks that are used in more than one place.
+ */
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
+{
+ if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
+ puts(oid_to_hex(oid));
+ return 0;
+ }
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
diff --git a/fsck.h b/fsck.h
index b25ae9d8b9..da58f585d7 100644
--- a/fsck.h
+++ b/fsck.h
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(struct fsck_options *options,
- const struct object_id *oid);
-
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
@@ -203,4 +200,19 @@ const char *fsck_describe_object(struct fsck_options *options,
*/
int git_fsck_config(const char *var, const char *value, void *cb);
+/*
+ * Custom error callbacks that are used in more than one place.
+ */
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ FSCK_OPTIONS_COMMON \
+}
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message);
+
#endif
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
2021-03-07 23:04 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 " Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:35 ` Junio C Hamano
2021-03-19 14:43 ` Johannes Schindelin
2021-03-16 16:17 ` [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (20 subsequent siblings)
23 siblings, 2 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Add the object_name member to the initialization macro. This was
omitted in 7b35efd734e (fsck_walk(): optionally name objects on the
go, 2016-07-17) when the field was added.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index 733378f126..2274843ba0 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,8 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
/* descend in all linked child objects
* the return value is:
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-03-16 16:17 ` [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:35 ` Junio C Hamano
2021-03-19 14:43 ` Johannes Schindelin
1 sibling, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:35 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Add the object_name member to the initialization macro. This was
> omitted in 7b35efd734e (fsck_walk(): optionally name objects on the
> go, 2016-07-17) when the field was added.
While this does not hurt, as the missing one was and is at the end
of the struct members, this has no effect. As you'll be rewriting
everything into designated initializers anyway, does it matter, I
have to wonder (it would affect your commit count karma, but you
already have enough of them ;-)?
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fsck.h b/fsck.h
> index 733378f126..2274843ba0 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -43,8 +43,8 @@ struct fsck_options {
> kh_oid_map_t *object_names;
> };
>
> -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
> -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
> +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
> +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
>
> /* descend in all linked child objects
> * the return value is:
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-03-16 16:17 ` [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
2021-03-17 18:35 ` Junio C Hamano
@ 2021-03-19 14:43 ` Johannes Schindelin
2021-03-20 9:16 ` Ævar Arnfjörð Bjarmason
1 sibling, 1 reply; 229+ messages in thread
From: Johannes Schindelin @ 2021-03-19 14:43 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Junio C Hamano, Jeff King, Jonathan Tan
[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]
Hi Ævar,
just a general note: this patch, which is the first of v4, is marked as
replying to the cover letter of v3. That feels quite odd. If you use
threading, why not let it reply to the cover letter of the same patch
series iteration?
In other words, would you mind using the `--thread=shallow` option in the
future, for better structuring on the mailing list?
Thanks,
Johannes
On Tue, 16 Mar 2021, Ævar Arnfjörð Bjarmason wrote:
> Add the object_name member to the initialization macro. This was
> omitted in 7b35efd734e (fsck_walk(): optionally name objects on the
> go, 2016-07-17) when the field was added.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fsck.h b/fsck.h
> index 733378f126..2274843ba0 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -43,8 +43,8 @@ struct fsck_options {
> kh_oid_map_t *object_names;
> };
>
> -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
> -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
> +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
> +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
>
> /* descend in all linked child objects
> * the return value is:
> --
> 2.31.0.260.g719c683c1d
>
>
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-03-19 14:43 ` Johannes Schindelin
@ 2021-03-20 9:16 ` Ævar Arnfjörð Bjarmason
2021-03-20 20:04 ` Junio C Hamano
0 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-20 9:16 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Junio C Hamano, Jeff King, Jonathan Tan
On Fri, Mar 19 2021, Johannes Schindelin wrote:
> Hi Ævar,
>
> just a general note: this patch, which is the first of v4, is marked as
> replying to the cover letter of v3. That feels quite odd. If you use
> threading, why not let it reply to the cover letter of the same patch
> series iteration?
>
> In other words, would you mind using the `--thread=shallow` option in the
> future, for better structuring on the mailing list?
Not at all, I've set it in my config now.
I've just been using the default configuration of format-patch
--in-reply-to --cover-letter && send-email *.patch all this time.
Looking around at other patch submissions (aside from GGG) this seems to
be the norm though, but isn't documented in SubmittingPatches
etc. AFAICT.
So I wonder if I'm using some different process from the norm, or if
most everyone else is just looking carefully at Message-ID/In-Reply-To
norms before sending...
> On Tue, 16 Mar 2021, Ævar Arnfjörð Bjarmason wrote:
>
>> Add the object_name member to the initialization macro. This was
>> omitted in 7b35efd734e (fsck_walk(): optionally name objects on the
>> go, 2016-07-17) when the field was added.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>> fsck.h | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fsck.h b/fsck.h
>> index 733378f126..2274843ba0 100644
>> --- a/fsck.h
>> +++ b/fsck.h
>> @@ -43,8 +43,8 @@ struct fsck_options {
>> kh_oid_map_t *object_names;
>> };
>>
>> -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
>> -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
>> +#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
>> +#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
>>
>> /* descend in all linked child objects
>> * the return value is:
>> --
>> 2.31.0.260.g719c683c1d
>>
>>
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-03-20 9:16 ` Ævar Arnfjörð Bjarmason
@ 2021-03-20 20:04 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-20 20:04 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: Johannes Schindelin, git, Jeff King, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>> In other words, would you mind using the `--thread=shallow` option in the
>> future, for better structuring on the mailing list?
>
> Not at all, I've set it in my config now.
>
> I've just been using the default configuration of format-patch
> --in-reply-to --cover-letter && send-email *.patch all this time.
> ...
> So I wonder if I'm using some different process from the norm, or if
> most everyone else is just looking carefully at Message-ID/In-Reply-To
> norms before sending...
Interesting. I always let send-email assign the message IDs and
haven't used --thread=<any> option at all. In other words, my
format-patch output files have no message IDs in them or In-reply-to
header fields. That in turn means that in-reply-to is decided not
when format-patch is run, but when send-email sends things out, it
gives them the ids and structures the in-reply-to chains.
I guess we have too much flexibility in our tooling X-<.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (2 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 18:59 ` Derrick Stolee
2021-03-17 18:38 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (19 subsequent siblings)
23 siblings, 2 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index 2274843ba0..40f3cb3f64 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,22 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_DEFAULT { \
+ .walk = NULL, \
+ .error_func = fsck_error_function, \
+ .strict = 0, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
+ .object_names = NULL, \
+}
+#define FSCK_OPTIONS_STRICT { \
+ .walk = NULL, \
+ .error_func = fsck_error_function, \
+ .strict = 1, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
+ .object_names = NULL, \
+}
/* descend in all linked child objects
* the return value is:
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-16 16:17 ` [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-16 18:59 ` Derrick Stolee
2021-03-17 18:38 ` Junio C Hamano
1 sibling, 0 replies; 229+ messages in thread
From: Derrick Stolee @ 2021-03-16 18:59 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason, git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.h | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/fsck.h b/fsck.h
> index 2274843ba0..40f3cb3f64 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -43,8 +43,22 @@ struct fsck_options {
> kh_oid_map_t *object_names;
> };
>
> -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
> -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
You just edited these lines in the previous patch. Seems unnecesary
to split them. You can point out that the object_names portion was
previously excluded in the message here.
> +#define FSCK_OPTIONS_DEFAULT { \
> + .walk = NULL, \
> + .error_func = fsck_error_function, \
> + .strict = 0, \
> + .msg_type = NULL, \
> + .skiplist = OIDSET_INIT, \
> + .object_names = NULL, \
> +}
> +#define FSCK_OPTIONS_STRICT { \
> + .walk = NULL, \
> + .error_func = fsck_error_function, \
> + .strict = 1, \
> + .msg_type = NULL, \
> + .skiplist = OIDSET_INIT, \
> + .object_names = NULL, \
> +}
This explicit definition is better.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-16 16:17 ` [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
2021-03-16 18:59 ` Derrick Stolee
@ 2021-03-17 18:38 ` Junio C Hamano
1 sibling, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:38 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.h | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/fsck.h b/fsck.h
> index 2274843ba0..40f3cb3f64 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -43,8 +43,22 @@ struct fsck_options {
> kh_oid_map_t *object_names;
> };
>
> -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
> -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
> +#define FSCK_OPTIONS_DEFAULT { \
> + .walk = NULL, \
> + .error_func = fsck_error_function, \
> + .strict = 0, \
> + .msg_type = NULL, \
> + .skiplist = OIDSET_INIT, \
> + .object_names = NULL, \
> +}
> +#define FSCK_OPTIONS_STRICT { \
> + .walk = NULL, \
> + .error_func = fsck_error_function, \
> + .strict = 1, \
> + .msg_type = NULL, \
> + .skiplist = OIDSET_INIT, \
> + .object_names = NULL, \
> +}
Being explicit is good, but spelling out zero initialization sounds
more like cluttering than clarifying. I do not mind .strict = 0 in
the DEFAULT one only because it contrasts well with .strict = 1 on
the STRICT side, but it would be easier to read to omit these zero
initilization of the .walk, .msg_type and .object_names members.
> /* descend in all linked child objects
> * the return value is:
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (3 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro Ævar Arnfjörð Bjarmason
` (18 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Use a temporary macro to define what FSCK_OPTIONS_{DEFAULT,STRICT}
have in common, and define the two in terms of that macro.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/fsck.h b/fsck.h
index 40f3cb3f64..ea3a907ec3 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,22 +43,14 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { \
+#define FSCK_OPTIONS_COMMON \
.walk = NULL, \
.error_func = fsck_error_function, \
- .strict = 0, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
- .object_names = NULL, \
-}
-#define FSCK_OPTIONS_STRICT { \
- .walk = NULL, \
- .error_func = fsck_error_function, \
- .strict = 1, \
- .msg_type = NULL, \
- .skiplist = OIDSET_INIT, \
- .object_names = NULL, \
-}
+ .object_names = NULL,
+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON }
+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }
/* descend in all linked child objects
* the return value is:
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (4 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 19:06 ` Derrick Stolee
2021-03-16 16:17 ` [PATCH v4 05/22] fsck.h: indent arguments to of fsck_set_msg_type Ævar Arnfjörð Bjarmason
` (17 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro for those that would like
to use FSCK_OPTIONS_COMMON in their own initialization, but supply
their own error functions.
Nothing is being changed to use this yet, but in some subsequent
commits we'll make use of this macro.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fsck.h b/fsck.h
index ea3a907ec3..dc35924cbf 100644
--- a/fsck.h
+++ b/fsck.h
@@ -45,12 +45,15 @@ struct fsck_options {
#define FSCK_OPTIONS_COMMON \
.walk = NULL, \
- .error_func = fsck_error_function, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
.object_names = NULL,
-#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON }
-#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }
+#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
+ FSCK_OPTIONS_COMMON \
+ .error_func = fsck_error_function
+
+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
/* descend in all linked child objects
* the return value is:
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
2021-03-16 16:17 ` [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro Ævar Arnfjörð Bjarmason
@ 2021-03-16 19:06 ` Derrick Stolee
0 siblings, 0 replies; 229+ messages in thread
From: Derrick Stolee @ 2021-03-16 19:06 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason, git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
> Add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro for those that would like
> to use FSCK_OPTIONS_COMMON in their own initialization, but supply
> their own error functions.
>
> Nothing is being changed to use this yet, but in some subsequent
> commits we'll make use of this macro.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.h | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fsck.h b/fsck.h
> index ea3a907ec3..dc35924cbf 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -45,12 +45,15 @@ struct fsck_options {
>
> #define FSCK_OPTIONS_COMMON \
> .walk = NULL, \
> - .error_func = fsck_error_function, \
> .msg_type = NULL, \
> .skiplist = OIDSET_INIT, \
> .object_names = NULL,
> -#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON }
> -#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }
> +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
> + FSCK_OPTIONS_COMMON \
> + .error_func = fsck_error_function
> +
> +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
> +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
OK. It seems like you are converging on your final definitions
for these macros. At first glance, this seems like unnecessary
split to demonstrate the tiny changes between, but it could
just be done with one change and a description of why you want
the four different entry points as macros.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 05/22] fsck.h: indent arguments to of fsck_set_msg_type
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (5 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 06/22] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
` (16 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fsck.h b/fsck.h
index dc35924cbf..5e488cef6b 100644
--- a/fsck.h
+++ b/fsck.h
@@ -11,7 +11,7 @@ struct fsck_options;
struct object;
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type);
+ const char *msg_id, const char *msg_type);
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);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 06/22] fsck.h: use "enum object_type" instead of "int"
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (6 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 05/22] fsck.h: indent arguments to of fsck_set_msg_type Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
` (15 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
355885d5315 (add generic, type aware object chain walker, 2008-02-25)
we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is
concerned, it just gives the compiler more information and makes this
easier to read.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 3 ++-
builtin/index-pack.c | 3 ++-
builtin/unpack-objects.c | 3 ++-
fsck.h | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 821e7798c7..68f0329e69 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -197,7 +197,8 @@ static int traverse_reachable(void)
return !!result;
}
-static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_used(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return 1;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bad5748807..69f24fe9f7 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -212,7 +212,8 @@ static void cleanup_thread(void)
free(thread_data);
}
-static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_link(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return -1;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index dd4a75e030..ca54fd1668 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -187,7 +187,8 @@ 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, struct fsck_options *options)
+static int check_object(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
struct obj_buffer *obj_buf;
diff --git a/fsck.h b/fsck.h
index 5e488cef6b..f67edd8f1f 100644
--- a/fsck.h
+++ b/fsck.h
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);
* <0 error signaled and abort
* >0 error signaled and do not abort
*/
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
+typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options);
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (7 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 06/22] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
` (14 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename variables in a function added in 0282f4dced0 (fsck: offer a
function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and
"msg_id" to "msg_id_str" etc. This will make a follow-up change
smaller.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/fsck.c b/fsck.c
index e3030f3b35..0a9ac9ca07 100644
--- a/fsck.c
+++ b/fsck.c
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
+ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
- if (id < 0)
- die("Unhandled message id: %s", msg_id);
- type = parse_msg_type(msg_type);
+ if (msg_id < 0)
+ die("Unhandled message id: %s", msg_id_str);
+ msg_type = parse_msg_type(msg_type_str);
- if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
- die("Cannot demote %s to %s", msg_id, msg_type);
+ if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
+ die("Cannot demote %s to %s", msg_id_str, msg_type_str);
if (!options->msg_type) {
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
+ int *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
}
- options->msg_type[id] = type;
+ options->msg_type[msg_id] = msg_type;
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id()
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (8 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:45 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
` (13 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor code added in 71ab8fa840f (fsck: report the ID of the
error/warning, 2015-06-22) to resolve the msg_id to a string in the
function that wants it, instead of doing it in report().
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index 0a9ac9ca07..b977493f57 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
{
+ const char *msg_id = msg_id_info[id].id_string;
for (;;) {
char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
+ append_msg_id(&sb, id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id()
2021-03-16 16:17 ` [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:45 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:45 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Refactor code added in 71ab8fa840f (fsck: report the ID of the
> error/warning, 2015-06-22) to resolve the msg_id to a string in the
> function that wants it, instead of doing it in report().
This reintroduces the same confusion 07/22 tried to get rid of,
unless msg_id variable is renamed to msg_id_str in this step,
instead of being left to the next step, no?
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fsck.c b/fsck.c
> index 0a9ac9ca07..b977493f57 100644
> --- a/fsck.c
> +++ b/fsck.c
> @@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
> free(to_free);
> }
>
> -static void append_msg_id(struct strbuf *sb, const char *msg_id)
> +static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
> {
> + const char *msg_id = msg_id_info[id].id_string;
> for (;;) {
> char c = *(msg_id)++;
>
> @@ -308,7 +309,7 @@ static int report(struct fsck_options *options,
> else if (msg_type == FSCK_INFO)
> msg_type = FSCK_WARN;
>
> - append_msg_id(&sb, msg_id_info[id].id_string);
> + append_msg_id(&sb, id);
>
> va_start(ap, fmt);
> strbuf_vaddf(&sb, fmt, ap);
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (9 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 08/22] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
` (12 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename the remaining variables of type fsck_msg_id from "id" to
"msg_id". This change is relatively small, and is worth the churn for
a later change where we have different id's in the "report" function.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fsck.c b/fsck.c
index b977493f57..6b72ddaa51 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id)
{
- const char *msg_id = msg_id_info[id].id_string;
+ const char *msg_id_str = msg_id_info[msg_id].id_string;
for (;;) {
- char c = *(msg_id)++;
+ char c = *(msg_id_str)++;
if (!c)
break;
if (c != '_')
strbuf_addch(sb, tolower(c));
else {
- assert(*msg_id);
- strbuf_addch(sb, *(msg_id)++);
+ assert(*msg_id_str);
+ strbuf_addch(sb, *(msg_id_str)++);
}
}
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_id id, const char *fmt, ...)
+ enum fsck_msg_id msg_id, const char *fmt, ...)
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(id, options), result;
+ int msg_type = fsck_msg_type(msg_id, options), result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, id);
+ append_msg_id(&sb, msg_id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (10 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
` (11 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor "if options->msg_type" and other code added in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit,
only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type()
function (also added in 0282f4dced0), which does a similar check for
"!options->msg_type". Another minor benefit is getting rid of the
style violation of not having braces for the body of the "if".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fsck.c b/fsck.c
index 6b72ddaa51..0988ab6579 100644
--- a/fsck.c
+++ b/fsck.c
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
static int fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
- int msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
- if (options->msg_type)
- msg_type = options->msg_type[msg_id];
- else {
- msg_type = msg_id_info[msg_id].msg_type;
+ if (!options->msg_type) {
+ int msg_type = msg_id_info[msg_id].msg_type;
+
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
+ return msg_type;
}
- return msg_type;
+ return options->msg_type[msg_id];
}
static int parse_msg_type(const char *str)
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (11 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:48 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
` (10 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to
fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings,
2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues
completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors,
2015-06-22)
The reason these were defined in two different places is because we
use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
used by external callbacks.
Untangling that would take some more work, since we expose the new
"enum fsck_msg_type" to both. Similar to "enum object_type" it's not
worth structuring the API in such a way that only those who need
FSCK_{ERROR,WARN} pass around a different type.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 2 +-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 3 ++-
fsck.c | 21 ++++++++++-----------
fsck.h | 16 ++++++++++------
5 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 68f0329e69..d6d745dc70 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 69f24fe9f7..56b8efaa89 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)
static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
/*
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 41a399a69e..1834394a9b 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/fsck.c b/fsck.c
index 0988ab6579..fb7d071bbf 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,9 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FSCK_FATAL -1
-#define FSCK_INFO -2
-
#define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {
const char *id_string;
const char *downcased;
const char *camelcased;
- int msg_type;
+ enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
FOREACH_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
list_config_item(list, prefix, msg_id_info[i].camelcased);
}
-static int fsck_msg_type(enum fsck_msg_id msg_id,
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
if (!options->msg_type) {
- int msg_type = msg_id_info[msg_id].msg_type;
+ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
+static enum fsck_msg_type parse_msg_type(const char *str)
{
if (!strcmp(str, "error"))
return FSCK_ERROR;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
+ enum fsck_msg_type msg_type;
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
- int *severity;
+ enum fsck_msg_type *severity;
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
severity[i] = fsck_msg_type(i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options,
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(msg_id, options), result;
+ enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
+ int result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index f67edd8f1f..2ecc15eee7 100644
--- a/fsck.h
+++ b/fsck.h
@@ -3,9 +3,13 @@
#include "oidset.h"
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
+enum fsck_msg_type {
+ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
struct fsck_options;
struct object;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
struct fsck_options {
fsck_walk_func walk;
fsck_error error_func;
unsigned strict:1;
- int *msg_type;
+ enum fsck_msg_type *msg_type;
struct oidset skiplist;
kh_oid_map_t *object_names;
};
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
2021-03-16 16:17 ` [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:48 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:48 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
> fsck_msg_type enum.
Nice.
> Untangling that would take some more work, since we expose the new
> "enum fsck_msg_type" to both. Similar to "enum object_type" it's not
> worth structuring the API in such a way that only those who need
> FSCK_{ERROR,WARN} pass around a different type.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type"
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (12 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:50 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
` (9 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the values in the "enum fsck_msg_type" from being manually
assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously
defined as "2".
I'm confident that nothing relies on these values, we always compare
them explicitly. Let's not omit "0" so it won't be assumed that we're
using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are
"private" v.s. "public". See the preceding commit for a rationale for
not simply splitting these into two enums, namely that this is used
for both the private and public fsck API.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fsck.h b/fsck.h
index 2ecc15eee7..fce9981a0c 100644
--- a/fsck.h
+++ b/fsck.h
@@ -4,11 +4,13 @@
#include "oidset.h"
enum fsck_msg_type {
- FSCK_INFO = -2,
- FSCK_FATAL = -1,
- FSCK_ERROR = 1,
+ /* for internal use only */
+ FSCK_IGNORE,
+ FSCK_INFO,
+ FSCK_FATAL,
+ /* "public", fed to e.g. error_func callbacks */
+ FSCK_ERROR,
FSCK_WARN,
- FSCK_IGNORE
};
struct fsck_options;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type"
2021-03-16 16:17 ` [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:50 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:50 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Change the values in the "enum fsck_msg_type" from being manually
> assigned to using default C enum values.
>
> This means we end up with a FSCK_IGNORE=0, which was previously
> defined as "2".
>
> I'm confident that nothing relies on these values, we always compare
> them explicitly. Let's not omit "0" so it won't be assumed that we're
> using these as a boolean somewhere.
Do you mean by "compare them explicitly", we always compare for
equality?
If the code had depended on constructs like "if (msg < FSCK_ERROR)",
this change would break badly.
> diff --git a/fsck.h b/fsck.h
> index 2ecc15eee7..fce9981a0c 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -4,11 +4,13 @@
> #include "oidset.h"
>
> enum fsck_msg_type {
> - FSCK_INFO = -2,
> - FSCK_FATAL = -1,
> - FSCK_ERROR = 1,
> + /* for internal use only */
> + FSCK_IGNORE,
> + FSCK_INFO,
> + FSCK_FATAL,
> + /* "public", fed to e.g. error_func callbacks */
> + FSCK_ERROR,
> FSCK_WARN,
> - FSCK_IGNORE
> };
>
> struct fsck_options;
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type()
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (13 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
` (8 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
There's no reason to defer the calling of parse_msg_type() until after
we've checked if the "id < 0". This is not a hot codepath, and
parse_msg_type() itself may die on invalid input.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index fb7d071bbf..2ccf1a2f0f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
+ enum fsck_msg_type msg_type = parse_msg_type(msg_type_str);
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
- msg_type = parse_msg_type(msg_type_str);
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (14 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 18:57 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
` (7 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
In f417eed8cde (fsck: provide a function to parse fsck message IDs,
2015-06-22) the "STR" macro was introduced, but that short macro name
was not undefined after use as was done earlier in the same series for
the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck
messages, 2015-06-22).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fsck.c b/fsck.c
index 2ccf1a2f0f..f4c924ed04 100644
--- a/fsck.c
+++ b/fsck.c
@@ -100,6 +100,7 @@ static struct {
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
+#undef STR
static void prepare_msg_ids(void)
{
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use
2021-03-16 16:17 ` [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
@ 2021-03-17 18:57 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 18:57 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> In f417eed8cde (fsck: provide a function to parse fsck message IDs,
> 2015-06-22) the "STR" macro was introduced, but that short macro name
> was not undefined after use as was done earlier in the same series for
> the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck
> messages, 2015-06-22).
Makes sense. Thanks.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> fsck.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fsck.c b/fsck.c
> index 2ccf1a2f0f..f4c924ed04 100644
> --- a/fsck.c
> +++ b/fsck.c
> @@ -100,6 +100,7 @@ static struct {
> { NULL, NULL, NULL, -1 }
> };
> #undef MSG_ID
> +#undef STR
>
> static void prepare_msg_ids(void)
> {
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (15 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 14/22] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
` (6 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation
for moving it over to fsck.h. It's good convention to name macros
in *.h files in such a way as to clearly not clash with any other
names in other files.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fsck.c b/fsck.c
index f4c924ed04..6fbc56e9fa 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,7 +22,7 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_MSG_ID(FUNC) \
+#define FOREACH_FSCK_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
#define MSG_ID(id, msg_type) FSCK_MSG_##id,
enum fsck_msg_id {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
FSCK_MSG_MAX
};
#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {
const char *camelcased;
enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (16 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
` (5 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps
define from fsck.c to fsck.h. This is in preparation for having
non-static functions take the fsck_msg_id as an argument.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 66 ----------------------------------------------------------
fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 66 deletions(-)
diff --git a/fsck.c b/fsck.c
index 6fbc56e9fa..8a66168e51 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,72 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_FSCK_MSG_ID(FUNC) \
- /* fatal errors */ \
- FUNC(NUL_IN_HEADER, FATAL) \
- FUNC(UNTERMINATED_HEADER, FATAL) \
- /* errors */ \
- FUNC(BAD_DATE, ERROR) \
- FUNC(BAD_DATE_OVERFLOW, ERROR) \
- FUNC(BAD_EMAIL, ERROR) \
- FUNC(BAD_NAME, ERROR) \
- FUNC(BAD_OBJECT_SHA1, ERROR) \
- FUNC(BAD_PARENT_SHA1, ERROR) \
- FUNC(BAD_TAG_OBJECT, ERROR) \
- FUNC(BAD_TIMEZONE, ERROR) \
- FUNC(BAD_TREE, ERROR) \
- FUNC(BAD_TREE_SHA1, ERROR) \
- FUNC(BAD_TYPE, ERROR) \
- FUNC(DUPLICATE_ENTRIES, ERROR) \
- FUNC(MISSING_AUTHOR, ERROR) \
- FUNC(MISSING_COMMITTER, ERROR) \
- FUNC(MISSING_EMAIL, ERROR) \
- FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_OBJECT, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_TAG, ERROR) \
- FUNC(MISSING_TAG_ENTRY, ERROR) \
- FUNC(MISSING_TREE, ERROR) \
- FUNC(MISSING_TREE_OBJECT, ERROR) \
- FUNC(MISSING_TYPE, ERROR) \
- FUNC(MISSING_TYPE_ENTRY, ERROR) \
- FUNC(MULTIPLE_AUTHORS, ERROR) \
- FUNC(TREE_NOT_SORTED, ERROR) \
- FUNC(UNKNOWN_TYPE, ERROR) \
- FUNC(ZERO_PADDED_DATE, ERROR) \
- FUNC(GITMODULES_MISSING, ERROR) \
- FUNC(GITMODULES_BLOB, ERROR) \
- FUNC(GITMODULES_LARGE, ERROR) \
- FUNC(GITMODULES_NAME, ERROR) \
- FUNC(GITMODULES_SYMLINK, ERROR) \
- FUNC(GITMODULES_URL, ERROR) \
- FUNC(GITMODULES_PATH, ERROR) \
- FUNC(GITMODULES_UPDATE, ERROR) \
- /* warnings */ \
- FUNC(BAD_FILEMODE, WARN) \
- FUNC(EMPTY_NAME, WARN) \
- FUNC(FULL_PATHNAME, WARN) \
- FUNC(HAS_DOT, WARN) \
- FUNC(HAS_DOTDOT, WARN) \
- FUNC(HAS_DOTGIT, WARN) \
- FUNC(NULL_SHA1, WARN) \
- FUNC(ZERO_PADDED_FILEMODE, WARN) \
- FUNC(NUL_IN_COMMIT, WARN) \
- /* infos (reported as warnings, but ignored by default) */ \
- FUNC(GITMODULES_PARSE, INFO) \
- FUNC(BAD_TAG_NAME, INFO) \
- FUNC(MISSING_TAGGER_ENTRY, INFO) \
- /* ignored (elevated when requested) */ \
- FUNC(EXTRA_HEADER_ENTRY, IGNORE)
-
-#define MSG_ID(id, msg_type) FSCK_MSG_##id,
-enum fsck_msg_id {
- FOREACH_FSCK_MSG_ID(MSG_ID)
- FSCK_MSG_MAX
-};
-#undef MSG_ID
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
diff --git a/fsck.h b/fsck.h
index fce9981a0c..c3d3b47b88 100644
--- a/fsck.h
+++ b/fsck.h
@@ -13,6 +13,72 @@ enum fsck_msg_type {
FSCK_WARN,
};
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \
+ FUNC(UNTERMINATED_HEADER, FATAL) \
+ /* errors */ \
+ FUNC(BAD_DATE, ERROR) \
+ FUNC(BAD_DATE_OVERFLOW, ERROR) \
+ FUNC(BAD_EMAIL, ERROR) \
+ FUNC(BAD_NAME, ERROR) \
+ FUNC(BAD_OBJECT_SHA1, ERROR) \
+ FUNC(BAD_PARENT_SHA1, ERROR) \
+ FUNC(BAD_TAG_OBJECT, ERROR) \
+ FUNC(BAD_TIMEZONE, ERROR) \
+ FUNC(BAD_TREE, ERROR) \
+ FUNC(BAD_TREE_SHA1, ERROR) \
+ FUNC(BAD_TYPE, ERROR) \
+ FUNC(DUPLICATE_ENTRIES, ERROR) \
+ FUNC(MISSING_AUTHOR, ERROR) \
+ FUNC(MISSING_COMMITTER, ERROR) \
+ FUNC(MISSING_EMAIL, ERROR) \
+ FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_OBJECT, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_TAG, ERROR) \
+ FUNC(MISSING_TAG_ENTRY, ERROR) \
+ FUNC(MISSING_TREE, ERROR) \
+ FUNC(MISSING_TREE_OBJECT, ERROR) \
+ FUNC(MISSING_TYPE, ERROR) \
+ FUNC(MISSING_TYPE_ENTRY, ERROR) \
+ FUNC(MULTIPLE_AUTHORS, ERROR) \
+ FUNC(TREE_NOT_SORTED, ERROR) \
+ FUNC(UNKNOWN_TYPE, ERROR) \
+ FUNC(ZERO_PADDED_DATE, ERROR) \
+ FUNC(GITMODULES_MISSING, ERROR) \
+ FUNC(GITMODULES_BLOB, ERROR) \
+ FUNC(GITMODULES_LARGE, ERROR) \
+ FUNC(GITMODULES_NAME, ERROR) \
+ FUNC(GITMODULES_SYMLINK, ERROR) \
+ FUNC(GITMODULES_URL, ERROR) \
+ FUNC(GITMODULES_PATH, ERROR) \
+ FUNC(GITMODULES_UPDATE, ERROR) \
+ /* warnings */ \
+ FUNC(BAD_FILEMODE, WARN) \
+ FUNC(EMPTY_NAME, WARN) \
+ FUNC(FULL_PATHNAME, WARN) \
+ FUNC(HAS_DOT, WARN) \
+ FUNC(HAS_DOTDOT, WARN) \
+ FUNC(HAS_DOTGIT, WARN) \
+ FUNC(NULL_SHA1, WARN) \
+ FUNC(ZERO_PADDED_FILEMODE, WARN) \
+ FUNC(NUL_IN_COMMIT, WARN) \
+ /* infos (reported as warnings, but ignored by default) */ \
+ FUNC(GITMODULES_PARSE, INFO) \
+ FUNC(BAD_TAG_NAME, INFO) \
+ FUNC(MISSING_TAGGER_ENTRY, INFO) \
+ /* ignored (elevated when requested) */ \
+ FUNC(EXTRA_HEADER_ENTRY, IGNORE)
+
+#define MSG_ID(id, msg_type) FSCK_MSG_##id,
+enum fsck_msg_id {
+ FOREACH_FSCK_MSG_ID(MSG_ID)
+ FSCK_MSG_MAX
+};
+#undef MSG_ID
+
struct fsck_options;
struct object;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (17 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-17 19:01 ` Junio C Hamano
2021-03-16 16:17 ` [PATCH v4 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
` (4 subsequent siblings)
23 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the fsck_error callback to also pass along the
fsck_msg_id. Before this change the only way to get the message id was
to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might
want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back
from the msg_id, but I'm not changing that convention. It's really
common to need the msg_type, and the report() function itself (which
calls "fsck_error") needs to call fsck_msg_type() to discover
it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 4 +++-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 1 +
fsck.c | 6 ++++--
fsck.h | 6 ++++--
5 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d6d745dc70..b71fac4cec 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -89,7 +89,9 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 56b8efaa89..2b2266a4b7 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
printf("%s\n", oid_to_hex(oid));
return 0;
}
- return fsck_error_function(o, oid, object_type, msg_type, message);
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
}
int cmd_index_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1834394a9b..dc989c356f 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -23,6 +23,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
switch (msg_type) {
diff --git a/fsck.c b/fsck.c
index 8a66168e51..5a040eb4fd 100644
--- a/fsck.c
+++ b/fsck.c
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(options, oid, object_type,
- msg_type, sb.buf);
+ msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index c3d3b47b88..33ecf3f3f1 100644
--- a/fsck.h
+++ b/fsck.h
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
struct fsck_options {
fsck_walk_func walk;
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback
2021-03-16 16:17 ` [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
@ 2021-03-17 19:01 ` Junio C Hamano
0 siblings, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 19:01 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Change the fsck_error callback to also pass along the
> fsck_msg_id. Before this change the only way to get the message id was
> to parse it back out of the "message".
Nice.
> Let's pass it down explicitly for the benefit of callers that might
> want to use it, as discussed in [1].
>
> Passing the msg_type is now redundant, as you can always get it back
> from the msg_id, but I'm not changing that convention. It's really
> common to need the msg_type, and the report() function itself (which
> calls "fsck_error") needs to call fsck_msg_type() to discover
> it. Let's not needlessly re-do that work in the user callback.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v4 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (18 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 19/22] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
` (3 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change code I added in acf9de4c94e (mktag: use fsck instead of custom
verify_tag(), 2021-01-05) to make use of a new API function that takes
the fsck_msg_{id,type} types, instead of arbitrary strings that
we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) it was only intended to be used to parse user-supplied
data.
For things that are purely internal to the C code it makes sense to
have the compiler check these arguments, and to skip the sanity
checking of the data in fsck_set_msg_type() which is redundant to
checks we get from the compiler.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/mktag.c | 3 ++-
fsck.c | 27 +++++++++++++++++----------
fsck.h | 3 +++
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index dc989c356f..de67a94f24 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -93,7 +93,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
die_errno(_("could not read from stdin"));
fsck_options.error_func = mktag_fsck_error_func;
- fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
git_config(mktag_config, NULL);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
diff --git a/fsck.c b/fsck.c
index 5a040eb4fd..f26f47b2a1 100644
--- a/fsck.c
+++ b/fsck.c
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
return 1;
}
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type)
+{
+ if (!options->msg_type) {
+ int i;
+ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
+}
+
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
- if (!options->msg_type) {
- int i;
- enum fsck_msg_type *severity;
- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
- severity[i] = fsck_msg_type(i, options);
- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;
+ fsck_set_msg_type_from_ids(options, msg_id, msg_type);
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index 33ecf3f3f1..6c2fd9c5cc 100644
--- a/fsck.h
+++ b/fsck.h
@@ -82,6 +82,9 @@ enum fsck_msg_id {
struct fsck_options;
struct object;
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type);
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id, const char *msg_type);
void fsck_set_msg_types(struct fsck_options *options, const char *values);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 19/22] fsck.c: move gitmodules_{found,done} into fsck_options
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (19 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 20/22] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
` (2 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the gitmodules_{found,done} static variables added in
159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the
fsck_options struct. It makes sense to keep all the context in the
same place.
This requires changing the recently added register_found_gitmodules()
function added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) to take fsck_options. That function will be
removed in a subsequent commit, but as it'll require the new
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 2 +-
fsck.c | 23 ++++++++++-------------
fsck.h | 7 ++++++-
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 6a61a46428..82c3c2c043 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(oid);
+ register_found_gitmodules(&fo, oid);
if (fsck_finish(&fo))
die("fsck failed");
}
diff --git a/fsck.c b/fsck.c
index f26f47b2a1..565274a946 100644
--- a/fsck.c
+++ b/fsck.c
@@ -19,9 +19,6 @@
#include "credential.h"
#include "help.h"
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options,
oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid,
has_dotgit |= is_ntfs_dotgit(backslash);
if (is_ntfs_dotgitmodules(backslash)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options, oid, OBJ_TREE,
FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
struct fsck_gitmodules_data data;
struct config_options config_opts = { 0 };
- if (!oidset_contains(&gitmodules_found, oid))
+ if (!oidset_contains(&options->gitmodules_found, oid))
return 0;
- oidset_insert(&gitmodules_done, oid);
+ oidset_insert(&options->gitmodules_done, oid);
if (object_on_skiplist(options, oid))
return 0;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(const struct object_id *oid)
+void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
{
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
}
int fsck_finish(struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
- oidset_iter_init(&gitmodules_found, &iter);
+ oidset_iter_init(&options->gitmodules_found, &iter);
while ((oid = oidset_iter_next(&iter))) {
enum object_type type;
unsigned long size;
char *buf;
- if (oidset_contains(&gitmodules_done, oid))
+ if (oidset_contains(&options->gitmodules_done, oid))
continue;
buf = read_object_file(oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options)
}
- oidset_clear(&gitmodules_found);
- oidset_clear(&gitmodules_done);
+ oidset_clear(&options->gitmodules_found);
+ oidset_clear(&options->gitmodules_done);
return ret;
}
diff --git a/fsck.h b/fsck.h
index 6c2fd9c5cc..bb59ef05b6 100644
--- a/fsck.h
+++ b/fsck.h
@@ -118,6 +118,8 @@ struct fsck_options {
unsigned strict:1;
enum fsck_msg_type *msg_type;
struct oidset skiplist;
+ struct oidset gitmodules_found;
+ struct oidset gitmodules_done;
kh_oid_map_t *object_names;
};
@@ -125,6 +127,8 @@ struct fsck_options {
.walk = NULL, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
.object_names = NULL,
#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(const struct object_id *oid);
+void register_found_gitmodules(struct fsck_options *options,
+ const struct object_id *oid);
/*
* fsck a tag, and pass info about it back to the caller. This is
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 20/22] fetch-pack: don't needlessly copy fsck_options
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (20 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 19/22] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 21/22] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the behavior of the .gitmodules validation added in
5476e1efde (fetch-pack: print and use dangling .gitmodules,
2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting
up the error_func earlier means that we're relying on the "error_func"
not being set in some code in between the two hunks being modified
here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is
further setup by calling fsck_set_msg_types(), and assigning to
do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the
fsck_options struct before setting error_func. Let's just do this
setup at the top of the function, along with the "walk" assignment.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2b2266a4b7..5ad80b85b4 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
+ fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
else
close(input_fd);
- if (do_fsck_object) {
- struct fsck_options fo = fsck_options;
-
- fo.error_func = print_dangling_gitmodules;
- if (fsck_finish(&fo))
- die(_("fsck error in pack objects"));
- }
+ if (do_fsck_object && fsck_finish(&fsck_options))
+ die(_("fsck error in pack objects"));
free(objects);
strbuf_release(&index_name_buf);
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 21/22] fetch-pack: use file-scope static struct for fsck_options
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (21 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 20/22] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 16:17 ` [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change code added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) so that we use a file-scoped "static struct
fsck_options" instead of defining one in the "fsck_gitmodules_oids()"
function.
We use this pattern in all of
builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see
fetch-pack be the odd one out. One might think that we're using other
fsck_options structs in fetch-pack, or doing on fsck twice there, but
we're not.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 82c3c2c043..229fd8e2c2 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,6 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
{
struct oidset_iter iter;
const struct object_id *oid;
- struct fsck_options fo = FSCK_OPTIONS_STRICT;
if (!oidset_size(gitmodules_oids))
return;
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fo, oid);
- if (fsck_finish(&fo))
+ register_found_gitmodules(&fsck_options, oid);
+ if (fsck_finish(&fsck_options))
die("fsck failed");
}
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
` (22 preceding siblings ...)
2021-03-16 16:17 ` [PATCH v4 21/22] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-16 16:17 ` Ævar Arnfjörð Bjarmason
2021-03-16 19:32 ` Derrick Stolee
2021-03-17 19:12 ` Junio C Hamano
23 siblings, 2 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-16 16:17 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor the check added in 5476e1efde (fetch-pack: print and use
dangling .gitmodules, 2021-02-22) to make use of us now passing the
"msg_id" to the user defined "error_func". We can now compare against
the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
message.
Let's also replace register_found_gitmodules() with directly
manipulating the "gitmodules_found" member. A recent commit moved it
into "fsck_options" so we could do this here.
Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
would be to either define this directly in fsck.c as a public API, or
to create some library shared by fetch-pack.c ad builtin/index-pack.
I expect that there won't be many of these fsck utility functions in
the future, so just having a single fsck-cb.c makes sense.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
Makefile | 1 +
builtin/index-pack.c | 21 +--------------------
fetch-pack.c | 4 ++--
fsck-cb.c | 16 ++++++++++++++++
fsck.c | 5 -----
fsck.h | 22 +++++++++++++++++++---
6 files changed, 39 insertions(+), 30 deletions(-)
create mode 100644 fsck-cb.c
diff --git a/Makefile b/Makefile
index dfb0f1000f..3faa8bd0d3 100644
--- a/Makefile
+++ b/Makefile
@@ -882,6 +882,7 @@ LIB_OBJS += fetch-negotiator.o
LIB_OBJS += fetch-pack.o
LIB_OBJS += fmt-merge-msg.o
LIB_OBJS += fsck.o
+LIB_OBJS += fsck-cb.o
LIB_OBJS += fsmonitor.o
LIB_OBJS += gettext.o
LIB_OBJS += gpg-interface.o
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5ad80b85b4..11f0fafd33 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -120,7 +120,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 struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static int verbose;
static int show_resolving_progress;
static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only)
}
}
-static int print_dangling_gitmodules(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
- const char *message)
-{
- /*
- * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
- * instead of relying on this string check.
- */
- if (starts_with(message, "gitmodulesMissing")) {
- printf("%s\n", oid_to_hex(oid));
- return 0;
- }
- return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
-}
-
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
- fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
diff --git a/fetch-pack.c b/fetch-pack.c
index 229fd8e2c2..008a3facd4 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,7 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
+ oidset_insert(&fsck_options.gitmodules_found, oid);
if (fsck_finish(&fsck_options))
die("fsck failed");
}
diff --git a/fsck-cb.c b/fsck-cb.c
new file mode 100644
index 0000000000..465a49235a
--- /dev/null
+++ b/fsck-cb.c
@@ -0,0 +1,16 @@
+#include "git-compat-util.h"
+#include "fsck.h"
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
+{
+ if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
+ puts(oid_to_hex(oid));
+ return 0;
+ }
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
diff --git a/fsck.c b/fsck.c
index 565274a946..b0089844db 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
-{
- oidset_insert(&options->gitmodules_found, oid);
-}
-
int fsck_finish(struct fsck_options *options)
{
int ret = 0;
diff --git a/fsck.h b/fsck.h
index bb59ef05b6..ae3107638a 100644
--- a/fsck.h
+++ b/fsck.h
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(struct fsck_options *options,
- const struct object_id *oid);
-
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
@@ -204,4 +201,23 @@ const char *fsck_describe_object(struct fsck_options *options,
int fsck_config_internal(const char *var, const char *value, void *cb,
struct fsck_options *options);
+/*
+ * Initializations for callbacks in fsck-cb.c
+ */
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ FSCK_OPTIONS_COMMON \
+}
+
+/*
+ * Error callbacks in fsck-cb.c
+ */
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message);
+
#endif
--
2.31.0.260.g719c683c1d
^ permalink raw reply related [flat|nested] 229+ messages in thread
* Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-03-16 16:17 ` [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
@ 2021-03-16 19:32 ` Derrick Stolee
2021-03-17 13:47 ` Ævar Arnfjörð Bjarmason
2021-03-17 19:12 ` Junio C Hamano
1 sibling, 1 reply; 229+ messages in thread
From: Derrick Stolee @ 2021-03-16 19:32 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason, git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
> Refactor the check added in 5476e1efde (fetch-pack: print and use
> dangling .gitmodules, 2021-02-22) to make use of us now passing the
> "msg_id" to the user defined "error_func". We can now compare against
> the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
> message.
>
> Let's also replace register_found_gitmodules() with directly
> manipulating the "gitmodules_found" member. A recent commit moved it
> into "fsck_options" so we could do this here.
>
> Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
> would be to either define this directly in fsck.c as a public API, or
> to create some library shared by fetch-pack.c ad builtin/index-pack.
>
> I expect that there won't be many of these fsck utility functions in
> the future, so just having a single fsck-cb.c makes sense.
I'm not convinced that having a single cb function merits its
own file. But, if you expect this pattern to be expanded a
couple more times, then I would say it is worth it. Do you have
such plans?
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-03-16 19:32 ` Derrick Stolee
@ 2021-03-17 13:47 ` Ævar Arnfjörð Bjarmason
2021-03-17 20:27 ` Derrick Stolee
0 siblings, 1 reply; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-17 13:47 UTC (permalink / raw)
To: Derrick Stolee
Cc: git, Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On Tue, Mar 16 2021, Derrick Stolee wrote:
> On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
>> Refactor the check added in 5476e1efde (fetch-pack: print and use
>> dangling .gitmodules, 2021-02-22) to make use of us now passing the
>> "msg_id" to the user defined "error_func". We can now compare against
>> the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
>> message.
>>
>> Let's also replace register_found_gitmodules() with directly
>> manipulating the "gitmodules_found" member. A recent commit moved it
>> into "fsck_options" so we could do this here.
>>
>> Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
>> would be to either define this directly in fsck.c as a public API, or
>> to create some library shared by fetch-pack.c ad builtin/index-pack.
>>
>> I expect that there won't be many of these fsck utility functions in
>> the future, so just having a single fsck-cb.c makes sense.
>
> I'm not convinced that having a single cb function merits its
> own file. But, if you expect this pattern to be expanded a
> couple more times, then I would say it is worth it. Do you have
> such plans?
Not really, well. Vague ones, but nothing I have even local patches for.
It just seemed odd to stick random callback functions shared by related
programs into fsck.h's interface, but I guess with
FSCK_OPTIONS_MISSING_GITMODULES I already did that.
Do you suggest just putting it into fsck.c?
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-03-17 13:47 ` Ævar Arnfjörð Bjarmason
@ 2021-03-17 20:27 ` Derrick Stolee
0 siblings, 0 replies; 229+ messages in thread
From: Derrick Stolee @ 2021-03-17 20:27 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan
On 3/17/2021 9:47 AM, Ævar Arnfjörð Bjarmason wrote:
>
> On Tue, Mar 16 2021, Derrick Stolee wrote:
>
>> On 3/16/2021 12:17 PM, Ævar Arnfjörð Bjarmason wrote:
>>> I expect that there won't be many of these fsck utility functions in
>>> the future, so just having a single fsck-cb.c makes sense.
>>
>> I'm not convinced that having a single cb function merits its
>> own file. But, if you expect this pattern to be expanded a
>> couple more times, then I would say it is worth it. Do you have
>> such plans?
>
> Not really, well. Vague ones, but nothing I have even local patches for.
>
> It just seemed odd to stick random callback functions shared by related
> programs into fsck.h's interface, but I guess with
> FSCK_OPTIONS_MISSING_GITMODULES I already did that.
>
> Do you suggest just putting it into fsck.c?
Yeah, if it is frequently paired with fsck operations, I think it
makes the most sense there.
And looking at it again, I'm not sure parse-options-cb.c has a
good excuse for being separate from parse-options.c, but that's
the current state so I wouldn't change it now.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 229+ messages in thread
* Re: [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-03-16 16:17 ` [PATCH v4 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
2021-03-16 19:32 ` Derrick Stolee
@ 2021-03-17 19:12 ` Junio C Hamano
1 sibling, 0 replies; 229+ messages in thread
From: Junio C Hamano @ 2021-03-17 19:12 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason
Cc: git, Jeff King, Johannes Schindelin, Jonathan Tan
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index 5ad80b85b4..11f0fafd33 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -120,7 +120,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 struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
Hmph, I do not think this is a good way to go. Specifically,
fsck-cb.c with the definition of what this thing is, and in fsck.h
file the normal "options" initializers being defined quite far away
from where this is defined, it is hard to see what is different
between the normal strict one and MISSING_GITMODULES one.
Rather, it may be far simpler to keep only DEFAULT and STRICT, and
override .error_func at runtime in the codepath(s) that needs to,
which would make it more clear what is going on. That way, we do
not need the split initializers with _ERROR_FUNC, which is another
reason why the approach taken by this series is not a good idea (it
does not scale---error-func may seem so special to deserve having
two sets of macros that use the default one and leave the member
unspecified, but it won't stay to be special forever).
IOW,
> @@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
>
> read_replace_refs = 0;
> fsck_options.walk = mark_link;
> - fsck_options.error_func = print_dangling_gitmodules;
I doubt this hunk is an improvement.
> diff --git a/fsck-cb.c b/fsck-cb.c
> new file mode 100644
> index 0000000000..465a49235a
> --- /dev/null
> +++ b/fsck-cb.c
> @@ -0,0 +1,16 @@
> +#include "git-compat-util.h"
> +#include "fsck.h"
> +
> +int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
> + const struct object_id *oid,
> + enum object_type object_type,
> + enum fsck_msg_type msg_type,
> + enum fsck_msg_id msg_id,
> + const char *message)
> +{
> + if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
> + puts(oid_to_hex(oid));
> + return 0;
> + }
> + return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
> +}
As Derrick noticed, I do not know if we want to have a separate file
for this single function. Shouldn't it be part of builtin/index-pack.c,
or do we want other places to do the same kind of checks?
Thanks.
^ permalink raw reply [flat|nested] 229+ messages in thread
* [PATCH v3 01/22] fsck.h: update FSCK_OPTIONS_* for object_name
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
2021-02-18 22:19 ` Junio C Hamano
2021-03-06 11:04 ` [PATCH v3 00/22] fsck: API improvements Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (20 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Add the object_name member to the initialization macro. This was
omitted in 7b35efd734e (fsck_walk(): optionally name objects on the
go, 2016-07-17) when the field was added.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index 733378f1260..2274843ba0c 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,8 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
/* descend in all linked child objects
* the return value is:
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT}
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (2 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 01/22] fsck.h: update FSCK_OPTIONS_* for object_name Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
` (19 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/fsck.h b/fsck.h
index 2274843ba0c..40f3cb3f645 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,8 +43,22 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_DEFAULT { \
+ .walk = NULL, \
+ .error_func = fsck_error_function, \
+ .strict = 0, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
+ .object_names = NULL, \
+}
+#define FSCK_OPTIONS_STRICT { \
+ .walk = NULL, \
+ .error_func = fsck_error_function, \
+ .strict = 1, \
+ .msg_type = NULL, \
+ .skiplist = OIDSET_INIT, \
+ .object_names = NULL, \
+}
/* descend in all linked child objects
* the return value is:
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT}
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (3 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 02/22] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro Ævar Arnfjörð Bjarmason
` (18 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Use a temporary macro to define what FSCK_OPTIONS_{DEFAULT,STRICT}
have in common, and define the two in terms of that macro.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/fsck.h b/fsck.h
index 40f3cb3f645..ea3a907ec3b 100644
--- a/fsck.h
+++ b/fsck.h
@@ -43,22 +43,14 @@ struct fsck_options {
kh_oid_map_t *object_names;
};
-#define FSCK_OPTIONS_DEFAULT { \
+#define FSCK_OPTIONS_COMMON \
.walk = NULL, \
.error_func = fsck_error_function, \
- .strict = 0, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
- .object_names = NULL, \
-}
-#define FSCK_OPTIONS_STRICT { \
- .walk = NULL, \
- .error_func = fsck_error_function, \
- .strict = 1, \
- .msg_type = NULL, \
- .skiplist = OIDSET_INIT, \
- .object_names = NULL, \
-}
+ .object_names = NULL,
+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON }
+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }
/* descend in all linked child objects
* the return value is:
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (4 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 03/22] fsck.h: reduce duplication between FSCK_OPTIONS_{DEFAULT,STRICT} Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 05/22] fsck.h: indent arguments to of fsck_set_msg_type Ævar Arnfjörð Bjarmason
` (17 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro for those that would like
to use FSCK_OPTIONS_COMMON in their own initialization, but supply
their own error functions.
Nothing is being changed to use this yet, but in some subsequent
commits we'll make use of this macro.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fsck.h b/fsck.h
index ea3a907ec3b..dc35924cbf5 100644
--- a/fsck.h
+++ b/fsck.h
@@ -45,12 +45,15 @@ struct fsck_options {
#define FSCK_OPTIONS_COMMON \
.walk = NULL, \
- .error_func = fsck_error_function, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
.object_names = NULL,
-#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON }
-#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON }
+#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
+ FSCK_OPTIONS_COMMON \
+ .error_func = fsck_error_function
+
+#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC }
+#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC }
/* descend in all linked child objects
* the return value is:
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 05/22] fsck.h: indent arguments to of fsck_set_msg_type
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (5 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 04/22] fsck.h: add a FSCK_OPTIONS_COMMON_ERROR_FUNC macro Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 06/22] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
` (16 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fsck.h b/fsck.h
index dc35924cbf5..5e488cef6b3 100644
--- a/fsck.h
+++ b/fsck.h
@@ -11,7 +11,7 @@ struct fsck_options;
struct object;
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type);
+ const char *msg_id, const char *msg_type);
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);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 06/22] fsck.h: use "enum object_type" instead of "int"
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (6 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 05/22] fsck.h: indent arguments to of fsck_set_msg_type Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
` (15 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the fsck_walk_func to use an "enum object_type" instead of an
"int" type. The types are compatible, and ever since this was added in
355885d5315 (add generic, type aware object chain walker, 2008-02-25)
we've used entries from object_type (OBJ_BLOB etc.).
So this doesn't really change anything as far as the generated code is
concerned, it just gives the compiler more information and makes this
easier to read.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 3 ++-
builtin/index-pack.c | 3 ++-
builtin/unpack-objects.c | 3 ++-
fsck.h | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 821e7798c70..68f0329e69e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -197,7 +197,8 @@ static int traverse_reachable(void)
return !!result;
}
-static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_used(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return 1;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bad57488079..69f24fe9f76 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -212,7 +212,8 @@ static void cleanup_thread(void)
free(thread_data);
}
-static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
+static int mark_link(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
if (!obj)
return -1;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index dd4a75e030d..ca54fd16688 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -187,7 +187,8 @@ 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, struct fsck_options *options)
+static int check_object(struct object *obj, enum object_type type,
+ void *data, struct fsck_options *options)
{
struct obj_buffer *obj_buf;
diff --git a/fsck.h b/fsck.h
index 5e488cef6b3..f67edd8f1f9 100644
--- a/fsck.h
+++ b/fsck.h
@@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);
* <0 error signaled and abort
* >0 error signaled and do not abort
*/
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
+typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
+ void *data, struct fsck_options *options);
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (7 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 06/22] fsck.h: use "enum object_type" instead of "int" Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 08/22] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
` (14 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename variables in a function added in 0282f4dced0 (fsck: offer a
function to demote fsck errors to warnings, 2015-06-22).
It was needlessly confusing that it took a "msg_type" argument, but
then later declared another "msg_type" of a different type.
Let's rename that to "severity", and rename "id" to "msg_id" and
"msg_id" to "msg_id_str" etc. This will make a follow-up change
smaller.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/fsck.c b/fsck.c
index e3030f3b358..0a9ac9ca070 100644
--- a/fsck.c
+++ b/fsck.c
@@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
}
void fsck_set_msg_type(struct fsck_options *options,
- const char *msg_id, const char *msg_type)
+ const char *msg_id_str, const char *msg_type_str)
{
- int id = parse_msg_id(msg_id), type;
+ int msg_id = parse_msg_id(msg_id_str), msg_type;
- if (id < 0)
- die("Unhandled message id: %s", msg_id);
- type = parse_msg_type(msg_type);
+ if (msg_id < 0)
+ die("Unhandled message id: %s", msg_id_str);
+ msg_type = parse_msg_type(msg_type_str);
- if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
- die("Cannot demote %s to %s", msg_id, msg_type);
+ if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
+ die("Cannot demote %s to %s", msg_id_str, msg_type_str);
if (!options->msg_type) {
int i;
- int *msg_type;
- ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
+ int *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
- msg_type[i] = fsck_msg_type(i, options);
- options->msg_type = msg_type;
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
}
- options->msg_type[id] = type;
+ options->msg_type[msg_id] = msg_type;
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 08/22] fsck.c: move definition of msg_id into append_msg_id()
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (8 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 07/22] fsck.c: rename variables in fsck_set_msg_type() for less confusion Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
` (13 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor code added in 71ab8fa840f (fsck: report the ID of the
error/warning, 2015-06-22) to resolve the msg_id to a string in the
function that wants it, instead of doing it in report().
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index 0a9ac9ca070..b977493f57a 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, const char *msg_id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
{
+ const char *msg_id = msg_id_info[id].id_string;
for (;;) {
char c = *(msg_id)++;
@@ -308,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, msg_id_info[id].id_string);
+ append_msg_id(&sb, id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id"
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (9 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 08/22] fsck.c: move definition of msg_id into append_msg_id() Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
` (12 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename the remaining variables of type fsck_msg_id from "id" to
"msg_id". This change is relatively small, and is worth the churn for
a later change where we have different id's in the "report" function.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fsck.c b/fsck.c
index b977493f57a..6b72ddaa51d 100644
--- a/fsck.c
+++ b/fsck.c
@@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
free(to_free);
}
-static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id)
+static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id)
{
- const char *msg_id = msg_id_info[id].id_string;
+ const char *msg_id_str = msg_id_info[msg_id].id_string;
for (;;) {
- char c = *(msg_id)++;
+ char c = *(msg_id_str)++;
if (!c)
break;
if (c != '_')
strbuf_addch(sb, tolower(c));
else {
- assert(*msg_id);
- strbuf_addch(sb, *(msg_id)++);
+ assert(*msg_id_str);
+ strbuf_addch(sb, *(msg_id_str)++);
}
}
@@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts,
__attribute__((format (printf, 5, 6)))
static int report(struct fsck_options *options,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_id id, const char *fmt, ...)
+ enum fsck_msg_id msg_id, const char *fmt, ...)
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(id, options), result;
+ int msg_type = fsck_msg_type(msg_id, options), result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -309,7 +309,7 @@ static int report(struct fsck_options *options,
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;
- append_msg_id(&sb, id);
+ append_msg_id(&sb, msg_id);
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type"
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (10 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 09/22] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
` (11 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor "if options->msg_type" and other code added in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) to reduce the scope of the "int msg_type" variable.
This is in preparation for changing its type in a subsequent commit,
only using it in the "!options->msg_type" scope makes that change
This also brings the code in line with the fsck_set_msg_type()
function (also added in 0282f4dced0), which does a similar check for
"!options->msg_type". Another minor benefit is getting rid of the
style violation of not having braces for the body of the "if".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fsck.c b/fsck.c
index 6b72ddaa51d..0988ab65792 100644
--- a/fsck.c
+++ b/fsck.c
@@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
static int fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
- int msg_type;
-
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
- if (options->msg_type)
- msg_type = options->msg_type[msg_id];
- else {
- msg_type = msg_id_info[msg_id].msg_type;
+ if (!options->msg_type) {
+ int msg_type = msg_id_info[msg_id].msg_type;
+
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
+ return msg_type;
}
- return msg_type;
+ return options->msg_type[msg_id];
}
static int parse_msg_type(const char *str)
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (11 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 10/22] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
` (10 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new
fsck_msg_type enum.
These defines were originally introduced in:
- ba002f3b28a (builtin-fsck: move common object checking code to
fsck.c, 2008-02-25)
- f50c4407305 (fsck: disallow demoting grave fsck errors to warnings,
2015-06-22)
- efaba7cc77f (fsck: optionally ignore specific fsck issues
completely, 2015-06-22)
- f27d05b1704 (fsck: allow upgrading fsck warnings to errors,
2015-06-22)
The reason these were defined in two different places is because we
use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are
used by external callbacks.
Untangling that would take some more work, since we expose the new
"enum fsck_msg_type" to both. Similar to "enum object_type" it's not
worth structuring the API in such a way that only those who need
FSCK_{ERROR,WARN} pass around a different type.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 2 +-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 3 ++-
fsck.c | 21 ++++++++++-----------
fsck.h | 16 ++++++++++------
5 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 68f0329e69e..d6d745dc702 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -89,7 +89,7 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 69f24fe9f76..56b8efaa89b 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)
static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
/*
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 41a399a69e4..1834394a9b6 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -22,7 +22,8 @@ static int mktag_config(const char *var, const char *value, void *cb)
static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/fsck.c b/fsck.c
index 0988ab65792..fb7d071bbf9 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,9 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FSCK_FATAL -1
-#define FSCK_INFO -2
-
#define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {
const char *id_string;
const char *downcased;
const char *camelcased;
- int msg_type;
+ enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
FOREACH_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
list_config_item(list, prefix, msg_id_info[i].camelcased);
}
-static int fsck_msg_type(enum fsck_msg_id msg_id,
+static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
struct fsck_options *options)
{
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
if (!options->msg_type) {
- int msg_type = msg_id_info[msg_id].msg_type;
+ enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
if (options->strict && msg_type == FSCK_WARN)
msg_type = FSCK_ERROR;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
return options->msg_type[msg_id];
}
-static int parse_msg_type(const char *str)
+static enum fsck_msg_type parse_msg_type(const char *str)
{
if (!strcmp(str, "error"))
return FSCK_ERROR;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
- int msg_id = parse_msg_id(msg_id_str), msg_type;
+ int msg_id = parse_msg_id(msg_id_str);
+ enum fsck_msg_type msg_type;
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (!options->msg_type) {
int i;
- int *severity;
+ enum fsck_msg_type *severity;
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
for (i = 0; i < FSCK_MSG_MAX; i++)
severity[i] = fsck_msg_type(i, options);
@@ -294,7 +292,8 @@ static int report(struct fsck_options *options,
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- int msg_type = fsck_msg_type(msg_id, options), result;
+ enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
+ int result;
if (msg_type == FSCK_IGNORE)
return 0;
@@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- int msg_type, const char *message)
+ enum fsck_msg_type msg_type, const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index f67edd8f1f9..2ecc15eee77 100644
--- a/fsck.h
+++ b/fsck.h
@@ -3,9 +3,13 @@
#include "oidset.h"
-#define FSCK_ERROR 1
-#define FSCK_WARN 2
-#define FSCK_IGNORE 3
+enum fsck_msg_type {
+ FSCK_INFO = -2,
+ FSCK_FATAL = -1,
+ FSCK_ERROR = 1,
+ FSCK_WARN,
+ FSCK_IGNORE
+};
struct fsck_options;
struct object;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- int msg_type, const char *message);
+ enum fsck_msg_type msg_type, const char *message);
struct fsck_options {
fsck_walk_func walk;
fsck_error error_func;
unsigned strict:1;
- int *msg_type;
+ enum fsck_msg_type *msg_type;
struct oidset skiplist;
kh_oid_map_t *object_names;
};
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type"
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (12 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 11/22] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
` (9 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the values in the "enum fsck_msg_type" from being manually
assigned to using default C enum values.
This means we end up with a FSCK_IGNORE=0, which was previously
defined as "2".
I'm confident that nothing relies on these values, we always compare
them explicitly. Let's not omit "0" so it won't be assumed that we're
using these as a boolean somewhere.
This also allows us to re-structure the fields to mark which are
"private" v.s. "public". See the preceding commit for a rationale for
not simply splitting these into two enums, namely that this is used
for both the private and public fsck API.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fsck.h b/fsck.h
index 2ecc15eee77..fce9981a0cb 100644
--- a/fsck.h
+++ b/fsck.h
@@ -4,11 +4,13 @@
#include "oidset.h"
enum fsck_msg_type {
- FSCK_INFO = -2,
- FSCK_FATAL = -1,
- FSCK_ERROR = 1,
+ /* for internal use only */
+ FSCK_IGNORE,
+ FSCK_INFO,
+ FSCK_FATAL,
+ /* "public", fed to e.g. error_func callbacks */
+ FSCK_ERROR,
FSCK_WARN,
- FSCK_IGNORE
};
struct fsck_options;
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type()
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (13 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 12/22] fsck.h: re-order and re-assign "enum fsck_msg_type" Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 14/22] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
` (8 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
There's no reason to defer the calling of parse_msg_type() until after
we've checked if the "id < 0". This is not a hot codepath, and
parse_msg_type() itself may die on invalid input.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fsck.c b/fsck.c
index fb7d071bbf9..2ccf1a2f0fd 100644
--- a/fsck.c
+++ b/fsck.c
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
- enum fsck_msg_type msg_type;
+ enum fsck_msg_type msg_type = parse_msg_type(msg_type_str);
if (msg_id < 0)
die("Unhandled message id: %s", msg_id_str);
- msg_type = parse_msg_type(msg_type_str);
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 14/22] fsck.c: undefine temporary STR macro after use
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (14 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 13/22] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
` (7 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
In f417eed8cde (fsck: provide a function to parse fsck message IDs,
2015-06-22) the "STR" macro was introduced, but that short macro name
was not undefined after use as was done earlier in the same series for
the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck
messages, 2015-06-22).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fsck.c b/fsck.c
index 2ccf1a2f0fd..f4c924ed044 100644
--- a/fsck.c
+++ b/fsck.c
@@ -100,6 +100,7 @@ static struct {
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
+#undef STR
static void prepare_msg_ids(void)
{
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (15 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 14/22] fsck.c: undefine temporary STR macro after use Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
` (6 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Rename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation
for moving it over to fsck.h. It's good convention to name macros
in *.h files in such a way as to clearly not clash with any other
names in other files.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fsck.c b/fsck.c
index f4c924ed044..6fbc56e9faa 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,7 +22,7 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_MSG_ID(FUNC) \
+#define FOREACH_FSCK_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
FUNC(UNTERMINATED_HEADER, FATAL) \
@@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
#define MSG_ID(id, msg_type) FSCK_MSG_##id,
enum fsck_msg_id {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
FSCK_MSG_MAX
};
#undef MSG_ID
@@ -96,7 +96,7 @@ static struct {
const char *camelcased;
enum fsck_msg_type msg_type;
} msg_id_info[FSCK_MSG_MAX + 1] = {
- FOREACH_MSG_ID(MSG_ID)
+ FOREACH_FSCK_MSG_ID(MSG_ID)
{ NULL, NULL, NULL, -1 }
};
#undef MSG_ID
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (16 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 15/22] fsck.c: give "FOREACH_MSG_ID" a more specific name Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
` (5 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps
define from fsck.c to fsck.h. This is in preparation for having
non-static functions take the fsck_msg_id as an argument.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fsck.c | 66 ----------------------------------------------------------
fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 66 deletions(-)
diff --git a/fsck.c b/fsck.c
index 6fbc56e9faa..8a66168e516 100644
--- a/fsck.c
+++ b/fsck.c
@@ -22,72 +22,6 @@
static struct oidset gitmodules_found = OIDSET_INIT;
static struct oidset gitmodules_done = OIDSET_INIT;
-#define FOREACH_FSCK_MSG_ID(FUNC) \
- /* fatal errors */ \
- FUNC(NUL_IN_HEADER, FATAL) \
- FUNC(UNTERMINATED_HEADER, FATAL) \
- /* errors */ \
- FUNC(BAD_DATE, ERROR) \
- FUNC(BAD_DATE_OVERFLOW, ERROR) \
- FUNC(BAD_EMAIL, ERROR) \
- FUNC(BAD_NAME, ERROR) \
- FUNC(BAD_OBJECT_SHA1, ERROR) \
- FUNC(BAD_PARENT_SHA1, ERROR) \
- FUNC(BAD_TAG_OBJECT, ERROR) \
- FUNC(BAD_TIMEZONE, ERROR) \
- FUNC(BAD_TREE, ERROR) \
- FUNC(BAD_TREE_SHA1, ERROR) \
- FUNC(BAD_TYPE, ERROR) \
- FUNC(DUPLICATE_ENTRIES, ERROR) \
- FUNC(MISSING_AUTHOR, ERROR) \
- FUNC(MISSING_COMMITTER, ERROR) \
- FUNC(MISSING_EMAIL, ERROR) \
- FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_OBJECT, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
- FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
- FUNC(MISSING_TAG, ERROR) \
- FUNC(MISSING_TAG_ENTRY, ERROR) \
- FUNC(MISSING_TREE, ERROR) \
- FUNC(MISSING_TREE_OBJECT, ERROR) \
- FUNC(MISSING_TYPE, ERROR) \
- FUNC(MISSING_TYPE_ENTRY, ERROR) \
- FUNC(MULTIPLE_AUTHORS, ERROR) \
- FUNC(TREE_NOT_SORTED, ERROR) \
- FUNC(UNKNOWN_TYPE, ERROR) \
- FUNC(ZERO_PADDED_DATE, ERROR) \
- FUNC(GITMODULES_MISSING, ERROR) \
- FUNC(GITMODULES_BLOB, ERROR) \
- FUNC(GITMODULES_LARGE, ERROR) \
- FUNC(GITMODULES_NAME, ERROR) \
- FUNC(GITMODULES_SYMLINK, ERROR) \
- FUNC(GITMODULES_URL, ERROR) \
- FUNC(GITMODULES_PATH, ERROR) \
- FUNC(GITMODULES_UPDATE, ERROR) \
- /* warnings */ \
- FUNC(BAD_FILEMODE, WARN) \
- FUNC(EMPTY_NAME, WARN) \
- FUNC(FULL_PATHNAME, WARN) \
- FUNC(HAS_DOT, WARN) \
- FUNC(HAS_DOTDOT, WARN) \
- FUNC(HAS_DOTGIT, WARN) \
- FUNC(NULL_SHA1, WARN) \
- FUNC(ZERO_PADDED_FILEMODE, WARN) \
- FUNC(NUL_IN_COMMIT, WARN) \
- /* infos (reported as warnings, but ignored by default) */ \
- FUNC(GITMODULES_PARSE, INFO) \
- FUNC(BAD_TAG_NAME, INFO) \
- FUNC(MISSING_TAGGER_ENTRY, INFO) \
- /* ignored (elevated when requested) */ \
- FUNC(EXTRA_HEADER_ENTRY, IGNORE)
-
-#define MSG_ID(id, msg_type) FSCK_MSG_##id,
-enum fsck_msg_id {
- FOREACH_FSCK_MSG_ID(MSG_ID)
- FSCK_MSG_MAX
-};
-#undef MSG_ID
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
diff --git a/fsck.h b/fsck.h
index fce9981a0cb..c3d3b47b88b 100644
--- a/fsck.h
+++ b/fsck.h
@@ -13,6 +13,72 @@ enum fsck_msg_type {
FSCK_WARN,
};
+#define FOREACH_FSCK_MSG_ID(FUNC) \
+ /* fatal errors */ \
+ FUNC(NUL_IN_HEADER, FATAL) \
+ FUNC(UNTERMINATED_HEADER, FATAL) \
+ /* errors */ \
+ FUNC(BAD_DATE, ERROR) \
+ FUNC(BAD_DATE_OVERFLOW, ERROR) \
+ FUNC(BAD_EMAIL, ERROR) \
+ FUNC(BAD_NAME, ERROR) \
+ FUNC(BAD_OBJECT_SHA1, ERROR) \
+ FUNC(BAD_PARENT_SHA1, ERROR) \
+ FUNC(BAD_TAG_OBJECT, ERROR) \
+ FUNC(BAD_TIMEZONE, ERROR) \
+ FUNC(BAD_TREE, ERROR) \
+ FUNC(BAD_TREE_SHA1, ERROR) \
+ FUNC(BAD_TYPE, ERROR) \
+ FUNC(DUPLICATE_ENTRIES, ERROR) \
+ FUNC(MISSING_AUTHOR, ERROR) \
+ FUNC(MISSING_COMMITTER, ERROR) \
+ FUNC(MISSING_EMAIL, ERROR) \
+ FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_OBJECT, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
+ FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
+ FUNC(MISSING_TAG, ERROR) \
+ FUNC(MISSING_TAG_ENTRY, ERROR) \
+ FUNC(MISSING_TREE, ERROR) \
+ FUNC(MISSING_TREE_OBJECT, ERROR) \
+ FUNC(MISSING_TYPE, ERROR) \
+ FUNC(MISSING_TYPE_ENTRY, ERROR) \
+ FUNC(MULTIPLE_AUTHORS, ERROR) \
+ FUNC(TREE_NOT_SORTED, ERROR) \
+ FUNC(UNKNOWN_TYPE, ERROR) \
+ FUNC(ZERO_PADDED_DATE, ERROR) \
+ FUNC(GITMODULES_MISSING, ERROR) \
+ FUNC(GITMODULES_BLOB, ERROR) \
+ FUNC(GITMODULES_LARGE, ERROR) \
+ FUNC(GITMODULES_NAME, ERROR) \
+ FUNC(GITMODULES_SYMLINK, ERROR) \
+ FUNC(GITMODULES_URL, ERROR) \
+ FUNC(GITMODULES_PATH, ERROR) \
+ FUNC(GITMODULES_UPDATE, ERROR) \
+ /* warnings */ \
+ FUNC(BAD_FILEMODE, WARN) \
+ FUNC(EMPTY_NAME, WARN) \
+ FUNC(FULL_PATHNAME, WARN) \
+ FUNC(HAS_DOT, WARN) \
+ FUNC(HAS_DOTDOT, WARN) \
+ FUNC(HAS_DOTGIT, WARN) \
+ FUNC(NULL_SHA1, WARN) \
+ FUNC(ZERO_PADDED_FILEMODE, WARN) \
+ FUNC(NUL_IN_COMMIT, WARN) \
+ /* infos (reported as warnings, but ignored by default) */ \
+ FUNC(GITMODULES_PARSE, INFO) \
+ FUNC(BAD_TAG_NAME, INFO) \
+ FUNC(MISSING_TAGGER_ENTRY, INFO) \
+ /* ignored (elevated when requested) */ \
+ FUNC(EXTRA_HEADER_ENTRY, IGNORE)
+
+#define MSG_ID(id, msg_type) FSCK_MSG_##id,
+enum fsck_msg_id {
+ FOREACH_FSCK_MSG_ID(MSG_ID)
+ FSCK_MSG_MAX
+};
+#undef MSG_ID
+
struct fsck_options;
struct object;
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (17 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 16/22] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
` (4 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the fsck_error callback to also pass along the
fsck_msg_id. Before this change the only way to get the message id was
to parse it back out of the "message".
Let's pass it down explicitly for the benefit of callers that might
want to use it, as discussed in [1].
Passing the msg_type is now redundant, as you can always get it back
from the msg_id, but I'm not changing that convention. It's really
common to need the msg_type, and the report() function itself (which
calls "fsck_error") needs to call fsck_msg_type() to discover
it. Let's not needlessly re-do that work in the user callback.
1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/fsck.c | 4 +++-
builtin/index-pack.c | 3 ++-
builtin/mktag.c | 1 +
fsck.c | 6 ++++--
fsck.h | 6 ++++--
5 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d6d745dc702..b71fac4ceca 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -89,7 +89,9 @@ static int objerror(struct object *obj, const char *err)
static int fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
switch (msg_type) {
case FSCK_WARN:
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 56b8efaa89b..2b2266a4b7d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
printf("%s\n", oid_to_hex(oid));
return 0;
}
- return fsck_error_function(o, oid, object_type, msg_type, message);
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
}
int cmd_index_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1834394a9b6..dc989c356f5 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -23,6 +23,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
const char *message)
{
switch (msg_type) {
diff --git a/fsck.c b/fsck.c
index 8a66168e516..5a040eb4fd5 100644
--- a/fsck.c
+++ b/fsck.c
@@ -245,7 +245,7 @@ static int report(struct fsck_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(options, oid, object_type,
- msg_type, sb.buf);
+ msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message)
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
{
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index c3d3b47b88b..33ecf3f3f16 100644
--- a/fsck.h
+++ b/fsck.h
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
typedef int (*fsck_error)(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid, enum object_type object_type,
- enum fsck_msg_type msg_type, const char *message);
+ enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+ const char *message);
struct fsck_options {
fsck_walk_func walk;
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (18 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 17/22] fsck.c: pass along the fsck_msg_id in the fsck_error callback Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 19/22] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
` (3 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change code I added in acf9de4c94e (mktag: use fsck instead of custom
verify_tag(), 2021-01-05) to make use of a new API function that takes
the fsck_msg_{id,type} types, instead of arbitrary strings that
we'll (hopefully) parse into those types.
At the time that the fsck_set_msg_type() API was introduced in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) it was only intended to be used to parse user-supplied
data.
For things that are purely internal to the C code it makes sense to
have the compiler check these arguments, and to skip the sanity
checking of the data in fsck_set_msg_type() which is redundant to
checks we get from the compiler.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/mktag.c | 3 ++-
fsck.c | 27 +++++++++++++++++----------
fsck.h | 3 +++
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index dc989c356f5..de67a94f24e 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -93,7 +93,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
die_errno(_("could not read from stdin"));
fsck_options.error_func = mktag_fsck_error_func;
- fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+ fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+ FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
git_config(mktag_config, NULL);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
diff --git a/fsck.c b/fsck.c
index 5a040eb4fd5..f26f47b2a10 100644
--- a/fsck.c
+++ b/fsck.c
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
return 1;
}
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type)
+{
+ if (!options->msg_type) {
+ int i;
+ enum fsck_msg_type *severity;
+ ALLOC_ARRAY(severity, FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
+ severity[i] = fsck_msg_type(i, options);
+ options->msg_type = severity;
+ }
+
+ options->msg_type[msg_id] = msg_type;
+}
+
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
- if (!options->msg_type) {
- int i;
- enum fsck_msg_type *severity;
- ALLOC_ARRAY(severity, FSCK_MSG_MAX);
- for (i = 0; i < FSCK_MSG_MAX; i++)
- severity[i] = fsck_msg_type(i, options);
- options->msg_type = severity;
- }
-
- options->msg_type[msg_id] = msg_type;
+ fsck_set_msg_type_from_ids(options, msg_id, msg_type);
}
void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index 33ecf3f3f16..6c2fd9c5cc0 100644
--- a/fsck.h
+++ b/fsck.h
@@ -82,6 +82,9 @@ enum fsck_msg_id {
struct fsck_options;
struct object;
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+ enum fsck_msg_id msg_id,
+ enum fsck_msg_type msg_type);
void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id, const char *msg_type);
void fsck_set_msg_types(struct fsck_options *options, const char *values);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 19/22] fsck.c: move gitmodules_{found,done} into fsck_options
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (19 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 18/22] fsck.c: add an fsck_set_msg_type() API that takes enums Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 20/22] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
` (2 subsequent siblings)
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Move the gitmodules_{found,done} static variables added in
159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the
fsck_options struct. It makes sense to keep all the context in the
same place.
This requires changing the recently added register_found_gitmodules()
function added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) to take fsck_options. That function will be
removed in a subsequent commit, but as it'll require the new
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 2 +-
fsck.c | 23 ++++++++++-------------
fsck.h | 7 ++++++-
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 0cb59acc486..53d7ef00856 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(oid);
+ register_found_gitmodules(&fo, oid);
if (fsck_finish(&fo))
die("fsck failed");
}
diff --git a/fsck.c b/fsck.c
index f26f47b2a10..565274a946c 100644
--- a/fsck.c
+++ b/fsck.c
@@ -19,9 +19,6 @@
#include "credential.h"
#include "help.h"
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
#define STR(x) #x
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
static struct {
@@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid,
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options,
oid, OBJ_TREE,
@@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid,
has_dotgit |= is_ntfs_dotgit(backslash);
if (is_ntfs_dotgitmodules(backslash)) {
if (!S_ISLNK(mode))
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
else
retval += report(options, oid, OBJ_TREE,
FSCK_MSG_GITMODULES_SYMLINK,
@@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
struct fsck_gitmodules_data data;
struct config_options config_opts = { 0 };
- if (!oidset_contains(&gitmodules_found, oid))
+ if (!oidset_contains(&options->gitmodules_found, oid))
return 0;
- oidset_insert(&gitmodules_done, oid);
+ oidset_insert(&options->gitmodules_done, oid);
if (object_on_skiplist(options, oid))
return 0;
@@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(const struct object_id *oid)
+void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
{
- oidset_insert(&gitmodules_found, oid);
+ oidset_insert(&options->gitmodules_found, oid);
}
int fsck_finish(struct fsck_options *options)
@@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options)
struct oidset_iter iter;
const struct object_id *oid;
- oidset_iter_init(&gitmodules_found, &iter);
+ oidset_iter_init(&options->gitmodules_found, &iter);
while ((oid = oidset_iter_next(&iter))) {
enum object_type type;
unsigned long size;
char *buf;
- if (oidset_contains(&gitmodules_done, oid))
+ if (oidset_contains(&options->gitmodules_done, oid))
continue;
buf = read_object_file(oid, &type, &size);
@@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options)
}
- oidset_clear(&gitmodules_found);
- oidset_clear(&gitmodules_done);
+ oidset_clear(&options->gitmodules_found);
+ oidset_clear(&options->gitmodules_done);
return ret;
}
diff --git a/fsck.h b/fsck.h
index 6c2fd9c5cc0..bb59ef05b68 100644
--- a/fsck.h
+++ b/fsck.h
@@ -118,6 +118,8 @@ struct fsck_options {
unsigned strict:1;
enum fsck_msg_type *msg_type;
struct oidset skiplist;
+ struct oidset gitmodules_found;
+ struct oidset gitmodules_done;
kh_oid_map_t *object_names;
};
@@ -125,6 +127,8 @@ struct fsck_options {
.walk = NULL, \
.msg_type = NULL, \
.skiplist = OIDSET_INIT, \
+ .gitmodules_found = OIDSET_INIT, \
+ .gitmodules_done = OIDSET_INIT, \
.object_names = NULL,
#define FSCK_OPTIONS_COMMON_ERROR_FUNC \
FSCK_OPTIONS_COMMON \
@@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(const struct object_id *oid);
+void register_found_gitmodules(struct fsck_options *options,
+ const struct object_id *oid);
/*
* fsck a tag, and pass info about it back to the caller. This is
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 20/22] fetch-pack: don't needlessly copy fsck_options
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (20 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 19/22] fsck.c: move gitmodules_{found,done} into fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 21/22] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change the behavior of the .gitmodules validation added in
5476e1efde (fetch-pack: print and use dangling .gitmodules,
2021-02-22) so we're using one "fsck_options".
I found that code confusing to read. One might think that not setting
up the error_func earlier means that we're relying on the "error_func"
not being set in some code in between the two hunks being modified
here.
But we're not, all we're doing in the rest of "cmd_index_pack()" is
further setup by calling fsck_set_msg_types(), and assigning to
do_fsck_object.
So there was no reason in 5476e1efde to make a shallow copy of the
fsck_options struct before setting error_func. Let's just do this
setup at the top of the function, along with the "walk" assignment.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/index-pack.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2b2266a4b7d..5ad80b85b47 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
+ fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
@@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
else
close(input_fd);
- if (do_fsck_object) {
- struct fsck_options fo = fsck_options;
-
- fo.error_func = print_dangling_gitmodules;
- if (fsck_finish(&fo))
- die(_("fsck error in pack objects"));
- }
+ if (do_fsck_object && fsck_finish(&fsck_options))
+ die(_("fsck error in pack objects"));
free(objects);
strbuf_release(&index_name_buf);
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 21/22] fetch-pack: use file-scope static struct for fsck_options
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (21 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 20/22] fetch-pack: don't needlessly copy fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
2021-03-06 11:04 ` [PATCH v3 22/22] fetch-pack: use new fsck API to printing dangling submodules Ævar Arnfjörð Bjarmason
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Change code added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) so that we use a file-scoped "static struct
fsck_options" instead of defining one in the "fsck_gitmodules_oids()"
function.
We use this pattern in all of
builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see
fetch-pack be the odd one out. One might think that we're using other
fsck_options structs in fetch-pack, or doing on fsck twice there, but
we're not.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
fetch-pack.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 53d7ef00856..f961c3067cd 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,6 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
{
struct oidset_iter iter;
const struct object_id *oid;
- struct fsck_options fo = FSCK_OPTIONS_STRICT;
if (!oidset_size(gitmodules_oids))
return;
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fo, oid);
- if (fsck_finish(&fo))
+ register_found_gitmodules(&fsck_options, oid);
+ if (fsck_finish(&fsck_options))
die("fsck failed");
}
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread
* [PATCH v3 22/22] fetch-pack: use new fsck API to printing dangling submodules
2021-02-18 10:58 ` [PATCH v2 00/10] fsck: API improvements (no conflicts with 'seen') Ævar Arnfjörð Bjarmason
` (22 preceding siblings ...)
2021-03-06 11:04 ` [PATCH v3 21/22] fetch-pack: use file-scope static struct for fsck_options Ævar Arnfjörð Bjarmason
@ 2021-03-06 11:04 ` Ævar Arnfjörð Bjarmason
23 siblings, 0 replies; 229+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-03-06 11:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Jeff King, Johannes Schindelin, Jonathan Tan,
Ævar Arnfjörð Bjarmason
Refactor the check added in 5476e1efde (fetch-pack: print and use
dangling .gitmodules, 2021-02-22) to make use of us now passing the
"msg_id" to the user defined "error_func". We can now compare against
the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated
message.
Let's also replace register_found_gitmodules() with directly
manipulating the "gitmodules_found" member. A recent commit moved it
into "fsck_options" so we could do this here.
Add a fsck-cb.c file similar to parse-options-cb.c, the alternative
would be to either define this directly in fsck.c as a public API, or
to create some library shared by fetch-pack.c ad builtin/index-pack.
I expect that there won't be many of these fsck utility functions in
the future, so just having a single fsck-cb.c makes sense.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
Makefile | 1 +
builtin/index-pack.c | 21 +--------------------
fetch-pack.c | 4 ++--
fsck-cb.c | 16 ++++++++++++++++
fsck.c | 5 -----
fsck.h | 22 +++++++++++++++++++---
6 files changed, 39 insertions(+), 30 deletions(-)
create mode 100644 fsck-cb.c
diff --git a/Makefile b/Makefile
index dd08b4ced01..5bf128c5d2c 100644
--- a/Makefile
+++ b/Makefile
@@ -879,6 +879,7 @@ LIB_OBJS += fetch-negotiator.o
LIB_OBJS += fetch-pack.o
LIB_OBJS += fmt-merge-msg.o
LIB_OBJS += fsck.o
+LIB_OBJS += fsck-cb.o
LIB_OBJS += fsmonitor.o
LIB_OBJS += gettext.o
LIB_OBJS += gpg-interface.o
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5ad80b85b47..11f0fafd33b 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -120,7 +120,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 struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static int verbose;
static int show_resolving_progress;
static int show_stat;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only)
}
}
-static int print_dangling_gitmodules(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
- const char *message)
-{
- /*
- * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
- * instead of relying on this string check.
- */
- if (starts_with(message, "gitmodulesMissing")) {
- printf("%s\n", oid_to_hex(oid));
- return 0;
- }
- return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
-}
-
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
read_replace_refs = 0;
fsck_options.walk = mark_link;
- fsck_options.error_func = print_dangling_gitmodules;
reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
diff --git a/fetch-pack.c b/fetch-pack.c
index f961c3067cd..7fc305b65c4 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -38,7 +38,7 @@ static int server_supports_filtering;
static int advertise_sid;
static struct shallow_lock shallow_lock;
static const char *alternate_shallow_file;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
static struct strbuf fsck_msg_types = STRBUF_INIT;
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
oidset_iter_init(gitmodules_oids, &iter);
while ((oid = oidset_iter_next(&iter)))
- register_found_gitmodules(&fsck_options, oid);
+ oidset_insert(&fsck_options.gitmodules_found, oid);
if (fsck_finish(&fsck_options))
die("fsck failed");
}
diff --git a/fsck-cb.c b/fsck-cb.c
new file mode 100644
index 00000000000..465a49235ac
--- /dev/null
+++ b/fsck-cb.c
@@ -0,0 +1,16 @@
+#include "git-compat-util.h"
+#include "fsck.h"
+
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message)
+{
+ if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
+ puts(oid_to_hex(oid));
+ return 0;
+ }
+ return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
+}
diff --git a/fsck.c b/fsck.c
index 565274a946c..b0089844db9 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o,
return 1;
}
-void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
-{
- oidset_insert(&options->gitmodules_found, oid);
-}
-
int fsck_finish(struct fsck_options *options)
{
int ret = 0;
diff --git a/fsck.h b/fsck.h
index bb59ef05b68..ae3107638ab 100644
--- a/fsck.h
+++ b/fsck.h
@@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
int fsck_object(struct object *obj, void *data, unsigned long size,
struct fsck_options *options);
-void register_found_gitmodules(struct fsck_options *options,
- const struct object_id *oid);
-
/*
* fsck a tag, and pass info about it back to the caller. This is
* exposed fsck_object() internals for git-mktag(1).
@@ -204,4 +201,23 @@ const char *fsck_describe_object(struct fsck_options *options,
int fsck_config_internal(const char *var, const char *value, void *cb,
struct fsck_options *options);
+/*
+ * Initializations for callbacks in fsck-cb.c
+ */
+#define FSCK_OPTIONS_MISSING_GITMODULES { \
+ .strict = 1, \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ FSCK_OPTIONS_COMMON \
+}
+
+/*
+ * Error callbacks in fsck-cb.c
+ */
+int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
+ const struct object_id *oid,
+ enum object_type object_type,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id,
+ const char *message);
+
#endif
--
2.31.0.rc0.126.g04f22c5b82
^ permalink raw reply related [flat|nested] 229+ messages in thread