Skip to content
Snippets Groups Projects
Commit dc0f6f9e authored by Junio C Hamano's avatar Junio C Hamano
Browse files

Merge branch 'nd/no-the-index'

The more library-ish parts of the codebase learned to work on the
in-core index-state instance that is passed in by their callers,
instead of always working on the singleton "the_index" instance.

* nd/no-the-index: (24 commits)
  blame.c: remove implicit dependency on the_index
  apply.c: remove implicit dependency on the_index
  apply.c: make init_apply_state() take a struct repository
  apply.c: pass struct apply_state to more functions
  resolve-undo.c: use the right index instead of the_index
  archive-*.c: use the right repository
  archive.c: avoid access to the_index
  grep: use the right index instead of the_index
  attr: remove index from git_attr_set_direction()
  entry.c: use the right index instead of the_index
  submodule.c: use the right index instead of the_index
  pathspec.c: use the right index instead of the_index
  unpack-trees: avoid the_index in verify_absent()
  unpack-trees: convert clear_ce_flags* to avoid the_index
  unpack-trees: don't shadow global var the_index
  unpack-trees: add a note about path invalidation
  unpack-trees: remove 'extern' on function declaration
  ls-files: correct index argument to get_convert_attr_ascii()
  preload-index.c: use the right index instead of the_index
  dir.c: remove an implicit dependency on the_index in pathspec code
  ...
parents ace1f99c ecbbc0a5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -76,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
}
 
