Merge branch 'jk/attr-macro-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:16 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:16 +0000 (14:26 -0800)
Asking "git check-attr" about a macro (e.g. "binary") on a specific
path did not work correctly, even though "git check-attr -a" listed
such a macro correctly. This has been corrected.

* jk/attr-macro-fix:
attr: do not mark queried macros as unset

1  2 
attr.c
diff --combined attr.c
index b63fe0fc0e99caa07dc2e6da816e1ac8d5942df6,293755226cdb78fc48c3992213d2db188e9b96ed..0cba78912907e35a26e43156e124912467e46b27
--- 1/attr.c
--- 2/attr.c
+++ b/attr.c
@@@ -41,17 -41,23 +41,17 @@@ const char *git_attr_name(const struct 
  
  struct attr_hashmap {
        struct hashmap map;
 -#ifndef NO_PTHREADS
        pthread_mutex_t mutex;
 -#endif
  };
  
  static inline void hashmap_lock(struct attr_hashmap *map)
  {
 -#ifndef NO_PTHREADS
        pthread_mutex_lock(&map->mutex);
 -#endif
  }
  
  static inline void hashmap_unlock(struct attr_hashmap *map)
  {
 -#ifndef NO_PTHREADS
        pthread_mutex_unlock(&map->mutex);
 -#endif
  }
  
  /*
@@@ -366,8 -372,8 +366,8 @@@ static struct match_attr *parse_attr_li
        if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen &&
            starts_with(name, ATTRIBUTE_MACRO_PREFIX)) {
                if (!macro_ok) {
 -                      fprintf(stderr, "%s not allowed: %s:%d\n",
 -                              name, src, lineno);
 +                      fprintf_ln(stderr, _("%s not allowed: %s:%d"),
 +                                 name, src, lineno);
                        goto fail_return;
                }
                is_macro = 1;
@@@ -492,17 -498,23 +492,17 @@@ static struct check_vector 
        size_t nr;
        size_t alloc;
        struct attr_check **checks;
 -#ifndef NO_PTHREADS
        pthread_mutex_t mutex;
 -#endif
  } check_vector;
  
  static inline void vector_lock(void)
  {
 -#ifndef NO_PTHREADS
        pthread_mutex_lock(&check_vector.mutex);
 -#endif
  }
  
  static inline void vector_unlock(void)
  {
 -#ifndef NO_PTHREADS
        pthread_mutex_unlock(&check_vector.mutex);
 -#endif
  }
  
  static void check_vector_add(struct attr_check *c)
@@@ -1092,7 -1104,7 +1092,7 @@@ static void collect_some_attrs(const st
                               const char *path,
                               struct attr_check *check)
  {
-       int i, pathlen, rem, dirlen;
+       int pathlen, rem, dirlen;
        const char *cp, *last_slash = NULL;
        int basename_offset;
  
        all_attrs_init(&g_attr_hashmap, check);
        determine_macros(check->all_attrs, check->stack);
  
-       if (check->nr) {
-               rem = 0;
-               for (i = 0; i < check->nr; i++) {
-                       int n = check->items[i].attr->attr_nr;
-                       struct all_attrs_item *item = &check->all_attrs[n];
-                       if (item->macro) {
-                               item->value = ATTR__UNSET;
-                               rem++;
-                       }
-               }
-               if (rem == check->nr)
-                       return;
-       }
        rem = check->all_attrs_nr;
        fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
  }
@@@ -1169,6 -1167,8 +1155,6 @@@ void git_all_attrs(const struct index_s
  
  void attr_start(void)
  {
 -#ifndef NO_PTHREADS
        pthread_mutex_init(&g_attr_hashmap.mutex, NULL);
        pthread_mutex_init(&check_vector.mutex, NULL);
 -#endif
  }