diff options
author | Brandon Williams <bmwill@google.com> | 2017-01-27 18:02:07 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-01 13:46:53 -0800 |
commit | f0dd042148233ad4681b29f35f3bc3ba3b962474 (patch) | |
tree | d748ff9b661d486df12146ee48e542359f2690a5 | |
parent | 0787dafdccfb09b26501293f72db74638c3834ad (diff) | |
download | git-f0dd042148233ad4681b29f35f3bc3ba3b962474.tar.gz |
attr: reformat git_attr_set_direction() functionbw/attr
Move the 'git_attr_set_direction()' up to be closer to the variables
that it modifies as well as a small formatting by renaming the variable
'new' to 'new_direction' so that it is more descriptive.
Update the comment about how 'direction' is used to read the state of
the world. It should be noted that callers of
'git_attr_set_direction()' should ensure that other threads are not
making calls into the attribute system until after the call to
'git_attr_set_direction()' completes. This function essentially acts as
reset button for the attribute system and should be handled with care.
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | attr.c | 49 | ||||
-rw-r--r-- | attr.h | 3 |
2 files changed, 22 insertions, 30 deletions
@@ -677,26 +677,30 @@ static struct attr_stack *read_attr_from_array(const char **list) } /* - * NEEDSWORK: these two are tricky. The callers assume there is a - * single, system-wide global state "where we read attributes from?" - * and when the state is flipped by calling git_attr_set_direction(), - * attr_stack is discarded so that subsequent attr_check will lazily - * read from the right place. And they do not know or care who called - * by them uses the attribute subsystem, hence have no knowledge of - * existing git_attr_check instances or future ones that will be - * created). - * - * Probably we need a thread_local that holds these two variables, - * and a list of git_attr_check instances (which need to be maintained - * by hooking into git_attr_check_alloc(), git_attr_check_initl(), and - * git_attr_check_clear(). Then git_attr_set_direction() updates the - * fields in that thread_local for these two variables, iterate over - * all the active git_attr_check instances and discard the attr_stack - * they hold. Yuck, but it sounds doable. + * Callers into the attribute system assume there is a single, system-wide + * global state where attributes are read from and when the state is flipped by + * calling git_attr_set_direction(), the stack frames that have been + * constructed need to be discarded so so that subsequent calls into the + * attribute system will lazily read from the right place. Since changing + * direction causes a global paradigm shift, it should not ever be called while + * another thread could potentially be calling into the attribute system. */ static enum git_attr_direction direction; static struct index_state *use_index; +void git_attr_set_direction(enum git_attr_direction new_direction, + struct index_state *istate) +{ + if (is_bare_repository() && new_direction != GIT_ATTR_INDEX) + die("BUG: non-INDEX attr direction in a bare repo"); + + if (new_direction != direction) + drop_all_attr_stacks(); + + direction = new_direction; + use_index = istate; +} + static struct attr_stack *read_attr_from_file(const char *path, int macro_ok) { FILE *fp = fopen(path, "r"); @@ -1148,19 +1152,6 @@ void git_all_attrs(const char *path, struct attr_check *check) } } -void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate) -{ - enum git_attr_direction old = direction; - - if (is_bare_repository() && new != GIT_ATTR_INDEX) - die("BUG: non-INDEX attr direction in a bare repo"); - - direction = new; - if (new != old) - drop_all_attr_stacks(); - use_index = istate; -} - void attr_start(void) { #ifndef NO_PTHREADS @@ -72,7 +72,8 @@ enum git_attr_direction { GIT_ATTR_CHECKOUT, GIT_ATTR_INDEX }; -void git_attr_set_direction(enum git_attr_direction, struct index_state *); +void git_attr_set_direction(enum git_attr_direction new_direction, + struct index_state *istate); extern void attr_start(void); |