int init_apply_state(struct apply_state *state,
struct repository *repo,
const char *prefix)
{
memset(state, 0, sizeof(*state));
state->prefix = prefix;
state->repo = repo;
state->apply = 1;
state->line_termination = '\n';
state->p_value = 1;
Loading
Loading
@@ -3374,14 +3376,17 @@ static struct patch *previous_patch(struct apply_state *state,
return previous;
}
 
static int verify_index_match(const struct cache_entry *ce, struct stat *st)
static int verify_index_match(struct apply_state *state,
const struct cache_entry *ce,
struct stat *st)
{
if (S_ISGITLINK(ce->ce_mode)) {
if (!S_ISDIR(st->st_mode))
return -1;
return 0;
}
return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
return ie_match_stat(state->repo->index, ce, st,
CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
}
 
#define SUBMODULE_PATCH_WITHOUT_INDEX 1
Loading
Loading
@@ -3514,17 +3519,17 @@ static int load_current(struct apply_state *state,
if (!patch->is_new)
BUG("patch to %s is not a creation", patch->old_name);
 
pos = cache_name_pos(name, strlen(name));
pos = index_name_pos(state->repo->index, name, strlen(name));
if (pos < 0)
return error(_("%s: does not exist in index"), name);
ce = active_cache[pos];
ce = state->repo->index->cache[pos];
if (lstat(name, &st)) {
if (errno != ENOENT)
return error_errno("%s", name);
if (checkout_target(&the_index, ce, &st))
if (checkout_target(state->repo->index, ce, &st))
return -1;
}
if (verify_index_match(ce, &st))
if (verify_index_match(state, ce, &st))
return error(_("%s: does not match index"), name);
 
status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
Loading
Loading
@@ -3683,18 +3688,19 @@ static int check_preimage(struct apply_state *state,
}
 
if (state->check_index && !previous) {
int pos = cache_name_pos(old_name, strlen(old_name));
int pos = index_name_pos(state->repo->index, old_name,
strlen(old_name));
if (pos < 0) {
if (patch->is_new < 0)
goto is_new;
return error(_("%s: does not exist in index"), old_name);
}
*ce = active_cache[pos];
*ce = state->repo->index->cache[pos];
if (stat_ret < 0) {
if (checkout_target(&the_index, *ce, st))
if (checkout_target(state->repo->index, *ce, st))
return -1;
}
if (!state->cached && verify_index_match(*ce, st))
if (!state->cached && verify_index_match(state, *ce, st))
return error(_("%s: does not match index"), old_name);
if (state->cached)
st_mode = (*ce)->ce_mode;
Loading
Loading
@@ -3738,7 +3744,7 @@ static int check_to_create(struct apply_state *state,
struct stat nst;
 
if (state->check_index &&
cache_name_pos(new_name, strlen(new_name)) >= 0 &&
index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
!ok_if_exists)
return EXISTS_IN_INDEX;
if (state->cached)
Loading
Loading
@@ -3827,7 +3833,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
if (state->check_index) {
struct cache_entry *ce;
 
ce = cache_file_exists(name->buf, name->len, ignore_case);
ce = index_file_exists(state->repo->index, name->buf,
name->len, ignore_case);
if (ce && S_ISLNK(ce->ce_mode))
return 1;
} else {
Loading
Loading
@@ -4002,9 +4009,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
static int read_apply_cache(struct apply_state *state)
{
if (state->index_file)
return read_cache_from(state->index_file);
return read_index_from(state->repo->index, state->index_file,
get_git_dir());
else
return read_cache();
return read_index(state->repo->index);
}
 
/* This function tries to read the object name from the current index */
Loading
Loading
@@ -4015,10 +4023,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
 
if (read_apply_cache(state) < 0)
return -1;
pos = cache_name_pos(path, strlen(path));
pos = index_name_pos(state->repo->index, path, strlen(path));
if (pos < 0)
return -1;
oidcpy(oid, &active_cache[pos]->oid);
oidcpy(oid, &state->repo->index->cache[pos]->oid);
return 0;
}
 
Loading
Loading
@@ -4246,7 +4254,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
{
if (state->update_index && !state->ita_only) {
if (remove_file_from_cache(patch->old_name) < 0)
if (remove_file_from_index(state->repo->index, patch->old_name) < 0)
return error(_("unable to remove %s from index"), patch->old_name);
}
if (!state->cached) {
Loading
Loading
@@ -4267,7 +4275,7 @@ static int add_index_file(struct apply_state *state,
struct cache_entry *ce;
int namelen = strlen(path);
 
ce = make_empty_cache_entry(&the_index, namelen);
ce = make_empty_cache_entry(state->repo->index, namelen);
memcpy(ce->name, path, namelen);
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(0);
Loading
Loading
@@ -4299,7 +4307,7 @@ static int add_index_file(struct apply_state *state,
"for newly created file %s"), path);
}
}
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
discard_cache_entry(ce);
return error(_("unable to add cache entry for %s"), path);
}
Loading
Loading
@@ -4313,7 +4321,9 @@ static int add_index_file(struct apply_state *state,
* 0 if everything went well
* 1 if a recoverable error happened
*/
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
static int try_create_file(struct apply_state *state, const char *path,
unsigned int mode, const char *buf,
unsigned long size)
{
int fd, res;
struct strbuf nbuf = STRBUF_INIT;
Loading
Loading
@@ -4335,7 +4345,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
if (fd < 0)
return 1;
 
if (convert_to_working_tree(path, buf, size, &nbuf)) {
if (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {
size = nbuf.len;
buf = nbuf.buf;
}
Loading
Loading
@@ -4371,7 +4381,7 @@ static int create_one_file(struct apply_state *state,
if (state->cached)
return 0;
 
res = try_create_file(path, mode, buf, size);
res = try_create_file(state, path, mode, buf, size);
if (res < 0)
return -1;
if (!res)
Loading
Loading
@@ -4380,7 +4390,7 @@ static int create_one_file(struct apply_state *state,
if (errno == ENOENT) {
if (safe_create_leading_directories(path))
return 0;
res = try_create_file(path, mode, buf, size);
res = try_create_file(state, path, mode, buf, size);
if (res < 0)
return -1;
if (!res)
Loading
Loading
@@ -4402,7 +4412,7 @@ static int create_one_file(struct apply_state *state,
for (;;) {
char newpath[PATH_MAX];
mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
res = try_create_file(newpath, mode, buf, size);
res = try_create_file(state, newpath, mode, buf, size);
if (res < 0)
return -1;
if (!res) {
Loading
Loading
@@ -4432,17 +4442,17 @@ static int add_conflicted_stages_file(struct apply_state *state,
namelen = strlen(patch->new_name);
mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
 
remove_file_from_cache(patch->new_name);
remove_file_from_index(state->repo->index, patch->new_name);
for (stage = 1; stage < 4; stage++) {
if (is_null_oid(&patch->threeway_stage[stage - 1]))
continue;
ce = make_empty_cache_entry(&the_index, namelen);
ce = make_empty_cache_entry(state->repo->index, namelen);
memcpy(ce->name, patch->new_name, namelen);
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = namelen;
oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
discard_cache_entry(ce);
return error(_("unable to add cache entry for %s"),
patch->new_name);
Loading
Loading
@@ -4891,7 +4901,7 @@ int apply_all_patches(struct apply_state *state,
}
 
if (state->update_index) {
res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
res = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);
if (res) {
error(_("Unable to write new index file"));
res = -128;
Loading
Loading
#ifndef APPLY_H
#define APPLY_H
 
struct repository;
enum apply_ws_error_action {
nowarn_ws_error,
warn_on_ws_error,
Loading
Loading
@@ -62,6 +64,7 @@ struct apply_state {
int unsafe_paths;
 
/* Other non boolean parameters */
struct repository *repo;
const char *index_file;
enum apply_verbosity apply_verbosity;
const char *fake_ancestor;
Loading
Loading
@@ -116,6 +119,7 @@ int apply_parse_options(int argc, const char **argv,
int *force_apply, int *options,
const char * const *apply_usage);
int init_apply_state(struct apply_state *state,
struct repository *repo,
const char *prefix);
void clear_apply_state(struct apply_state *state);
int check_apply_state(struct apply_state *state, int force_apply);
Loading
Loading
Loading
Loading
@@ -277,7 +277,7 @@ static int write_tar_entry(struct archiver_args *args,
memcpy(header.name, path, pathlen);
 
if (S_ISREG(mode) && !args->convert &&
oid_object_info(the_repository, oid, &size) == OBJ_BLOB &&
oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
size > big_file_threshold)
buffer = NULL;
else if (S_ISLNK(mode) || S_ISREG(mode)) {
Loading
Loading
Loading
Loading
@@ -326,7 +326,7 @@ static int write_zip_entry(struct archiver_args *args,
compressed_size = 0;
buffer = NULL;
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
enum object_type type = oid_object_info(the_repository, oid,
enum object_type type = oid_object_info(args->repo, oid,
&size);
 
method = 0;
Loading
Loading
Loading
Loading
@@ -79,7 +79,7 @@ void *object_file_to_archive(const struct archiver_args *args,
size_t size = 0;
 
strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
convert_to_working_tree(path, buf.buf, buf.len, &buf);
convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf);
if (commit)
format_subst(commit, buf.buf, buf.len, &buf);
buffer = strbuf_detach(&buf, &size);
Loading
Loading
@@ -104,12 +104,13 @@ struct archiver_context {
struct directory *bottom;
};
 
static const struct attr_check *get_archive_attrs(const char *path)
static const struct attr_check *get_archive_attrs(struct index_state *istate,
const char *path)
{
static struct attr_check *check;
if (!check)
check = attr_check_initl("export-ignore", "export-subst", NULL);
return git_check_attr(path, check) ? NULL : check;
return git_check_attr(istate, path, check) ? NULL : check;
}
 
static int check_attr_export_ignore(const struct attr_check *check)
Loading
Loading
@@ -145,7 +146,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 
if (!S_ISDIR(mode)) {
const struct attr_check *check;
check = get_archive_attrs(path_without_prefix);
check = get_archive_attrs(args->repo->index, path_without_prefix);
if (check_attr_export_ignore(check))
return 0;
args->convert = check_attr_export_subst(check);
Loading
Loading
@@ -220,7 +221,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
/* Borrow base, but restore its original value when done. */
strbuf_addstr(base, filename);
strbuf_addch(base, '/');
check = get_archive_attrs(base->buf);
check = get_archive_attrs(c->args->repo->index, base->buf);
strbuf_setlen(base, baselen);
 
if (check_attr_export_ignore(check))
Loading
Loading
@@ -268,13 +269,13 @@ int write_archive_entries(struct archiver_args *args,
memset(&opts, 0, sizeof(opts));
opts.index_only = 1;
opts.head_idx = -1;
opts.src_index = &the_index;
opts.dst_index = &the_index;
opts.src_index = args->repo->index;
opts.dst_index = args->repo->index;
opts.fn = oneway_merge;
init_tree_desc(&t, args->tree->buffer, args->tree->size);
if (unpack_trees(1, &t, &opts))
return -1;
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
git_attr_set_direction(GIT_ATTR_INDEX);
}
 
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
Loading
Loading
@@ -304,33 +305,43 @@ static const struct archiver *lookup_archiver(const char *name)
return NULL;
}
 
struct path_exists_context {
struct pathspec pathspec;
struct archiver_args *args;
};
static int reject_entry(const struct object_id *oid, struct strbuf *base,
const char *filename, unsigned mode,
int stage, void *context)
{
int ret = -1;
struct path_exists_context *ctx = context;
if (S_ISDIR(mode)) {
struct strbuf sb = STRBUF_INIT;
strbuf_addbuf(&sb, base);
strbuf_addstr(&sb, filename);
if (!match_pathspec(context, sb.buf, sb.len, 0, NULL, 1))
if (!match_pathspec(ctx->args->repo->index,
&ctx->pathspec,
sb.buf, sb.len, 0, NULL, 1))
ret = READ_TREE_RECURSIVE;
strbuf_release(&sb);
}
return ret;
}
 
static int path_exists(struct tree *tree, const char *path)
static int path_exists(struct archiver_args *args, const char *path)
{
const char *paths[] = { path, NULL };
struct pathspec pathspec;
struct path_exists_context ctx;
int ret;
 
parse_pathspec(&pathspec, 0, 0, "", paths);
pathspec.recursive = 1;
ret = read_tree_recursive(tree, "", 0, 0, &pathspec,
reject_entry, &pathspec);
clear_pathspec(&pathspec);
ctx.args = args;
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
ctx.pathspec.recursive = 1;
ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
reject_entry, &ctx);
clear_pathspec(&ctx.pathspec);
return ret != 0;
}
 
Loading
Loading
@@ -348,7 +359,7 @@ static void parse_pathspec_arg(const char **pathspec,
ar_args->pathspec.recursive = 1;
if (pathspec) {
while (*pathspec) {
if (**pathspec && !path_exists(ar_args->tree, *pathspec))
if (**pathspec && !path_exists(ar_args, *pathspec))
die(_("pathspec '%s' did not match any files"), *pathspec);
pathspec++;
}
Loading
Loading
@@ -510,6 +521,7 @@ static int parse_archive_args(int argc, const char **argv,
}
 
int write_archive(int argc, const char **argv, const char *prefix,
struct repository *repo,
const char *name_hint, int remote)
{
const struct archiver *ar = NULL;
Loading
Loading
@@ -521,6 +533,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
init_tar_archiver();
init_zip_archiver();
 
args.repo = repo;
argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
if (!startup_info->have_repository) {
/*
Loading
Loading
Loading
Loading
@@ -3,7 +3,10 @@
 
#include "pathspec.h"
 
struct repository;
struct archiver_args {
struct repository *repo;
const char *base;
size_t baselen;
struct tree *tree;
Loading
Loading
@@ -17,6 +20,16 @@ struct archiver_args {
int compression_level;
};
 
/* main api */
extern int write_archive(int argc, const char **argv, const char *prefix,
struct repository *repo,
const char *name_hint, int remote);
const char *archive_format_from_filename(const char *filename);
/* archive backend stuff */
#define ARCHIVER_WANT_COMPRESSION_LEVELS 1
#define ARCHIVER_REMOTE 2
struct archiver {
Loading
Loading
@@ -36,9 +49,6 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
unsigned int mode);
 
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
const char *archive_format_from_filename(const char *filename);
extern void *object_file_to_archive(const struct archiver_args *args,
const char *path, const struct object_id *oid,
unsigned int mode, enum object_type *type,
Loading
Loading
Loading
Loading
@@ -708,10 +708,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
* 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)
void git_attr_set_direction(enum git_attr_direction new_direction)
{
if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
BUG("non-INDEX attr direction in a bare repo");
Loading
Loading
@@ -720,7 +718,6 @@ void git_attr_set_direction(enum git_attr_direction new_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)
Loading
Loading
@@ -743,13 +740,18 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
return res;
}
 
static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
static struct attr_stack *read_attr_from_index(const struct index_state *istate,
const char *path,
int macro_ok)
{
struct attr_stack *res;
char *buf, *sp;
int lineno = 0;
 
buf = read_blob_data_from_index(use_index ? use_index : &the_index, path, NULL);
if (!istate)
return NULL;
buf = read_blob_data_from_index(istate, path, NULL);
if (!buf)
return NULL;
 
Loading
Loading
@@ -768,15 +770,16 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
return res;
}
 
static struct attr_stack *read_attr(const char *path, int macro_ok)
static struct attr_stack *read_attr(const struct index_state *istate,
const char *path, int macro_ok)
{
struct attr_stack *res = NULL;
 
if (direction == GIT_ATTR_INDEX) {
res = read_attr_from_index(path, macro_ok);
res = read_attr_from_index(istate, path, macro_ok);
} else if (!is_bare_repository()) {
if (direction == GIT_ATTR_CHECKOUT) {
res = read_attr_from_index(path, macro_ok);
res = read_attr_from_index(istate, path, macro_ok);
if (!res)
res = read_attr_from_file(path, macro_ok);
} else if (direction == GIT_ATTR_CHECKIN) {
Loading
Loading
@@ -788,7 +791,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
* We allow operation in a sparsely checked out
* work tree, so read from it.
*/
res = read_attr_from_index(path, macro_ok);
res = read_attr_from_index(istate, path, macro_ok);
}
}
 
Loading
Loading
@@ -859,7 +862,8 @@ static void push_stack(struct attr_stack **attr_stack_p,
}
}
 
static void bootstrap_attr_stack(struct attr_stack **stack)
static void bootstrap_attr_stack(const struct index_state *istate,
struct attr_stack **stack)
{
struct attr_stack *e;
 
Loading
Loading
@@ -883,7 +887,7 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
}
 
/* root directory */
e = read_attr(GITATTRIBUTES_FILE, 1);
e = read_attr(istate, GITATTRIBUTES_FILE, 1);
push_stack(stack, e, xstrdup(""), 0);
 
/* info frame */
Loading
Loading
@@ -896,7 +900,8 @@ static void bootstrap_attr_stack(struct attr_stack **stack)
push_stack(stack, e, NULL, 0);
}
 
static void prepare_attr_stack(const char *path, int dirlen,
static void prepare_attr_stack(const struct index_state *istate,
const char *path, int dirlen,
struct attr_stack **stack)
{
struct attr_stack *info;
Loading
Loading
@@ -917,7 +922,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
* .gitattributes in deeper directories to shallower ones,
* and finally use the built-in set as the default.
*/
bootstrap_attr_stack(stack);
bootstrap_attr_stack(istate, stack);
 
/*
* Pop the "info" one that is always at the top of the stack.
Loading
Loading
@@ -973,7 +978,7 @@ static void prepare_attr_stack(const char *path, int dirlen,
strbuf_add(&pathbuf, path + pathbuf.len, (len - pathbuf.len));
strbuf_addf(&pathbuf, "/%s", GITATTRIBUTES_FILE);
 
next = read_attr(pathbuf.buf, 0);
next = read_attr(istate, pathbuf.buf, 0);
 
/* reset the pathbuf to not include "/.gitattributes" */
strbuf_setlen(&pathbuf, len);
Loading
Loading
@@ -1095,7 +1100,9 @@ static void determine_macros(struct all_attrs_item *all_attrs,
* If check->check_nr is non-zero, only attributes in check[] are collected.
* Otherwise all attributes are collected.
*/
static void collect_some_attrs(const char *path, struct attr_check *check)
static void collect_some_attrs(const struct index_state *istate,
const char *path,
struct attr_check *check)
{
int i, pathlen, rem, dirlen;
const char *cp, *last_slash = NULL;
Loading
Loading
@@ -1114,7 +1121,7 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
dirlen = 0;
}
 
prepare_attr_stack(path, dirlen, &check->stack);
prepare_attr_stack(istate, path, dirlen, &check->stack);
all_attrs_init(&g_attr_hashmap, check);
determine_macros(check->all_attrs, check->stack);
 
Loading
Loading
@@ -1136,11 +1143,13 @@ static void collect_some_attrs(const char *path, struct attr_check *check)
fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
}
 
int git_check_attr(const char *path, struct attr_check *check)
int git_check_attr(const struct index_state *istate,
const char *path,
struct attr_check *check)
{
int i;
 
collect_some_attrs(path, check);
collect_some_attrs(istate, path, check);
 
for (i = 0; i < check->nr; i++) {
size_t n = check->items[i].attr->attr_nr;
Loading
Loading
@@ -1153,12 +1162,13 @@ int git_check_attr(const char *path, struct attr_check *check)
return 0;
}
 
void git_all_attrs(const char *path, struct attr_check *check)
void git_all_attrs(const struct index_state *istate,
const char *path, struct attr_check *check)
{
int i;
 
attr_check_reset(check);
collect_some_attrs(path, check);
collect_some_attrs(istate, path, check);
 
for (i = 0; i < check->all_attrs_nr; i++) {
const char *name = check->all_attrs[i].attr->name;
Loading
Loading
#ifndef ATTR_H
#define ATTR_H
 
struct index_state;
/* An attribute is a pointer to this opaque structure */
struct git_attr;
 
Loading
Loading
@@ -60,21 +62,22 @@ void attr_check_free(struct attr_check *check);
*/
const char *git_attr_name(const struct git_attr *);
 
int git_check_attr(const char *path, struct attr_check *check);
int git_check_attr(const struct index_state *istate,
const char *path, struct attr_check *check);
 
/*
* Retrieve all attributes that apply to the specified path.
* check holds the attributes and their values.
*/
void git_all_attrs(const char *path, struct attr_check *check);
void git_all_attrs(const struct index_state *istate,
const char *path, struct attr_check *check);
 
enum git_attr_direction {
GIT_ATTR_CHECKIN,
GIT_ATTR_CHECKOUT,
GIT_ATTR_INDEX
};
void git_attr_set_direction(enum git_attr_direction new_direction,
struct index_state *istate);
void git_attr_set_direction(enum git_attr_direction new_direction);
 
void attr_start(void);
 
Loading
Loading
Loading
Loading
@@ -90,7 +90,8 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
 
 
 
static void verify_working_tree_path(struct commit *work_tree, const char *path)
static void verify_working_tree_path(struct repository *repo,
struct commit *work_tree, const char *path)
{
struct commit_list *parents;
int pos;
Loading
Loading
@@ -101,15 +102,15 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
unsigned mode;
 
if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
oid_object_info(repo, &blob_oid, NULL) == OBJ_BLOB)
return;
}
 
pos = cache_name_pos(path, strlen(path));
pos = index_name_pos(repo->index, path, strlen(path));
if (pos >= 0)
; /* path is in the index */
else if (-1 - pos < active_nr &&
!strcmp(active_cache[-1 - pos]->name, path))
else if (-1 - pos < repo->index->cache_nr &&
!strcmp(repo->index->cache[-1 - pos]->name, path))
; /* path is in the index, unmerged */
else
die("no such path '%s' in HEAD", path);
Loading
Loading
@@ -165,7 +166,8 @@ static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
* Prepare a dummy commit that represents the work tree (or staged) item.
* Note that annotating work tree item never works in the reverse.
*/
static struct commit *fake_working_tree_commit(struct diff_options *opt,
static struct commit *fake_working_tree_commit(struct repository *repo,
struct diff_options *opt,
const char *path,
const char *contents_from)
{
Loading
Loading
@@ -181,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
unsigned mode;
struct strbuf msg = STRBUF_INIT;
 
read_cache();
read_index(repo->index);
time(&now);
commit = alloc_commit_node(the_repository);
commit->object.parsed = 1;
Loading
Loading
@@ -193,7 +195,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 
parent_tail = append_parent(parent_tail, &head_oid);
append_merge_parents(parent_tail);
verify_working_tree_path(commit, path);
verify_working_tree_path(repo, commit, path);
 
origin = make_origin(commit, path);
 
Loading
Loading
@@ -251,7 +253,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
if (strbuf_read(&buf, 0, 0) < 0)
die_errno("failed to read from stdin");
}
convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
convert_to_git(repo->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
Loading
Loading
@@ -262,27 +264,28 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
* bits; we are not going to write this index out -- we just
* want to run "diff-index --cached".
*/
discard_cache();
read_cache();
discard_index(repo->index);
read_index(repo->index);
 
len = strlen(path);
if (!mode) {
int pos = cache_name_pos(path, len);
int pos = index_name_pos(repo->index, path, len);
if (0 <= pos)
mode = active_cache[pos]->ce_mode;
mode = repo->index->cache[pos]->ce_mode;
else
/* Let's not bother reading from HEAD tree */
mode = S_IFREG | 0644;
}
ce = make_empty_cache_entry(&the_index, len);
ce = make_empty_cache_entry(repo->index, len);
oidcpy(&ce->oid, &origin->blob_oid);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
add_index_entry(repo->index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
 
cache_tree_invalidate_path(&the_index, path);
cache_tree_invalidate_path(repo->index, path);
 
return commit;
}
Loading
Loading
@@ -519,13 +522,14 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
*
* This also fills origin->mode for corresponding tree path.
*/
static int fill_blob_sha1_and_mode(struct blame_origin *origin)
static int fill_blob_sha1_and_mode(struct repository *repo,
struct blame_origin *origin)
{
if (!is_null_oid(&origin->blob_oid))
return 0;
if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
if (oid_object_info(the_repository, &origin->blob_oid, NULL) != OBJ_BLOB)
if (oid_object_info(repo, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
Loading
Loading
@@ -1767,7 +1771,9 @@ void init_scoreboard(struct blame_scoreboard *sb)
sb->copy_score = BLAME_DEFAULT_COPY_SCORE;
}
 
void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blame_origin **orig)
void setup_scoreboard(struct blame_scoreboard *sb,
const char *path,
struct blame_origin **orig)
{
const char *final_commit_name = NULL;
struct blame_origin *o;
Loading
Loading
@@ -1779,6 +1785,9 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
if (sb->reverse && sb->contents_from)
die(_("--contents and --reverse do not blend well."));
 
if (!sb->repo)
BUG("repo is NULL");
if (!sb->reverse) {
sb->final = find_single_final(sb->revs, &final_commit_name);
sb->commits.compare = compare_commits_by_commit_date;
Loading
Loading
@@ -1800,7 +1809,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
* or "--contents".
*/
setup_work_tree();
sb->final = fake_working_tree_commit(&sb->revs->diffopt,
sb->final = fake_working_tree_commit(sb->repo,
&sb->revs->diffopt,
path, sb->contents_from);
add_pending_object(sb->revs, &(sb->final->object), ":");
}
Loading
Loading
@@ -1845,7 +1855,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
}
else {
o = get_origin(sb->final, path);
if (fill_blob_sha1_and_mode(o))
if (fill_blob_sha1_and_mode(sb->repo, o))
die(_("no such path %s in %s"), path, final_commit_name);
 
if (sb->revs->diffopt.flags.allow_textconv &&
Loading
Loading
Loading
Loading
@@ -102,6 +102,7 @@ struct blame_scoreboard {
struct commit *final;
/* Priority queue for commits with unassigned blame records */
struct prio_queue commits;
struct repository *repo;
struct rev_info *revs;
const char *path;
 
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip)
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i];
 
if (pathspec && !ce_path_match(ce, pathspec, NULL))
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue;
 
if (chmod_cache_entry(ce, flip) < 0)
Loading
Loading
@@ -135,7 +135,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
continue; /* do not touch unmerged paths */
if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
continue; /* do not touch non blobs */
if (pathspec && !ce_path_match(ce, pathspec, NULL))
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue;
retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
}
Loading
Loading
@@ -155,7 +155,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
if (dir_path_match(entry, pathspec, prefix, seen))
if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
*dst++ = entry;
}
dir->nr = dst - dir->entries;
Loading
Loading
Loading
Loading
@@ -1464,7 +1464,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
int force_apply = 0;
int options = 0;
 
if (init_apply_state(&apply_state, NULL))
if (init_apply_state(&apply_state, the_repository, NULL))
BUG("init_apply_state() failed");
 
argv_array_push(&apply_opts, "apply");
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
int ret;
struct apply_state state;
 
if (init_apply_state(&state, prefix))
if (init_apply_state(&state, the_repository, prefix))
exit(128);
 
argc = apply_parse_options(argc, argv,
Loading
Loading
Loading
Loading
@@ -105,5 +105,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 
return write_archive(argc, argv, prefix, output, 0);
return write_archive(argc, argv, prefix, the_repository, output, 0);
}
Loading
Loading
@@ -988,6 +988,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
sb.revs = &revs;
sb.contents_from = contents_from;
sb.reverse = reverse;
sb.repo = the_repository;
setup_scoreboard(&sb, path, &o);
lno = sb.num_lines;
 
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@ static int filter_object(const char *path, unsigned mode,
oid_to_hex(oid), path);
if ((type == OBJ_BLOB) && S_ISREG(mode)) {
struct strbuf strbuf = STRBUF_INIT;
if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
free(*buf);
*size = strbuf.len;
*buf = strbuf_detach(&strbuf, NULL);
Loading
Loading
Loading
Loading
@@ -63,9 +63,9 @@ static void check_attr(const char *prefix,
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
 
if (collect_all) {
git_all_attrs(full_path, check);
git_all_attrs(&the_index, full_path, check);
} else {
if (git_check_attr(full_path, check))
if (git_check_attr(&the_index, full_path, check))
die("git_check_attr died");
}
output_attr(check, file);
Loading
Loading
@@ -120,7 +120,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
}
 
if (cached_attrs)
git_attr_set_direction(GIT_ATTR_INDEX, NULL);
git_attr_set_direction(GIT_ATTR_INDEX);
 
doubledash = -1;
for (i = 0; doubledash < 0 && i < argc; i++) {
Loading
Loading
Loading
Loading
@@ -190,6 +190,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
 
argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
builtin_checkout_index_usage, 0);
state.istate = &the_index;
state.force = force;
state.quiet = quiet;
state.not_new = not_new;
Loading
Loading
Loading
Loading
@@ -318,7 +318,7 @@ static int checkout_paths(const struct checkout_opts *opts,
* match_pathspec() for _all_ entries when
* opts->source_tree != NULL.
*/
if (ce_path_match(ce, &opts->pathspec, ps_matched))
if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))
ce->ce_flags |= CE_MATCHED;
}
 
Loading
Loading
Loading
Loading
@@ -976,7 +976,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
continue;
 
if (pathspec.nr)
matches = dir_path_match(ent, &pathspec, 0, NULL);
matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
 
if (pathspec.nr && !matches)
continue;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment