diff.c: remove the_index dependency in textconv() functions
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 21 Sep 2018 15:57:22 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Sep 2018 16:48:10 +0000 (09:48 -0700)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
blame.c
builtin/cat-file.c
builtin/log.c
combine-diff.c
diff.c
diff.h
diffcore-pickaxe.c
grep.c
diff --git a/blame.c b/blame.c
index 98bf50d89a83108977b1673743365a8d78cdd096..9d57c76baa0951a369e6af49b72b6520cddd4e86 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
                        if (opt->flags.allow_textconv &&
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
                        if (opt->flags.allow_textconv &&
-                           textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
+                           textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
                                strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
                        else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
                                die_errno("cannot open or read '%s'", read_from);
                                strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
                        else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
                                die_errno("cannot open or read '%s'", read_from);
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
 
                (*num_read_blob)++;
                if (opt->flags.allow_textconv &&
 
                (*num_read_blob)++;
                if (opt->flags.allow_textconv &&
-                   textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
+                   textconv_object(opt->repo, o->path, o->mode,
+                                   &o->blob_oid, 1, &file->ptr, &file_size))
                        ;
                else
                        file->ptr = read_object_file(&o->blob_oid, &type,
                        ;
                else
                        file->ptr = read_object_file(&o->blob_oid, &type,
@@ -1857,7 +1858,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
                        die(_("no such path %s in %s"), path, final_commit_name);
 
                if (sb->revs->diffopt.flags.allow_textconv &&
                        die(_("no such path %s in %s"), path, final_commit_name);
 
                if (sb->revs->diffopt.flags.allow_textconv &&
-                   textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
+                   textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
                                    &sb->final_buf_size))
                        ;
                else
                                    &sb->final_buf_size))
                        ;
                else
index 64ec1745ab2c20ef18a9292ef3b3c82efd46de17..8d97c84725cd0f7f5347e8ca808072bd227d4d1c 100644 (file)
@@ -113,7 +113,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                        die("git cat-file --textconv %s: <object> must be <sha1:path>",
                            obj_name);
 
                        die("git cat-file --textconv %s: <object> must be <sha1:path>",
                            obj_name);
 
-               if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size))
+               if (textconv_object(the_repository, path, obj_context.mode,
+                                   &oid, 1, &buf, &size))
                        break;
                /* else fallthrough */
 
                        break;
                /* else fallthrough */
 
@@ -305,7 +306,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
                                            oid_to_hex(oid), data->rest);
                        } else if (opt->cmdmode == 'c') {
                                enum object_type type;
                                            oid_to_hex(oid), data->rest);
                        } else if (opt->cmdmode == 'c') {
                                enum object_type type;
-                               if (!textconv_object(data->rest, 0100644, oid,
+                               if (!textconv_object(the_repository,
+                                                    data->rest, 0100644, oid,
                                                     1, &contents, &size))
                                        contents = read_object_file(oid,
                                                                    &type,
                                                     1, &contents, &size))
                                        contents = read_object_file(oid,
                                                                    &type,
index e094560d9abca6e819c24b845dc7c04d384850c3..f32a07f6a9a535bd0f68d8a357189dadf0a13423 100644 (file)
@@ -507,7 +507,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
                                 &oidc, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path ||
                                 &oidc, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path ||
-           !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
+           !textconv_object(the_repository, obj_context.path,
+                            obj_context.mode, &oidc, 1, &buf, &size)) {
                free(obj_context.path);
                return stream_blob_to_fd(1, oid, NULL, 0);
        }
                free(obj_context.path);
                return stream_blob_to_fd(1, oid, NULL, 0);
        }
index 4fa7707b57dedc6317fa70e5135675f19e8b256f..9b43e557a1608145568f70b570038f6c202b5f1f 100644 (file)
@@ -285,7 +285,8 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
        return base;
 }
 
        return base;
 }
 
-static char *grab_blob(const struct object_id *oid, unsigned int mode,
+static char *grab_blob(struct repository *r,
+                      const struct object_id *oid, unsigned int mode,
                       unsigned long *size, struct userdiff_driver *textconv,
                       const char *path)
 {
                       unsigned long *size, struct userdiff_driver *textconv,
                       const char *path)
 {
@@ -304,7 +305,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
        } else if (textconv) {
                struct diff_filespec *df = alloc_filespec(path);
                fill_filespec(df, oid, 1, mode);
        } else if (textconv) {
                struct diff_filespec *df = alloc_filespec(path);
                fill_filespec(df, oid, 1, mode);
-               *size = fill_textconv(textconv, df, &blob);
+               *size = fill_textconv(r, textconv, df, &blob);
                free_filespec(df);
        } else {
                blob = read_object_file(oid, &type, size);
                free_filespec(df);
        } else {
                blob = read_object_file(oid, &type, size);
@@ -389,7 +390,8 @@ static void consume_line(void *state_, char *line, unsigned long len)
        }
 }
 
        }
 }
 
