]> git.proxmox.com Git - libgit2.git/blobdiff - src/attr.c
Merge pull request #968 from arrbee/diff-support-typechange
[libgit2.git] / src / attr.c
index 1c511993b529c85c8533a9f9f274cfbf8fdcc5a3..025ad3c87236712fe67c2caa8b7ce114776c2992 100644 (file)
@@ -1,6 +1,7 @@
 #include "repository.h"
 #include "fileops.h"
 #include "config.h"
+#include "git2/oid.h"
 #include <ctype.h>
 
 GIT__USE_STRMAP;
@@ -41,7 +42,7 @@ int git_attr_get(
        int error;
        git_attr_path path;
        git_vector files = GIT_VECTOR_INIT;
-       unsigned int i, j;
+       size_t i, j;
        git_attr_file *file;
        git_attr_name attr;
        git_attr_rule *rule;
@@ -93,7 +94,7 @@ int git_attr_get_many(
        int error;
        git_attr_path path;
        git_vector files = GIT_VECTOR_INIT;
-       unsigned int i, j, k;
+       size_t i, j, k;
        git_attr_file *file;
        git_attr_rule *rule;
        attr_get_many_info *info = NULL;
@@ -157,7 +158,7 @@ int git_attr_foreach(
        int error;
        git_attr_path path;
        git_vector files = GIT_VECTOR_INIT;
-       unsigned int i, j, k;
+       size_t i, j, k;
        git_attr_file *file;
        git_attr_rule *rule;
        git_attr_assignment *assign;
@@ -182,11 +183,15 @@ int git_attr_foreach(
                                        continue;
 
                                git_strmap_insert(seen, assign->name, assign, error);
-                               if (error >= 0)
-                                       error = callback(assign->name, assign->value, payload);
+                               if (error < 0)
+                                       goto cleanup;
 
-                               if (error != 0)
+                               error = callback(assign->name, assign->value, payload);
+                               if (error) {
+                                       giterr_clear();
+                                       error = GIT_EUSER;
                                        goto cleanup;
+                               }
                        }
                }
        }
@@ -371,6 +376,7 @@ int git_attr_cache__push_file(
        const char *filename,
        git_attr_file_source source,
        git_attr_file_parser parse,
+       void* parsedata,
        git_vector *stack)
 {
        int error = 0;
@@ -431,7 +437,7 @@ int git_attr_cache__push_file(
                        goto finish;
        }
 
-       if (parse && (error = parse(repo, content, file)) < 0)
+       if (parse && (error = parse(repo, parsedata, content, file)) < 0)
                goto finish;
 
        git_strmap_insert(cache->files, file->key, file, error); //-V595
@@ -463,7 +469,7 @@ finish:
 }
 
 #define push_attr_file(R,S,B,F) \
-       git_attr_cache__push_file((R),(B),(F),GIT_ATTR_FILE_FROM_FILE,git_attr_file__parse_buffer,(S))
+       git_attr_cache__push_file((R),(B),(F),GIT_ATTR_FILE_FROM_FILE,git_attr_file__parse_buffer,NULL,(S))
 
 typedef struct {
        git_repository *repo;
@@ -512,7 +518,7 @@ static int push_one_attr(void *ref, git_buf *path)
        for (i = 0; !error && i < n_src; ++i)
                error = git_attr_cache__push_file(
                        info->repo, path->ptr, GIT_ATTR_FILE, src[i],
-                       git_attr_file__parse_buffer, info->files);
+                       git_attr_file__parse_buffer, NULL, info->files);
 
        return error;
 }
@@ -586,6 +592,18 @@ static int collect_attr_files(
        return error;
 }
 
+static char *try_global_default(const char *relpath)
+{
+       git_buf dflt = GIT_BUF_INIT;
+       char *rval = NULL;
+
+       if (!git_futils_find_global_file(&dflt, relpath))
+               rval = git_buf_detach(&dflt);
+
+       git_buf_free(&dflt);
+
+       return rval;
+}
 
 int git_attr_cache__init(git_repository *repo)
 {
@@ -603,10 +621,14 @@ int git_attr_cache__init(git_repository *repo)
        ret = git_config_get_string(&cache->cfg_attr_file, cfg, GIT_ATTR_CONFIG);
        if (ret < 0 && ret != GIT_ENOTFOUND)
                return ret;
+       if (ret == GIT_ENOTFOUND)
+               cache->cfg_attr_file = try_global_default(GIT_ATTR_CONFIG_DEFAULT);
 
        ret = git_config_get_string(&cache->cfg_excl_file, cfg, GIT_IGNORE_CONFIG);
        if (ret < 0 && ret != GIT_ENOTFOUND)
                return ret;
+       if (ret == GIT_ENOTFOUND)
+               cache->cfg_excl_file = try_global_default(GIT_IGNORE_CONFIG_DEFAULT);
 
        giterr_clear();