Re: [PATCH v3 2/8] help: make autocorrect handling reusable
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Mar 10, 2026, 12:52 UTC
- Message-ID
- <CAOLa=ZQypadiSnU1hqHBUzzayGvvvv0z-X+-vNJRFgREmdB+qg@mail.gmail.com>
- In-Reply-To
- <SY0P300MB08017404C417D02058423130CE46A@SY0P300MB0801.AUSP300.PROD.OUTLOOK.COM>
Jiamu Sun <39@barroit.sh> writes:
Show 26 quoted lines
> Move config parsing and prompt/delay handling into autocorrect.c and > expose them in autocorrect.h. This makes autocorrect reusable regardless > of which target links against it. > > Signed-off-by: Jiamu Sun <39@barroit.sh> > --- > This patch moves autocorrect handling out of help.c as a preparatory > step for subcommand autocorrection. > > This is necessary because help.c uses load_builtin_commands(), which is > provided by git.o. Executables that do not link against git.o, such as > git-daemon, will hit a link error if they use symbols defined in help.o. > A simple and clean fix is to make the relevant functions independent of > help.c and move them to a dedicated file. > > Changes in v3: > - Split patch so diffs don't get hidden by code movement > > Makefile | 1 + > autocorrect.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ > autocorrect.h | 16 ++++++++++++ > help.c | 64 +++------------------------------------------ > 4 files changed, 93 insertions(+), 60 deletions(-) > create mode 100644 autocorrect.c > create mode 100644 autocorrect.h >
This should also be added to meson.build.
[snip]
Show 21 quoted lines
> diff --git a/autocorrect.h b/autocorrect.h > new file mode 100644 > index 000000000000..45609990c77e > --- /dev/null > +++ b/autocorrect.h > @@ -0,0 +1,16 @@ > +#ifndef AUTOCORRECT_H > +#define AUTOCORRECT_H > + > +#define AUTOCORRECT_SHOW (-4) > +#define AUTOCORRECT_PROMPT (-3) > +#define AUTOCORRECT_NEVER (-2) > +#define AUTOCORRECT_IMMEDIATELY (-1) > + > +struct config_context; > + > +void autocorr_resolve_config(const char *var, const char *value, > + const struct config_context *ctx, void *data); > + > +void autocorr_confirm(int autocorr, const char *assumed); > +
Why not use s/autocorr/autocorrect/ ? Also would be nice to add some documentation about each of the functions here.
[snip]
Also got this from running `git-clang-format` on this commit. Generally applying changes while moving code makes it harder to review. But here the changes are small enough that we could get away with it. I'll leave it to you.
diff --git a/autocorrect.c b/autocorrect.c index 1037f03201..87351fd08f 100644 --- a/autocorrect.c +++ b/autocorrect.c @@ -9,12 +9,12 @@ static int parse_autocorrect(const char *value) { switch (git_parse_maybe_bool_text(value)) { - case 1: - return AUTOCORRECT_IMMEDIATELY; - case 0: - return AUTOCORRECT_SHOW; - default: /* other random text */ - break; + case 1: + return AUTOCORRECT_IMMEDIATELY; + case 0: + return AUTOCORRECT_SHOW; + default: /* other random text */ + break; } if (!strcmp(value, "prompt")) diff --git a/autocorrect.h b/autocorrect.h index 45609990c7..38f1e73131 100644 --- a/autocorrect.h +++ b/autocorrect.h @@ -1,9 +1,9 @@ #ifndef AUTOCORRECT_H #define AUTOCORRECT_H -#define AUTOCORRECT_SHOW (-4) -#define AUTOCORRECT_PROMPT (-3) -#define AUTOCORRECT_NEVER (-2) +#define AUTOCORRECT_SHOW (-4) +#define AUTOCORRECT_PROMPT (-3) +#define AUTOCORRECT_NEVER (-2) #define AUTOCORRECT_IMMEDIATELY (-1) struct config_context;