-static void combine_diff(const struct object_id *parent, unsigned int mode,
+static void combine_diff(struct repository *r,
+                        const struct object_id *parent, unsigned int mode,
                         mmfile_t *result_file,
                         struct sline *sline, unsigned int cnt, int n,
                         int num_parent, int result_deleted,
                         mmfile_t *result_file,
                         struct sline *sline, unsigned int cnt, int n,
                         int num_parent, int result_deleted,
@@ -407,7 +409,7 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
        if (result_deleted)
                return; /* result deleted */
 
        if (result_deleted)
                return; /* result deleted */
 
-       parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
+       parent_file.ptr = grab_blob(r, parent, mode, &sz, textconv, path);
        parent_file.size = sz;
        memset(&xpp, 0, sizeof(xpp));
        xpp.flags = flags;
        parent_file.size = sz;
        memset(&xpp, 0, sizeof(xpp));
        xpp.flags = flags;
@@ -993,7 +995,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 
        /* Read the result of merge first */
        if (!working_tree_file)
 
        /* Read the result of merge first */
        if (!working_tree_file)
-               result = grab_blob(&elem->oid, elem->mode, &result_size,
+               result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size,
                                   textconv, elem->path);
        else {
                /* Used by diff-tree to read from the working tree */
                                   textconv, elem->path);
        else {
                /* Used by diff-tree to read from the working tree */
@@ -1016,15 +1018,16 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                } else if (S_ISDIR(st.st_mode)) {
                        struct object_id oid;
                        if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
                } else if (S_ISDIR(st.st_mode)) {
                        struct object_id oid;
                        if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
-                               result = grab_blob(&elem->oid, elem->mode,
-                                                  &result_size, NULL, NULL);
+                               result = grab_blob(opt->repo, &elem->oid,
+                                                  elem->mode, &result_size,
+                                                  NULL, NULL);
                        else
                        else
-                               result = grab_blob(&oid, elem->mode,
+                               result = grab_blob(opt->repo, &oid, elem->mode,
                                                   &result_size, NULL, NULL);
                } else if (textconv) {
                        struct diff_filespec *df = alloc_filespec(elem->path);
                        fill_filespec(df, &null_oid, 0, st.st_mode);
                                                   &result_size, NULL, NULL);
                } else if (textconv) {
                        struct diff_filespec *df = alloc_filespec(elem->path);
                        fill_filespec(df, &null_oid, 0, st.st_mode);
-                       result_size = fill_textconv(textconv, df, &result);
+                       result_size = fill_textconv(opt->repo, textconv, df, &result);
                        free_filespec(df);
                } else if (0 <= (fd = open(elem->path, O_RDONLY))) {
                        size_t len = xsize_t(st.st_size);
                        free_filespec(df);
                } else if (0 <= (fd = open(elem->path, O_RDONLY))) {
                        size_t len = xsize_t(st.st_size);
@@ -1090,7 +1093,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                for (i = 0; !is_binary && i < num_parent; i++) {
                        char *buf;
                        unsigned long size;
                for (i = 0; !is_binary && i < num_parent; i++) {
                        char *buf;
                        unsigned long size;
-                       buf = grab_blob(&elem->parent[i].oid,
+                       buf = grab_blob(opt->repo,
+                                       &elem->parent[i].oid,
                                        elem->parent[i].mode,
                                        &size, NULL, NULL);
                        if (buffer_is_binary(buf, size))
                                        elem->parent[i].mode,
                                        &size, NULL, NULL);
                        if (buffer_is_binary(buf, size))
@@ -1146,7 +1150,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        }
                }
                if (i <= j)
                        }
                }
                if (i <= j)
-                       combine_diff(&elem->parent[i].oid,
+                       combine_diff(opt->repo,
+                                    &elem->parent[i].oid,
                                     elem->parent[i].mode,
                                     &result_file, sline,
                                     cnt, i, num_parent, result_deleted,
                                     elem->parent[i].mode,
                                     &result_file, sline,
                                     cnt, i, num_parent, result_deleted,
diff --git a/diff.c b/diff.c
index e5d6d30a676aacf7a8ee1888d208582765630183..0848ac65dfc56e31f99c861fd5e6a76634643150 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1700,8 +1700,8 @@ static void emit_rewrite_diff(const char *name_a,
        quote_two_c_style(&a_name, a_prefix, name_a, 0);
        quote_two_c_style(&b_name, b_prefix, name_b, 0);
 
        quote_two_c_style(&a_name, a_prefix, name_a, 0);
        quote_two_c_style(&b_name, b_prefix, name_b, 0);
 
-       size_one = fill_textconv(textconv_one, one, &data_one);
-       size_two = fill_textconv(textconv_two, two, &data_two);
+       size_one = fill_textconv(o->repo, textconv_one, one, &data_one);
+       size_two = fill_textconv(o->repo, textconv_two, two, &data_two);
 
        memset(&ecbdata, 0, sizeof(ecbdata));
        ecbdata.color_diff = want_color(o->use_color);
 
        memset(&ecbdata, 0, sizeof(ecbdata));
        ecbdata.color_diff = want_color(o->use_color);
@@ -3462,8 +3462,8 @@ static void builtin_diff(const char *name_a,
                        strbuf_reset(&header);
                }
 
                        strbuf_reset(&header);
                }
 
-               mf1.size = fill_textconv(textconv_one, one, &mf1.ptr);
-               mf2.size = fill_textconv(textconv_two, two, &mf2.ptr);
+               mf1.size = fill_textconv(o->repo, textconv_one, one, &mf1.ptr);
+               mf2.size = fill_textconv(o->repo, textconv_two, two, &mf2.ptr);
 
                pe = diff_funcname_pattern(one);
                if (!pe)
 
                pe = diff_funcname_pattern(one);
                if (!pe)
@@ -6337,11 +6337,11 @@ static char *run_textconv(struct repository *r,
        return strbuf_detach(&buf, outsize);
 }
 
        return strbuf_detach(&buf, outsize);
 }
 
-size_t fill_textconv(struct userdiff_driver *driver,
+size_t fill_textconv(struct repository *r,
+                    struct userdiff_driver *driver,
                     struct diff_filespec *df,
                     char **outbuf)
 {
                     struct diff_filespec *df,
                     char **outbuf)
 {
-       struct repository *r = the_repository;
        size_t size;
 
        if (!driver) {
        size_t size;
 
        if (!driver) {
@@ -6386,7 +6386,8 @@ size_t fill_textconv(struct userdiff_driver *driver,
        return size;
 }
 
        return size;
 }
 
-int textconv_object(const char *path,
+int textconv_object(struct repository *r,
+                   const char *path,
                    unsigned mode,
                    const struct object_id *oid,
                    int oid_valid,
                    unsigned mode,
                    const struct object_id *oid,
                    int oid_valid,
@@ -6404,7 +6405,7 @@ int textconv_object(const char *path,
                return 0;
        }
 
                return 0;
        }
 
-       *buf_size = fill_textconv(textconv, df, buf);
+       *buf_size = fill_textconv(r, textconv, df, buf);
        free_filespec(df);
        return 1;
 }
        free_filespec(df);
        return 1;
 }
diff --git a/diff.h b/diff.h
index 0b67932109eb72f7856a9073044e9765fc45860a..812f71d9535de13003e80b549e839e951186920d 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -442,7 +442,8 @@ int index_differs_from(const char *def, const struct diff_flags *flags,
  * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
  * that should be freed by the caller.
  */
  * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
  * that should be freed by the caller.
  */
-size_t fill_textconv(struct userdiff_driver *driver,
+size_t fill_textconv(struct repository *r,
+                    struct userdiff_driver *driver,
                     struct diff_filespec *df,
                     char **outbuf);
 
                     struct diff_filespec *df,
                     char **outbuf);
 
@@ -458,7 +459,11 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one);
  * if the textconv driver exists.
  * Return 1 if the conversion succeeds, 0 otherwise.
  */
  * if the textconv driver exists.
  * Return 1 if the conversion succeeds, 0 otherwise.
  */
-int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
+int textconv_object(struct repository *repo,
+                   const char *path,
+                   unsigned mode,
+                   const struct object_id *oid, int oid_valid,
+                   char **buf, unsigned long *buf_size);
 
 int parse_rename_score(const char **cp_p);
 
 
 int parse_rename_score(const char **cp_p);
 
index 800a899c8621eaeba7f4246139df0f289ceb6ee2..7a5cf446ff2d5e5313ba8c0984d439280e91abef 100644 (file)
@@ -153,8 +153,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
        if (textconv_one == textconv_two && diff_unmodified_pair(p))
                return 0;
 
        if (textconv_one == textconv_two && diff_unmodified_pair(p))
                return 0;
 
-       mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
-       mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
+       mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
+       mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
        ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
                 DIFF_FILE_VALID(p->two) ? &mf2 : NULL,
 
        ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
                 DIFF_FILE_VALID(p->two) ? &mf2 : NULL,
diff --git a/grep.c b/grep.c
index 2b26cee08d559ceba6dd5a83ae90aaa0155ebca8..e146ff20bb60b3e3126d40197cf3378afe616f55 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1741,7 +1741,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
         * structure.
         */
        grep_read_lock();
         * structure.
         */
        grep_read_lock();
-       size = fill_textconv(driver, df, &buf);
+       size = fill_textconv(the_repository, driver, df, &buf);
        grep_read_unlock();
        free_filespec(df);
 
        grep_read_unlock();
        free_filespec(df);