Message ID | 2726f6dc05c319e2baaf76a05d62426e0695fe65.1604521275.git.matheus.bernardino@usp.br (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Parallel Checkout (part I) | expand |
On Wed, Nov 4, 2020 at 9:33 PM Matheus Tavares <matheus.bernardino@usp.br> wrote: > > From: Jeff Hostetler <jeffhost@microsoft.com> > > Move convert_attrs() declaration from convert.c to convert.h, together > with the conv_attrs struct and the crlf_action enum. This function and > the data structures will be used outside convert.c in the upcoming > parallel checkout implementation. Note that crlf_action is renamed to > convert_crlf_action, which is more appropriate for the global namespace. It annoys me a bit that some things are called "conv_*" and others "convert_*". Maybe we could standardize everything, but it could be a separate patch series. > Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> > [matheus.bernardino: squash and reword msg] Not sure we want the above line, which could actually not be completely true if you rework the patch before it gets merged. > Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> > --- a/convert.h > +++ b/convert.h > @@ -63,6 +63,30 @@ struct checkout_metadata { > struct object_id blob; > }; > > +enum convert_crlf_action { > + CRLF_UNDEFINED, > + CRLF_BINARY, > + CRLF_TEXT, > + CRLF_TEXT_INPUT, > + CRLF_TEXT_CRLF, > + CRLF_AUTO, > + CRLF_AUTO_INPUT, > + CRLF_AUTO_CRLF > +}; Maybe we should also prepend "CONVERT_" to the values?
On Sat, Dec 5, 2020 at 7:40 AM Christian Couder <christian.couder@gmail.com> wrote: > > On Wed, Nov 4, 2020 at 9:33 PM Matheus Tavares > <matheus.bernardino@usp.br> wrote: > > > > From: Jeff Hostetler <jeffhost@microsoft.com> > > > > Move convert_attrs() declaration from convert.c to convert.h, together > > with the conv_attrs struct and the crlf_action enum. This function and > > the data structures will be used outside convert.c in the upcoming > > parallel checkout implementation. Note that crlf_action is renamed to > > convert_crlf_action, which is more appropriate for the global namespace. > > It annoys me a bit that some things are called "conv_*" and others > "convert_*". Maybe we could standardize everything, but it could be a > separate patch series. > > > Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> > > [matheus.bernardino: squash and reword msg] > > Not sure we want the above line, which could actually not be > completely true if you rework the patch before it gets merged. Right, I'll remove this line from this and the next patches. Thanks. > > Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> > > > --- a/convert.h > > +++ b/convert.h > > @@ -63,6 +63,30 @@ struct checkout_metadata { > > struct object_id blob; > > }; > > > > +enum convert_crlf_action { > > + CRLF_UNDEFINED, > > + CRLF_BINARY, > > + CRLF_TEXT, > > + CRLF_TEXT_INPUT, > > + CRLF_TEXT_CRLF, > > + CRLF_AUTO, > > + CRLF_AUTO_INPUT, > > + CRLF_AUTO_CRLF > > +}; > > Maybe we should also prepend "CONVERT_" to the values? Yeah, I also wondered about that. But I wasn't sure if it was worth the change since there are about 52 occurrences of them. Junio later mentioned [1] that it might be OK to leave them as-is since the use sites will always pass these values to the API functions, which would make it clear that they are from the "convert_" family. [1]: https://lore.kernel.org/git/xmqqd00z397m.fsf@gitster.c.googlers.com/
diff --git a/convert.c b/convert.c index ee360c2f07..f13b001273 100644 --- a/convert.c +++ b/convert.c @@ -24,17 +24,6 @@ #define CONVERT_STAT_BITS_TXT_CRLF 0x2 #define CONVERT_STAT_BITS_BIN 0x4 -enum crlf_action { - CRLF_UNDEFINED, - CRLF_BINARY, - CRLF_TEXT, - CRLF_TEXT_INPUT, - CRLF_TEXT_CRLF, - CRLF_AUTO, - CRLF_AUTO_INPUT, - CRLF_AUTO_CRLF -}; - struct text_stat { /* NUL, CR, LF and CRLF counts */ unsigned nul, lonecr, lonelf, crlf; @@ -172,7 +161,7 @@ static int text_eol_is_crlf(void) return 0; } -static enum eol output_eol(enum crlf_action crlf_action) +static enum eol output_eol(enum convert_crlf_action crlf_action) { switch (crlf_action) { case CRLF_BINARY: @@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path) } static int will_convert_lf_to_crlf(struct text_stat *stats, - enum crlf_action crlf_action) + enum convert_crlf_action crlf_action) { if (output_eol(crlf_action) != EOL_CRLF) return 0; @@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len, static int crlf_to_git(const struct index_state *istate, const char *path, const char *src, size_t len, struct strbuf *buf, - enum crlf_action crlf_action, int conv_flags) + enum convert_crlf_action crlf_action, int conv_flags) { struct text_stat stats; char *dst; @@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate, return 1; } -static int crlf_to_worktree(const char *src, size_t len, - struct strbuf *buf, enum crlf_action crlf_action) +static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf, + enum convert_crlf_action crlf_action) { char *to_free = NULL; struct text_stat stats; @@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check) return value; } -static enum crlf_action git_path_check_crlf(struct attr_check_item *check) +static enum convert_crlf_action git_path_check_crlf(struct attr_check_item *check) { const char *value = check->value; @@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check) return !!ATTR_TRUE(value); } -struct conv_attrs { - struct convert_driver *drv; - enum crlf_action attr_action; /* What attr says */ - enum crlf_action crlf_action; /* When no attr is set, use core.autocrlf */ - int ident; - const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */ -}; - static struct attr_check *check; -static void convert_attrs(const struct index_state *istate, - struct conv_attrs *ca, const char *path) +void convert_attrs(const struct index_state *istate, + struct conv_attrs *ca, const char *path) { struct attr_check_item *ccheck = NULL; diff --git a/convert.h b/convert.h index e29d1026a6..5678e99922 100644 --- a/convert.h +++ b/convert.h @@ -63,6 +63,30 @@ struct checkout_metadata { struct object_id blob; }; +enum convert_crlf_action { + CRLF_UNDEFINED, + CRLF_BINARY, + CRLF_TEXT, + CRLF_TEXT_INPUT, + CRLF_TEXT_CRLF, + CRLF_AUTO, + CRLF_AUTO_INPUT, + CRLF_AUTO_CRLF +}; + +struct convert_driver; + +struct conv_attrs { + struct convert_driver *drv; + enum convert_crlf_action attr_action; /* What attr says */ + enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */ + int ident; + const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */ +}; + +void convert_attrs(const struct index_state *istate, + struct conv_attrs *ca, const char *path); + extern enum eol core_eol; extern char *check_roundtrip_encoding; const char *get_cached_convert_stats_ascii(const struct index_state *istate,