THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

Merge branch 'sb/object-store-grafts'

The conversion to pass "the_repository" and then "a_repository"
throughout the object access API continues.

* sb/object-store-grafts:
  commit: allow lookup_commit_graft to handle arbitrary repositories
  commit: allow prepare_commit_graft to handle arbitrary repositories
  shallow: migrate shallow information into the object parser
  path.c: migrate global git_path_* to take a repository argument
  cache: convert get_graft_file to handle arbitrary repositories
  commit: convert read_graft_file to handle arbitrary repositories
  commit: convert register_commit_graft to handle arbitrary repositories
  commit: convert commit_graft_pos() to handle arbitrary repositories
  shallow: add repository argument to is_repository_shallow
  shallow: add repository argument to check_shallow_file_for_update
  shallow: add repository argument to register_shallow
  shallow: add repository argument to set_alternate_shallow_file
  commit: add repository argument to lookup_commit_graft
  commit: add repository argument to prepare_commit_graft
  commit: add repository argument to read_graft_file
  commit: add repository argument to register_commit_graft
  commit: add repository argument to commit_graft_pos
  object: move grafts to object parser
  object-store: move object access functions to object-store.h
tags/v2.19.0-rc0
Junio C Hamano 1 year ago
parent
commit
00624d608c
95 changed files with 463 additions and 328 deletions
  1. +1
    -0
      apply.c
  2. +1
    -0
      archive-tar.c
  3. +1
    -0
      archive-zip.c
  4. +1
    -0
      archive.c
  5. +6
    -3
      blame.c
  6. +7
    -7
      branch.c
  7. +3
    -1
      builtin/blame.c
  8. +1
    -0
      builtin/cat-file.c
  9. +1
    -0
      builtin/checkout.c
  10. +1
    -0
      builtin/clone.c
  11. +1
    -0
      builtin/commit-tree.c
  12. +19
    -19
      builtin/commit.c
  13. +1
    -0
      builtin/describe.c
  14. +1
    -0
      builtin/difftool.c
  15. +1
    -0
      builtin/fast-export.c
  16. +4
    -3
      builtin/fetch.c
  17. +1
    -0
      builtin/fmt-merge-msg.c
  18. +1
    -0
      builtin/hash-object.c
  19. +1
    -0
      builtin/log.c
  20. +1
    -0
      builtin/ls-tree.c
  21. +1
    -0
      builtin/merge-tree.c
  22. +19
    -18
      builtin/merge.c
  23. +1
    -0
      builtin/mktag.c
  24. +1
    -0
      builtin/mktree.c
  25. +1
    -0
      builtin/notes.c
  26. +3
    -3
      builtin/pack-objects.c
  27. +2
    -1
      builtin/prune.c
  28. +2
    -2
      builtin/pull.c
  29. +2
    -1
      builtin/receive-pack.c
  30. +1
    -0
      builtin/reflog.c
  31. +1
    -0
      builtin/remote.c
  32. +1
    -1
      builtin/replace.c
  33. +1
    -1
      builtin/reset.c
  34. +1
    -0
      builtin/rev-list.c
  35. +2
    -1
      builtin/rev-parse.c
  36. +1
    -0
      builtin/show-ref.c
  37. +1
    -0
      builtin/tag.c
  38. +1
    -0
      builtin/unpack-file.c
  39. +1
    -0
      builtin/unpack-objects.c
  40. +1
    -0
      builtin/verify-commit.c
  41. +1
    -0
      bulk-checkin.c
  42. +1
    -0
      bundle.c
  43. +1
    -0
      cache-tree.c
  44. +1
    -118
      cache.h
  45. +1
    -0
      combine-diff.c
  46. +41
    -36
      commit.c
  47. +5
    -5
      commit.h
  48. +1
    -0
      config.c
  49. +1
    -0
      convert.c
  50. +1
    -0
      diff.c
  51. +1
    -0
      diffcore-rename.c
  52. +1
    -0
      dir.c
  53. +1
    -0
      entry.c
  54. +4
    -4
      environment.c
  55. +8
    -7
      fetch-pack.c
  56. +2
    -1
      fsck.c
  57. +1
    -1
      git.c
  58. +1
    -0
      grep.c
  59. +1
    -0
      list-objects-filter.c
  60. +1
    -0
      list-objects.c
  61. +1
    -0
      log-tree.c
  62. +1
    -0
      mailmap.c
  63. +1
    -0
      match-trees.c
  64. +1
    -0
      merge-blobs.c
  65. +1
    -0
      merge-recursive.c
  66. +1
    -0
      notes-cache.c
  67. +1
    -0
      notes-merge.c
  68. +1
    -0
      notes.c
  69. +117
    -0
      object-store.h
  70. +4
    -0
      object.c
  71. +10
    -0
      object.h
  72. +1
    -0
      pack-bitmap-write.c
  73. +5
    -0
      packfile.h
  74. +9
    -9
      path.c
  75. +31
    -9
      path.h
  76. +1
    -0
      read-cache.c
  77. +1
    -0
      ref-filter.c
  78. +1
    -0
      refs.c
  79. +1
    -0
      remote-testsvn.c
  80. +1
    -0
      remote.c
  81. +5
    -0
      repository.h
  82. +5
    -3
      rerere.c
  83. +1
    -0
      revision.c
  84. +4
    -3
      send-pack.c
  85. +27
    -25
      sequencer.c
  86. +38
    -36
      shallow.c
  87. +1
    -0
      submodule-config.c
  88. +1
    -0
      tag.c
  89. +1
    -0
      tree-walk.c
  90. +1
    -0
      tree.c
  91. +1
    -0
      unpack-trees.c
  92. +9
    -6
      upload-pack.c
  93. +1
    -0
      walker.c
  94. +4
    -4
      wt-status.c
  95. +1
    -0
      xdiff-interface.c

+ 1
- 0
apply.c View File

@@ -9,6 +9,7 @@

#include "cache.h"
#include "config.h"
#include "object-store.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"

+ 1
- 0
archive-tar.c View File

@@ -5,6 +5,7 @@
#include "config.h"
#include "tar.h"
#include "archive.h"
#include "object-store.h"
#include "streaming.h"
#include "run-command.h"


+ 1
- 0
archive-zip.c View File

@@ -6,6 +6,7 @@
#include "archive.h"
#include "streaming.h"
#include "utf8.h"
#include "object-store.h"
#include "userdiff.h"
#include "xdiff-interface.h"


+ 1
- 0
archive.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
#include "commit.h"
#include "tree-walk.h"
#include "attr.h"

+ 6
- 3
blame.c View File

@@ -1,5 +1,6 @@
#include "cache.h"
#include "refs.h"
#include "object-store.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "diff.h"
@@ -129,17 +130,19 @@ static void append_merge_parents(struct commit_list **tail)
int merge_head;
struct strbuf line = STRBUF_INIT;

merge_head = open(git_path_merge_head(), O_RDONLY);
merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
if (merge_head < 0) {
if (errno == ENOENT)
return;
die("cannot open '%s' for reading", git_path_merge_head());
die("cannot open '%s' for reading",
git_path_merge_head(the_repository));
}

while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
struct object_id oid;
if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
die("unknown line in '%s': %s",
git_path_merge_head(the_repository), line.buf);
tail = append_parent(tail, &oid);
}
close(merge_head);

+ 7
- 7
branch.c View File

@@ -340,13 +340,13 @@ void create_branch(const char *name, const char *start_name,

void remove_branch_state(void)
{
unlink(git_path_cherry_pick_head());
unlink(git_path_revert_head());
unlink(git_path_merge_head());
unlink(git_path_merge_rr());
unlink(git_path_merge_msg());
unlink(git_path_merge_mode());
unlink(git_path_squash_msg());
unlink(git_path_cherry_pick_head(the_repository));
unlink(git_path_revert_head(the_repository));
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_rr(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
unlink(git_path_squash_msg(the_repository));
}

void die_if_checked_out(const char *branch, int ignore_current_worktree)

+ 3
- 1
builtin/blame.c View File

@@ -9,6 +9,7 @@
#include "config.h"
#include "color.h"
#include "builtin.h"
#include "repository.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
@@ -23,6 +24,7 @@
#include "line-log.h"
#include "dir.h"
#include "progress.h"
#include "object-store.h"
#include "blame.h"
#include "string-list.h"

@@ -576,7 +578,7 @@ static int read_ancestry(const char *graft_file)
/* The format is just "Commit Parent1 Parent2 ...\n" */
struct commit_graft *graft = read_graft_line(&buf);
if (graft)
register_commit_graft(graft, 0);
register_commit_graft(the_repository, graft, 0);
}
fclose(fp);
strbuf_release(&buf);

+ 1
- 0
builtin/cat-file.c View File

@@ -13,6 +13,7 @@
#include "tree-walk.h"
#include "sha1-array.h"
#include "packfile.h"
#include "object-store.h"

struct batch_options {
int enabled;

+ 1
- 0
builtin/checkout.c View File

@@ -4,6 +4,7 @@
#include "lockfile.h"
#include "parse-options.h"
#include "refs.h"
#include "object-store.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"

+ 1
- 0
builtin/clone.c View File

@@ -15,6 +15,7 @@
#include "fetch-pack.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"

+ 1
- 0
builtin/commit-tree.c View File

@@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "object-store.h"
#include "commit.h"
#include "tree.h"
#include "builtin.h"

+ 19
- 19
builtin/commit.c View File

@@ -168,9 +168,9 @@ static int opt_parse_rename_score(const struct option *opt, const char *arg, int

static void determine_whence(struct wt_status *s)
{
if (file_exists(git_path_merge_head()))
if (file_exists(git_path_merge_head(the_repository)))
whence = FROM_MERGE;
else if (file_exists(git_path_cherry_pick_head())) {
else if (file_exists(git_path_cherry_pick_head(the_repository))) {
whence = FROM_CHERRY_PICK;
if (file_exists(git_path_seq_dir()))
sequencer_in_use = 1;
@@ -718,21 +718,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (have_option_m)
strbuf_addbuf(&sb, &message);
hook_arg1 = "message";
} else if (!stat(git_path_merge_msg(), &statbuf)) {
} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
/*
* prepend SQUASH_MSG here if it exists and a
* "merge --squash" was originally performed
*/
if (!stat(git_path_squash_msg(), &statbuf)) {
if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
die_errno(_("could not read SQUASH_MSG"));
hook_arg1 = "squash";
} else
hook_arg1 = "merge";
if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
if (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0)
die_errno(_("could not read MERGE_MSG"));
} else if (!stat(git_path_squash_msg(), &statbuf)) {
if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
} else if (!stat(git_path_squash_msg(the_repository), &statbuf)) {
if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0)
die_errno(_("could not read SQUASH_MSG"));
hook_arg1 = "squash";
} else if (template_file) {
@@ -813,8 +813,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
" %s\n"
"and try again.\n"),
whence == FROM_MERGE ?
git_path_merge_head() :
git_path_cherry_pick_head());
git_path_merge_head(the_repository) :
git_path_cherry_pick_head(the_repository));
}

fprintf(s->fp, "\n");
@@ -1564,7 +1564,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (!reflog_msg)
reflog_msg = "commit (merge)";
pptr = commit_list_append(current_head, pptr);
fp = xfopen(git_path_merge_head(), "r");
fp = xfopen(git_path_merge_head(the_repository), "r");
while (strbuf_getline_lf(&m, fp) != EOF) {
struct commit *parent;

@@ -1575,8 +1575,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
}
fclose(fp);
strbuf_release(&m);
if (!stat(git_path_merge_mode(), &statbuf)) {
if (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)
if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
die_errno(_("could not read MERGE_MODE"));
if (!strcmp(sb.buf, "no-ff"))
allow_fast_forward = 0;
@@ -1639,12 +1639,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
die("%s", err.buf);
}

unlink(git_path_cherry_pick_head());
unlink(git_path_revert_head());
unlink(git_path_merge_head());
unlink(git_path_merge_msg());
unlink(git_path_merge_mode());
unlink(git_path_squash_msg());
unlink(git_path_cherry_pick_head(the_repository));
unlink(git_path_revert_head(the_repository));
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
unlink(git_path_squash_msg(the_repository));

if (commit_index_files())
die (_("Repository has been updated, but unable to write\n"

+ 1
- 0
builtin/describe.c View File

@@ -13,6 +13,7 @@
#include "hashmap.h"
#include "argv-array.h"
#include "run-command.h"
#include "object-store.h"
#include "revision.h"
#include "list-objects.h"
#include "commit-slab.h"

+ 1
- 0
builtin/difftool.c View File

@@ -20,6 +20,7 @@
#include "argv-array.h"
#include "strbuf.h"
#include "lockfile.h"
#include "object-store.h"
#include "dir.h"

static char *diff_gui_tool;

+ 1
- 0
builtin/fast-export.c View File

@@ -8,6 +8,7 @@
#include "config.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
#include "commit.h"
#include "object.h"
#include "tag.h"

+ 4
- 3
builtin/fetch.c View File

@@ -6,6 +6,7 @@
#include "repository.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
#include "commit.h"
#include "builtin.h"
#include "string-list.h"
@@ -777,7 +778,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
const char *what, *kind;
struct ref *rm;
char *url;
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head(the_repository);
int want_status;
int summary_width = transport_summary_width(ref_map);

@@ -1029,7 +1030,7 @@ static void check_not_current_branch(struct ref *ref_map)

static int truncate_fetch_head(void)
{
const char *filename = git_path_fetch_head();
const char *filename = git_path_fetch_head(the_repository);
FILE *fp = fopen_for_writing(filename);

if (!fp)
@@ -1449,7 +1450,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
if (unshallow) {
if (depth)
die(_("--depth and --unshallow cannot be used together"));
else if (!is_repository_shallow())
else if (!is_repository_shallow(the_repository))
die(_("--unshallow on a complete repository does not make sense"));
else
depth = xstrfmt("%d", INFINITE_DEPTH);

+ 1
- 0
builtin/fmt-merge-msg.c View File

@@ -2,6 +2,7 @@
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"

+ 1
- 0
builtin/hash-object.c View File

@@ -6,6 +6,7 @@
*/
#include "builtin.h"
#include "config.h"
#include "object-store.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"

+ 1
- 0
builtin/log.c View File

@@ -7,6 +7,7 @@
#include "cache.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
#include "color.h"
#include "commit.h"
#include "diff.h"

+ 1
- 0
builtin/ls-tree.c View File

@@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "object-store.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"

+ 1
- 0
builtin/merge-tree.c View File

@@ -1,6 +1,7 @@
#include "builtin.h"
#include "tree-walk.h"
#include "xdiff-interface.h"
#include "object-store.h"
#include "blob.h"
#include "exec-cmd.h"
#include "merge-blobs.h"

+ 19
- 18
builtin/merge.c View File

@@ -247,9 +247,9 @@ static struct option builtin_merge_options[] = {
/* Cleans up metadata that is uninteresting after a succeeded merge. */
static void drop_save(void)
{
unlink(git_path_merge_head());
unlink(git_path_merge_msg());
unlink(git_path_merge_mode());
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
}

static int save_state(struct object_id *stash)
@@ -382,7 +382,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
oid_to_hex(&commit->object.oid));
pretty_print_commit(&ctx, commit, &out);
}
write_file_buf(git_path_squash_msg(), out.buf, out.len);
write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);
strbuf_release(&out);
}

@@ -741,7 +741,7 @@ static void add_strategies(const char *string, unsigned attr)

static void read_merge_msg(struct strbuf *msg)
{
const char *filename = git_path_merge_msg();
const char *filename = git_path_merge_msg(the_repository);
strbuf_reset(msg);
if (strbuf_read_file(msg, filename, 0) < 0)
die_errno(_("Could not read from '%s'"), filename);
@@ -778,18 +778,18 @@ static void prepare_to_commit(struct commit_list *remoteheads)
if (signoff)
append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
write_merge_heads(remoteheads);
write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len);
if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
git_path_merge_msg(), "merge", NULL))
git_path_merge_msg(the_repository), "merge", NULL))
abort_commit(remoteheads, NULL);
if (0 < option_edit) {
if (launch_editor(git_path_merge_msg(), NULL, NULL))
if (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))
abort_commit(remoteheads, NULL);
}

if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),
"commit-msg",
git_path_merge_msg(), NULL))
git_path_merge_msg(the_repository), NULL))
abort_commit(remoteheads, NULL);

read_merge_msg(&msg);
@@ -859,7 +859,7 @@ static int suggest_conflicts(void)
FILE *fp;
struct strbuf msgbuf = STRBUF_INIT;

filename = git_path_merge_msg();
filename = git_path_merge_msg(the_repository);
fp = xfopen(filename, "a");

append_conflicts_hint(&msgbuf);
@@ -942,12 +942,12 @@ static void write_merge_heads(struct commit_list *remoteheads)
}
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
}
write_file_buf(git_path_merge_head(), buf.buf, buf.len);
write_file_buf(git_path_merge_head(the_repository), buf.buf, buf.len);

strbuf_reset(&buf);
if (fast_forward == FF_NO)
strbuf_addstr(&buf, "no-ff");
write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
write_file_buf(git_path_merge_mode(the_repository), buf.buf, buf.len);
strbuf_release(&buf);
}

@@ -955,7 +955,8 @@ static void write_merge_state(struct commit_list *remoteheads)
{
write_merge_heads(remoteheads);
strbuf_addch(&merge_msg, '\n');
write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
write_file_buf(git_path_merge_msg(the_repository), merge_msg.buf,
merge_msg.len);
}

static int default_edit_option(void)
@@ -1038,7 +1039,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
if (!merge_names)
merge_names = &fetch_head_file;

filename = git_path_fetch_head();
filename = git_path_fetch_head(the_repository);
fd = open(filename, O_RDONLY);
if (fd < 0)
die_errno(_("could not open '%s' for reading"), filename);
@@ -1213,7 +1214,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
usage_msg_opt(_("--abort expects no arguments"),
builtin_merge_usage, builtin_merge_options);

if (!file_exists(git_path_merge_head()))
if (!file_exists(git_path_merge_head(the_repository)))
die(_("There is no merge to abort (MERGE_HEAD missing)."));

/* Invoke 'git reset --merge' */
@@ -1229,7 +1230,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
usage_msg_opt(_("--continue expects no arguments"),
builtin_merge_usage, builtin_merge_options);

if (!file_exists(git_path_merge_head()))
if (!file_exists(git_path_merge_head(the_repository)))
die(_("There is no merge in progress (MERGE_HEAD missing)."));

/* Invoke 'git commit' */
@@ -1240,7 +1241,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (read_cache_unmerged())
die_resolve_conflict("merge");

if (file_exists(git_path_merge_head())) {
if (file_exists(git_path_merge_head(the_repository))) {
/*
* There is no unmerged entry, don't advise 'git
* add/rm <file>', just 'git commit'.
@@ -1251,7 +1252,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
else
die(_("You have not concluded your merge (MERGE_HEAD exists)."));
}
if (file_exists(git_path_cherry_pick_head())) {
if (file_exists(git_path_cherry_pick_head(the_repository))) {
if (advice_resolve_conflict)
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
"Please, commit your changes before you merge."));

+ 1
- 0
builtin/mktag.c View File

@@ -1,6 +1,7 @@
#include "builtin.h"
#include "tag.h"
#include "replace-object.h"
#include "object-store.h"

/*
* A signature file has a very simple fixed format: four lines

+ 1
- 0
builtin/mktree.c View File

@@ -7,6 +7,7 @@
#include "quote.h"
#include "tree.h"
#include "parse-options.h"
#include "object-store.h"

static struct treeent {
unsigned mode;

+ 1
- 0
builtin/notes.c View File

@@ -11,6 +11,7 @@
#include "config.h"
#include "builtin.h"
#include "notes.h"
#include "object-store.h"
#include "blob.h"
#include "pretty.h"
#include "refs.h"

+ 3
- 3
builtin/pack-objects.c View File

@@ -2969,7 +2969,7 @@ static void get_object_list(int ac, const char **av)
setup_revisions(ac, av, &revs, NULL);

/* make sure shallows are read */
is_repository_shallow();
is_repository_shallow(the_repository);

while (fgets(line, sizeof(line), stdin) != NULL) {
int len = strlen(line);
@@ -2987,7 +2987,7 @@ static void get_object_list(int ac, const char **av)
struct object_id oid;
if (get_oid_hex(line + 10, &oid))
die("not an SHA-1 '%s'", line + 10);
register_shallow(&oid);
register_shallow(the_repository, &oid);
use_bitmap_index = 0;
continue;
}
@@ -3299,7 +3299,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
use_bitmap_index = use_bitmap_index_default;

/* "hard" reasons not to use bitmaps; these just won't work at all */
if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
use_bitmap_index = 0;

if (pack_to_stdout || !rev_list_all)

+ 2
- 1
builtin/prune.c View File

@@ -6,6 +6,7 @@
#include "reachable.h"
#include "parse-options.h"
#include "progress.h"
#include "object-store.h"

static const char * const prune_usage[] = {
N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"),
@@ -159,7 +160,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
remove_temporary_files(s);
free(s);

if (is_repository_shallow())
if (is_repository_shallow(the_repository))
prune_shallow(show_only);

return 0;

+ 2
- 2
builtin/pull.c View File

@@ -356,7 +356,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
*/
static void get_merge_heads(struct oid_array *merge_heads)
{
const char *filename = git_path_fetch_head();
const char *filename = git_path_fetch_head(the_repository);
FILE *fp;
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
@@ -864,7 +864,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (read_cache_unmerged())
die_resolve_conflict("pull");

if (file_exists(git_path_merge_head()))
if (file_exists(git_path_merge_head(the_repository)))
die_conclude_merge();

if (get_oid("HEAD", &orig_head))

+ 2
- 1
builtin/receive-pack.c View File

@@ -25,6 +25,7 @@
#include "tmp-objdir.h"
#include "oidset.h"
#include "packfile.h"
#include "object-store.h"
#include "protocol.h"

static const char * const receive_pack_usage[] = {
@@ -905,7 +906,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
* not lose these new roots..
*/
for (i = 0; i < extra.nr; i++)
register_shallow(&extra.oid[i]);
register_shallow(the_repository, &extra.oid[i]);

si->shallow_ref[cmd->index] = 0;
oid_array_clear(&extra);

+ 1
- 0
builtin/reflog.c View File

@@ -1,6 +1,7 @@
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
#include "object-store.h"
#include "commit.h"
#include "refs.h"
#include "dir.h"

+ 1
- 0
builtin/remote.c View File

@@ -8,6 +8,7 @@
#include "run-command.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
#include "argv-array.h"

static const char * const builtin_remote_usage[] = {

+ 1
- 1
builtin/replace.c View File

@@ -487,7 +487,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)

static int convert_graft_file(int force)
{
const char *graft_file = get_graft_file();
const char *graft_file = get_graft_file(the_repository);
FILE *fp = fopen_or_warn(graft_file, "r");
struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT;
struct argv_array args = ARGV_ARRAY_INIT;

+ 1
- 1
builtin/reset.c View File

@@ -39,7 +39,7 @@ static const char *reset_type_names[] = {

static inline int is_merge(void)
{
return !access(git_path_merge_head(), F_OK);
return !access(git_path_merge_head(the_repository), F_OK);
}

static int reset_index(const struct object_id *oid, int reset_type, int quiet)

+ 1
- 0
builtin/rev-list.c View File

@@ -6,6 +6,7 @@
#include "list-objects.h"
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "object-store.h"
#include "pack.h"
#include "pack-bitmap.h"
#include "builtin.h"

+ 2
- 1
builtin/rev-parse.c View File

@@ -883,7 +883,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--is-shallow-repository")) {
printf("%s\n", is_repository_shallow() ? "true"
printf("%s\n",
is_repository_shallow(the_repository) ? "true"
: "false");
continue;
}

+ 1
- 0
builtin/show-ref.c View File

@@ -1,6 +1,7 @@
#include "builtin.h"
#include "cache.h"
#include "refs.h"
#include "object-store.h"
#include "object.h"
#include "tag.h"
#include "string-list.h"

+ 1
- 0
builtin/tag.c View File

@@ -10,6 +10,7 @@
#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "object-store.h"
#include "tag.h"
#include "run-command.h"
#include "parse-options.h"

+ 1
- 0
builtin/unpack-file.c View File

@@ -1,5 +1,6 @@
#include "builtin.h"
#include "config.h"
#include "object-store.h"

static char *create_temp_file(struct object_id *oid)
{

+ 1
- 0
builtin/unpack-objects.c View File

@@ -1,6 +1,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "object-store.h"
#include "object.h"
#include "delta.h"
#include "pack.h"

+ 1
- 0
builtin/verify-commit.c View File

@@ -8,6 +8,7 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "object-store.h"
#include "commit.h"
#include "run-command.h"
#include <signal.h>

+ 1
- 0
bulk-checkin.c View File

@@ -8,6 +8,7 @@
#include "pack.h"
#include "strbuf.h"
#include "packfile.h"
#include "object-store.h"

static struct bulk_checkin_state {
unsigned plugged:1;

+ 1
- 0
bundle.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "lockfile.h"
#include "bundle.h"
#include "object-store.h"
#include "object.h"
#include "commit.h"
#include "diff.h"

+ 1
- 0
cache-tree.c View File

@@ -3,6 +3,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "cache-tree.h"
#include "object-store.h"

#ifndef DEBUG
#define DEBUG 0

+ 1
- 118
cache.h View File

@@ -484,7 +484,7 @@ extern const char *get_git_dir(void);
extern const char *get_git_common_dir(void);
extern char *get_object_directory(void);
extern char *get_index_file(void);
extern char *get_graft_file(void);
extern char *get_graft_file(struct repository *r);
extern void set_git_dir(const char *path);
extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
extern int get_common_dir(struct strbuf *sb, const char *gitdir);
@@ -1192,32 +1192,6 @@ extern char *xdg_config_home(const char *filename);
*/
extern char *xdg_cache_home(const char *filename);

extern void *read_object_file_extended(const struct object_id *oid,
enum object_type *type,
unsigned long *size, int lookup_replace);
static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
{
return read_object_file_extended(oid, type, size, 1);
}

/* Read and unpack an object file into memory, write memory to an object file */
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);

extern int hash_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);

extern int write_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);

extern int hash_object_file_literally(const void *buf, unsigned long len,
const char *type, struct object_id *oid,
unsigned flags);

extern int pretend_object_file(void *, unsigned long, enum object_type,
struct object_id *oid);

extern int force_object_loose(const struct object_id *oid, time_t mtime);

extern int git_open_cloexec(const char *name, int flags);
#define git_open(name) git_open_cloexec(name, O_RDONLY)
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
@@ -1227,43 +1201,6 @@ extern int check_object_signature(const struct object_id *oid, void *buf, unsign

extern int finalize_object_file(const char *tmpfile, const char *filename);

/*
* Open the loose object at path, check its hash, and return the contents,
* type, and size. If the object is a blob, then "contents" may return NULL,
* to allow streaming of large blobs.
*
* Returns 0 on success, negative on error (details may be written to stderr).
*/
int read_loose_object(const char *path,
const struct object_id *expected_oid,
enum object_type *type,
unsigned long *size,
void **contents);

/*
* Convenience for sha1_object_info_extended() with a NULL struct
* object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
* nonzero flags to also set other flags.
*/
extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
static inline int has_sha1_file(const unsigned char *sha1)
{
return has_sha1_file_with_flags(sha1, 0);
}

/* Same as the above, except for struct object_id. */
extern int has_object_file(const struct object_id *oid);
extern int has_object_file_with_flags(const struct object_id *oid, int flags);

/*
* Return true iff an alternate object database has a loose object
* with the specified name. This function does not respect replace
* references.
*/
extern int has_loose_object_nonlocal(const struct object_id *oid);

extern void assert_oid_type(const struct object_id *oid, enum object_type expect);

/* Helper to check and "touch" a file */
extern int check_and_freshen_file(const char *fn, int freshen);

@@ -1631,60 +1568,6 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);

struct object_info {
/* Request */
enum object_type *typep;
unsigned long *sizep;
off_t *disk_sizep;
unsigned char *delta_base_sha1;
struct strbuf *type_name;
void **contentp;

/* Response */
enum {
OI_CACHED,
OI_LOOSE,
OI_PACKED,
OI_DBCACHED
} whence;
union {
/*
* struct {
* ... Nothing to expose in this case
* } cached;
* struct {
* ... Nothing to expose in this case
* } loose;
*/
struct {
struct packed_git *pack;
off_t offset;
unsigned int is_delta;
} packed;
} u;
};

/*
* Initializer for a "struct object_info" that wants no items. You may
* also memset() the memory to all-zeroes.
*/
#define OBJECT_INFO_INIT {NULL}

/* Invoke lookup_replace_object() on the given hash */
#define OBJECT_INFO_LOOKUP_REPLACE 1
/* Allow reading from a loose object file of unknown/bogus type */
#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
/* Do not check cached storage */
#define OBJECT_INFO_SKIP_CACHED 4
/* Do not retry packed storage after checking packed and loose storage */
#define OBJECT_INFO_QUICK 8
/* Do not check loose object */
#define OBJECT_INFO_IGNORE_LOOSE 16

int oid_object_info_extended(struct repository *r,
const struct object_id *,
struct object_info *, unsigned flags);

/*
* Set this to 0 to prevent sha1_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.

+ 1
- 0
combine-diff.c View File

@@ -1,4 +1,5 @@
#include "cache.h"
#include "object-store.h"
#include "commit.h"
#include "blob.h"
#include "diff.h"

+ 41
- 36
commit.c View File

@@ -2,6 +2,8 @@
#include "tag.h"
#include "commit.h"
#include "commit-graph.h"
#include "repository.h"
#include "object-store.h"
#include "pkt-line.h"
#include "utf8.h"
#include "diff.h"
@@ -98,41 +100,44 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
return parse_timestamp(dateptr, NULL, 10);
}

static struct commit_graft **commit_graft;
static int commit_graft_alloc, commit_graft_nr;

static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
{
struct commit_graft **commit_graft_table = table;
return commit_graft_table[index]->oid.hash;
}

static int commit_graft_pos(const unsigned char *sha1)
static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
{
return sha1_pos(sha1, commit_graft, commit_graft_nr,
return sha1_pos(sha1, r->parsed_objects->grafts,
r->parsed_objects->grafts_nr,
commit_graft_sha1_access);
}

int register_commit_graft(struct commit_graft *graft, int ignore_dups)
int register_commit_graft(struct repository *r, struct commit_graft *graft,
int ignore_dups)
{
int pos = commit_graft_pos(graft->oid.hash);
int pos = commit_graft_pos(r, graft->oid.hash);

if (0 <= pos) {
if (ignore_dups)
free(graft);
else {
free(commit_graft[pos]);
commit_graft[pos] = graft;
free(r->parsed_objects->grafts[pos]);
r->parsed_objects->grafts[pos] = graft;
}
return 1;
}
pos = -pos - 1;
ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
commit_graft_nr++;
if (pos < commit_graft_nr)
MOVE_ARRAY(commit_graft + pos + 1, commit_graft + pos,
commit_graft_nr - pos - 1);
commit_graft[pos] = graft;
ALLOC_GROW(r->parsed_objects->grafts,
r->parsed_objects->grafts_nr + 1,
r->parsed_objects->grafts_alloc);
r->parsed_objects->grafts_nr++;
if (pos < r->parsed_objects->grafts_nr)
memmove(r->parsed_objects->grafts + pos + 1,
r->parsed_objects->grafts + pos,
(r->parsed_objects->grafts_nr - pos - 1) *
sizeof(*r->parsed_objects->grafts));
r->parsed_objects->grafts[pos] = graft;
return 0;
}

@@ -174,7 +179,7 @@ bad_graft_data:
return NULL;
}

static int read_graft_file(const char *graft_file)
static int read_graft_file(struct repository *r, const char *graft_file)
{
FILE *fp = fopen_or_warn(graft_file, "r");
struct strbuf buf = STRBUF_INIT;
@@ -194,7 +199,7 @@ static int read_graft_file(const char *graft_file)
struct commit_graft *graft = read_graft_line(&buf);
if (!graft)
continue;
if (register_commit_graft(graft, 1))
if (register_commit_graft(r, graft, 1))
error("duplicate graft data: %s", buf.buf);
}
fclose(fp);
@@ -202,50 +207,50 @@ static int read_graft_file(const char *graft_file)
return 0;
}

static void prepare_commit_graft(void)
static void prepare_commit_graft(struct repository *r)
{
static int commit_graft_prepared;
char *graft_file;

if (commit_graft_prepared)
if (r->parsed_objects->commit_graft_prepared)
return;
if (!startup_info->have_repository)
return;

graft_file = get_graft_file();
read_graft_file(graft_file);
graft_file = get_graft_file(r);
read_graft_file(r, graft_file);
/* make sure shallows are read */
is_repository_shallow();
commit_graft_prepared = 1;
is_repository_shallow(r);
r->parsed_objects->commit_graft_prepared = 1;
}

struct commit_graft *lookup_commit_graft(const struct object_id *oid)
struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid)
{
int pos;
prepare_commit_graft();
pos = commit_graft_pos(oid->hash);
prepare_commit_graft(r);
pos = commit_graft_pos(r, oid->hash);
if (pos < 0)
return NULL;
return commit_graft[pos];
return r->parsed_objects->grafts[pos];
}

int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
{
int i, ret;
for (i = ret = 0; i < commit_graft_nr && !ret; i++)
ret = fn(commit_graft[i], cb_data);
for (i = ret = 0; i < the_repository->parsed_objects->grafts_nr && !ret; i++)
ret = fn(the_repository->parsed_objects->grafts[i], cb_data);
return ret;
}

int unregister_shallow(const struct object_id *oid)
{
int pos = commit_graft_pos(oid->hash);
int pos = commit_graft_pos(the_repository, oid->hash);
if (pos < 0)
return -1;
if (pos + 1 < commit_graft_nr)
MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,
commit_graft_nr - pos - 1);
commit_graft_nr--;
if (pos + 1 < the_repository->parsed_objects->grafts_nr)
MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
the_repository->parsed_objects->grafts + pos + 1,
the_repository->parsed_objects->grafts_nr - pos - 1);
the_repository->parsed_objects->grafts_nr--;
return 0;
}

@@ -381,7 +386,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;

graft = lookup_commit_graft(&item->object.oid);
graft = lookup_commit_graft(the_repository, &item->object.oid);
while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
struct commit *new_parent;


+ 5
- 5
commit.h View File

@@ -194,8 +194,8 @@ struct commit_graft {
typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);

struct commit_graft *read_graft_line(struct strbuf *line);
int register_commit_graft(struct commit_graft *, int);
struct commit_graft *lookup_commit_graft(const struct object_id *oid);
int register_commit_graft(struct repository *r, struct commit_graft *, int);
struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);

extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);
@@ -209,15 +209,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,

struct oid_array;
struct ref;
extern int register_shallow(const struct object_id *oid);
extern int register_shallow(struct repository *r, const struct object_id *oid);
extern int unregister_shallow(const struct object_id *oid);
extern int for_each_commit_graft(each_commit_graft_fn, void *);
extern int is_repository_shallow(void);
extern int is_repository_shallow(struct repository *r);
extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
extern struct commit_list *get_shallow_commits_by_rev_list(
int ac, const char **av, int shallow_flag, int not_shallow_flag);
extern void set_alternate_shallow_file(const char *path, int override);
extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
const struct oid_array *extra);
extern void setup_alternate_shallow(struct lock_file *shallow_lock,

+ 1
- 0
config.c View File

@@ -14,6 +14,7 @@
#include "quote.h"
#include "hashmap.h"
#include "string-list.h"
#include "object-store.h"
#include "utf8.h"
#include "dir.h"
#include "color.h"

+ 1
- 0
convert.c View File

@@ -1,6 +1,7 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "object-store.h"
#include "attr.h"
#include "run-command.h"
#include "quote.h"

+ 1
- 0
diff.c View File

@@ -13,6 +13,7 @@
#include "attr.h"
#include "run-command.h"
#include "utf8.h"
#include "object-store.h"
#include "userdiff.h"
#include "submodule-config.h"
#include "submodule.h"

+ 1
- 0
diffcore-rename.c View File

@@ -4,6 +4,7 @@
#include "cache.h"
#include "diff.h"
#include "diffcore.h"
#include "object-store.h"
#include "hashmap.h"
#include "progress.h"


+ 1
- 0
dir.c View File

@@ -11,6 +11,7 @@
#include "cache.h"
#include "config.h"
#include "dir.h"
#include "object-store.h"
#include "attr.h"
#include "refs.h"
#include "wildmatch.h"

+ 1
- 0
entry.c View File

@@ -1,5 +1,6 @@
#include "cache.h"
#include "blob.h"
#include "object-store.h"
#include "dir.h"
#include "streaming.h"
#include "submodule.h"

+ 4
- 4
environment.c View File

@@ -192,7 +192,7 @@ void setup_git_env(const char *git_dir)
git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
if (shallow_file)
set_alternate_shallow_file(shallow_file, 0);
set_alternate_shallow_file(the_repository, shallow_file, 0);
}

int is_bare_repository(void)
@@ -319,11 +319,11 @@ char *get_index_file(void)
return the_repository->index_file;
}

char *get_graft_file(void)
char *get_graft_file(struct repository *r)
{
if (!the_repository->graft_file)
if (!r->graft_file)
BUG("git environment hasn't been setup");
return the_repository->graft_file;
return r->graft_file;
}

static void set_git_dir_1(const char *path)

+ 8
- 7
fetch-pack.c View File

@@ -19,6 +19,7 @@
#include "sha1-array.h"
#include "oidset.h"
#include "packfile.h"
#include "object-store.h"

static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -396,7 +397,7 @@ static int find_common(struct fetch_pack_args *args,
return 1;
}

if (is_repository_shallow())
if (is_repository_shallow(the_repository))
write_shallow_commits(&req_buf, 1, NULL);
if (args->depth > 0)
packet_buf_write(&req_buf, "deepen %d", args->depth);
@@ -427,7 +428,7 @@ static int find_common(struct fetch_pack_args *args,
if (skip_prefix(line, "shallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid shallow line: %s"), line);
register_shallow(&oid);
register_shallow(the_repository, &oid);
continue;
}
if (skip_prefix(line, "unshallow ", &arg)) {
@@ -985,7 +986,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
sort_ref_list(&ref, ref_compare_name);
QSORT(sought, nr_sought, cmp_ref_by_name);

if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
if ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports("shallow"))
die(_("Server does not support shallow clients"));
if (args->depth > 0 || args->deepen_since || args->deepen_not)
args->deepen = 1;
@@ -1083,7 +1084,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
static void add_shallow_requests(struct strbuf *req_buf,
const struct fetch_pack_args *args)
{
if (is_repository_shallow())
if (is_repository_shallow(the_repository))
write_shallow_commits(req_buf, 1, NULL);
if (args->depth > 0)
packet_buf_write(req_buf, "deepen %d", args->depth);
@@ -1195,7 +1196,7 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
/* Add shallow-info and deepen request */
if (server_supports_feature("fetch", "shallow", 0))
add_shallow_requests(&req_buf, args);
else if (is_repository_shallow() || args->deepen)
else if (is_repository_shallow(the_repository) || args->deepen)
die(_("Server does not support shallow requests"));

/* Add filter */
@@ -1308,7 +1309,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
if (skip_prefix(reader->line, "shallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid shallow line: %s"), reader->line);
register_shallow(&oid);
register_shallow(the_repository, &oid);
continue;
}
if (skip_prefix(reader->line, "unshallow ", &arg)) {
@@ -1479,7 +1480,7 @@ static void update_shallow(struct fetch_pack_args *args,

if (args->deepen && alternate_shallow_file) {
if (*alternate_shallow_file == '\0') { /* --unshallow */
unlink_or_warn(git_path_shallow());
unlink_or_warn(git_path_shallow(the_repository));
rollback_lock_file(&shallow_lock);
} else
commit_lock_file(&shallow_lock);

+ 2
- 1
fsck.c View File

@@ -1,4 +1,5 @@
#include "cache.h"
#include "object-store.h"
#include "object.h"
#include "blob.h"
#include "tree.h"
@@ -795,7 +796,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
buffer = p + 1;
parent_line_count++;
}
graft = lookup_commit_graft(&commit->object.oid);
graft = lookup_commit_graft(the_repository, &commit->object.oid);
parent_count = commit_list_count(commit->parents);
if (graft) {
if (graft->nr_parent == -1 && !parent_count)

+ 1
- 1
git.c View File

@@ -267,7 +267,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
} else if (!strcmp(cmd, "--shallow-file")) {
(*argv)++;
(*argc)--;
set_alternate_shallow_file((*argv)[0], 1);
set_alternate_shallow_file(the_repository, (*argv)[0], 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "-C")) {

+ 1
- 0
grep.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "config.h"
#include "grep.h"
#include "object-store.h"
#include "userdiff.h"
#include "xdiff-interface.h"
#include "diff.h"

+ 1
- 0
list-objects-filter.c View File

@@ -11,6 +11,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "oidset.h"
#include "object-store.h"

/* Remember to update object flag allocation in object.h */
/*

+ 1
- 0
list-objects.c View File

@@ -10,6 +10,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
#include "object-store.h"

static void process_blob(struct rev_info *revs,
struct blob *blob,

+ 1
- 0
log-tree.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "config.h"
#include "diff.h"
#include "object-store.h"
#include "commit.h"
#include "tag.h"
#include "graph.h"

+ 1
- 0
mailmap.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "string-list.h"
#include "mailmap.h"
#include "object-store.h"

#define DEBUG_MAILMAP 0
#if DEBUG_MAILMAP

+ 1
- 0
match-trees.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "tree.h"
#include "tree-walk.h"
#include "object-store.h"

static int score_missing(unsigned mode, const char *path)
{

+ 1
- 0
merge-blobs.c View File

@@ -4,6 +4,7 @@
#include "ll-merge.h"
#include "blob.h"
#include "merge-blobs.h"
#include "object-store.h"

static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{

+ 1
- 0
merge-recursive.c View File

@@ -8,6 +8,7 @@
#include "advice.h"
#include "lockfile.h"
#include "cache-tree.h"
#include "object-store.h"
#include "commit.h"
#include "blob.h"
#include "builtin.h"

+ 1
- 0
notes-cache.c View File

@@ -1,5 +1,6 @@
#include "cache.h"
#include "notes-cache.h"
#include "object-store.h"
#include "commit.h"
#include "refs.h"


+ 1
- 0
notes-merge.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "commit.h"
#include "refs.h"
#include "object-store.h"
#include "diff.h"
#include "diffcore.h"
#include "xdiff-interface.h"

+ 1
- 0
notes.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "config.h"
#include "notes.h"
#include "object-store.h"
#include "blob.h"
#include "tree.h"
#include "utf8.h"

+ 117
- 0
object-store.h View File

@@ -139,4 +139,121 @@ void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned cha

void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);

extern void *read_object_file_extended(const struct object_id *oid,
enum object_type *type,
unsigned long *size, int lookup_replace);
static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
{
return read_object_file_extended(oid, type, size, 1);
}

/* Read and unpack an object file into memory, write memory to an object file */
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);

extern int hash_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);

extern int write_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);

extern int hash_object_file_literally(const void *buf, unsigned long len,
const char *type, struct object_id *oid,
unsigned flags);

extern int pretend_object_file(void *, unsigned long, enum object_type,
struct object_id *oid);

extern int force_object_loose(const struct object_id *oid, time_t mtime);

/*
* Open the loose object at path, check its hash, and return the contents,
* type, and size. If the object is a blob, then "contents" may return NULL,
* to allow streaming of large blobs.
*
* Returns 0 on success, negative on error (details may be written to stderr).
*/
int read_loose_object(const char *path,
const struct object_id *expected_oid,
enum object_type *type,
unsigned long *size,
void **contents);

/*
* Convenience for sha1_object_info_extended() with a NULL struct
* object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
* nonzero flags to also set other flags.
*/
extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
static inline int has_sha1_file(const unsigned char *sha1)
{
return has_sha1_file_with_flags(sha1, 0);
}

/* Same as the above, except for struct object_id. */
extern int has_object_file(const struct object_id *oid);
extern int has_object_file_with_flags(const struct object_id *oid, int flags);

/*
* Return true iff an alternate object database has a loose object
* with the specified name. This function does not respect replace
* references.
*/
extern int has_loose_object_nonlocal(const struct object_id *);

extern void assert_oid_type(const struct object_id *oid, enum object_type expect);

struct object_info {
/* Request */
enum object_type *typep;
unsigned long *sizep;
off_t *disk_sizep;
unsigned char *delta_base_sha1;
struct strbuf *type_name;
void **contentp;

/* Response */
enum {
OI_CACHED,
OI_LOOSE,
OI_PACKED,
OI_DBCACHED
} whence;
union {
/*
* struct {
* ... Nothing to expose in this case
* } cached;
* struct {
* ... Nothing to expose in this case
* } loose;
*/
struct {
struct packed_git *pack;
off_t offset;
unsigned int is_delta;
} packed;
} u;
};

/*
* Initializer for a "struct object_info" that wants no items. You may
* also memset() the memory to all-zeroes.
*/
#define OBJECT_INFO_INIT {NULL}

/* Invoke lookup_replace_object() on the given hash */
#define OBJECT_INFO_LOOKUP_REPLACE 1
/* Allow reading from a loose object file of unknown/bogus type */
#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
/* Do not check cached storage */
#define OBJECT_INFO_SKIP_CACHED 4
/* Do not retry packed storage after checking packed and loose storage */
#define OBJECT_INFO_QUICK 8
/* Do not check loose object */
#define OBJECT_INFO_IGNORE_LOOSE 16

int oid_object_info_extended(struct repository *r,
const struct object_id *,
struct object_info *, unsigned flags);

#endif /* OBJECT_STORE_H */

+ 4
- 0
object.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "object.h"
#include "replace-object.h"
#include "object-store.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
@@ -463,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void)
o->tag_state = allocate_alloc_state();
o->object_state = allocate_alloc_state();

o->is_shallow = -1;
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));

return o;
}


+ 10
- 0
object.h View File

@@ -12,6 +12,16 @@ struct parsed_object_pool {
struct alloc_state *tag_state;
struct alloc_state *object_state;
unsigned commit_count;

/* parent substitutions from .git/info/grafts and .git/shallow */
struct commit_graft **grafts;
int grafts_alloc, grafts_nr;

int is_shallow;
struct stat_validity *shallow_stat;
char *alternate_shallow_file;

int commit_graft_prepared;
};

struct parsed_object_pool *parsed_object_pool_new(void);

+ 1
- 0
pack-bitmap-write.c View File

@@ -1,4 +1,5 @@
#include "cache.h"
#include "object-store.h"
#include "commit.h"
#include "tag.h"
#include "diff.h"

+ 5
- 0
packfile.h View File

@@ -3,6 +3,11 @@

#include "oidset.h"

/* in object-store.h */
struct packed_git;
struct object_info;
enum object_type;

/*
* Generate the filename to be used for a pack file with checksum "sha1" and
* extension "ext". The result is written into the strbuf "buf", overwriting

+ 9
- 9
path.c View File

@@ -1442,12 +1442,12 @@ char *xdg_cache_home(const char *filename)
return NULL;
}

GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")
GIT_PATH_FUNC(git_path_merge_msg, "MERGE_MSG")
GIT_PATH_FUNC(git_path_merge_rr, "MERGE_RR")
GIT_PATH_FUNC(git_path_merge_mode, "MERGE_MODE")
GIT_PATH_FUNC(git_path_merge_head, "MERGE_HEAD")
GIT_PATH_FUNC(git_path_fetch_head, "FETCH_HEAD")
GIT_PATH_FUNC(git_path_shallow, "shallow")
REPO_GIT_PATH_FUNC(cherry_pick_head, "CHERRY_PICK_HEAD")
REPO_GIT_PATH_FUNC(revert_head, "REVERT_HEAD")
REPO_GIT_PATH_FUNC(squash_msg, "SQUASH_MSG")
REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
REPO_GIT_PATH_FUNC(shallow, "shallow")

+ 31
- 9
path.h View File

@@ -160,14 +160,36 @@ extern void report_linked_checkout_garbage(void);
return ret; \
}

const char *git_path_cherry_pick_head(void);
const char *git_path_revert_head(void);
const char *git_path_squash_msg(void);
const char *git_path_merge_msg(void);
const char *git_path_merge_rr(void);
const char *git_path_merge_mode(void);
const char *git_path_merge_head(void);
const char *git_path_fetch_head(void);
const char *git_path_shallow(void);
#define REPO_GIT_PATH_FUNC(var, filename) \
const char *git_path_##var(struct repository *r) \
{ \
if (!r->cached_paths.var) \
r->cached_paths.var = git_pathdup(filename); \
return r->cached_paths.var; \
}

struct path_cache {
const char *cherry_pick_head;
const char *revert_head;
const char *squash_msg;
const char *merge_msg;
const char *merge_rr;
const char *merge_mode;
const char *merge_head;
const char *fetch_head;
const char *shallow;
};

#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }

const char *git_path_cherry_pick_head(struct repository *r);
const char *git_path_revert_head(struct repository *r);
const char *git_path_squash_msg(struct repository *r);
const char *git_path_merge_msg(struct repository *r);
const char *git_path_merge_rr(struct repository *r);
const char *git_path_merge_mode(struct repository *r);
const char *git_path_merge_head(struct repository *r);
const char *git_path_fetch_head(struct repository *r);
const char *git_path_shallow(struct repository *r);

#endif /* PATH_H */

+ 1
- 0
read-cache.c View File

@@ -11,6 +11,7 @@
#include "cache-tree.h"
#include "refs.h"
#include "dir.h"
#include "object-store.h"
#include "tree.h"
#include "commit.h"
#include "blob.h"

+ 1
- 0
ref-filter.c View File

@@ -3,6 +3,7 @@
#include "parse-options.h"
#include "refs.h"
#include "wildmatch.h"
#include "object-store.h"
#include "commit.h"
#include "remote.h"
#include "color.h"

+ 1
- 0
refs.c View File

@@ -9,6 +9,7 @@
#include "iterator.h"
#include "refs.h"
#include "refs/refs-internal.h"
#include "object-store.h"
#include "object.h"
#include "tag.h"
#include "submodule.h"

+ 1
- 0
remote-testsvn.c View File

@@ -1,6 +1,7 @@
#include "cache.h"
#include "refs.h"
#include "remote.h"
#include "object-store.h"
#include "strbuf.h"
#include "url.h"
#include "exec-cmd.h"

+ 1
- 0
remote.c View File

@@ -3,6 +3,7 @@
#include "remote.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"

+ 5
- 0
repository.h View File

@@ -38,6 +38,11 @@ struct repository {
/* The store in which the refs are held. */
struct ref_store *refs;

/*
* Contains path to often used file names.
*/
struct path_cache cached_paths;

/*
* Path to the repository's graft file.
* Cannot be NULL after initialization.

+ 5
- 3
rerere.c View File

@@ -9,6 +9,7 @@
#include "ll-merge.h"
#include "attr.h"
#include "pathspec.h"
#include "object-store.h"
#include "sha1-lookup.h"

#define RESOLVED 0
@@ -200,7 +201,7 @@ static struct rerere_id *new_rerere_id(unsigned char *sha1)
static void read_rr(struct string_list *rr)
{
struct strbuf buf = STRBUF_INIT;
FILE *in = fopen_or_warn(git_path_merge_rr(), "r");
FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");

if (!in)
return;
@@ -895,7 +896,8 @@ int setup_rerere(struct string_list *merge_rr, int flags)
if (flags & RERERE_READONLY)
fd = 0;
else
fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
fd = hold_lock_file_for_update(&write_lock,
git_path_merge_rr(the_repository),
LOCK_DIE_ON_ERROR);
read_rr(merge_rr);
return fd;
@@ -1245,6 +1247,6 @@ void rerere_clear(struct string_list *merge_rr)
rmdir(rerere_path(id, NULL));
}
}
unlink_or_warn(git_path_merge_rr());
unlink_or_warn(git_path_merge_rr(the_repository));
rollback_lock_file(&write_lock);
}

+ 1
- 0
revision.c View File

@@ -1,4 +1,5 @@
#include "cache.h"
#include "object-store.h"
#include "tag.h"
#include "blob.h"
#include "tree.h"

+ 4
- 3
send-pack.c View File

@@ -2,6 +2,7 @@
#include "config.h"
#include "commit.h"
#include "refs.h"
#include "object-store.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
@@ -75,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
argv_array_push(&po.args, "-q");
if (args->progress)
argv_array_push(&po.args, "--progress");
if (is_repository_shallow())
if (is_repository_shallow(the_repository))
argv_array_push(&po.args, "--shallow");
po.in = -1;
po.out = args->stateless_rpc ? -1 : fd;
@@ -220,7 +221,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c

static void advertise_shallow_grafts_buf(struct strbuf *sb)
{
if (!is_repository_shallow())
if (!is_repository_shallow(the_repository))
return;
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
}
@@ -537,7 +538,7 @@ int send_pack(struct send_pack_args *args,
}

if (args->stateless_rpc) {
if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
packet_buf_flush(&req_buf);
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
}

+ 27
- 25
sequencer.c View File

@@ -2,6 +2,7 @@
#include "config.h"
#include "lockfile.h"
#include "dir.h"
#include "object-store.h"
#include "object.h"
#include "commit.h"
#include "sequencer.h"
@@ -357,7 +358,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
* (typically rebase --interactive) wants to take care
* of the commit itself so remove CHERRY_PICK_HEAD
*/
unlink(git_path_cherry_pick_head());
unlink(git_path_cherry_pick_head(the_repository));
return;
}

@@ -1324,8 +1325,8 @@ static int do_commit(const char *msg_file, const char *author,
&oid);
strbuf_release(&sb);
if (!res) {
unlink(git_path_cherry_pick_head());
unlink(git_path_merge_msg());
unlink(git_path_cherry_pick_head(the_repository));
unlink(git_path_merge_msg(the_repository));
if (!is_rebase_i(opts))
print_commit_summary(NULL, &oid,
SUMMARY_SHOW_AUTHOR_DATE);
@@ -1613,7 +1614,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
struct replay_opts *opts, int final_fixup)
{
unsigned int flags = opts->edit ? EDIT_MSG : 0;
const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);
struct object_id head;
struct commit *base, *next, *parent;
const char *base_label, *next_label;
@@ -1755,12 +1756,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
flags |= CLEANUP_MSG;
msg_file = rebase_path_fixup_msg();
} else {
const char *dest = git_path_squash_msg();
const char *dest = git_path_squash_msg(the_repository);
unlink(dest);
if (copy_file(dest, rebase_path_squash_msg(), 0666))
return error(_("could not rename '%s' to '%s'"),
rebase_path_squash_msg(), dest);
unlink(git_path_merge_msg());
unlink(git_path_merge_msg(the_repository));
msg_file = dest;
flags |= EDIT_MSG;
}
@@ -1778,13 +1779,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
goto leave;

res |= write_message(msgbuf.buf, msgbuf.len,
git_path_merge_msg(), 0);
git_path_merge_msg(the_repository), 0);
} else {
struct commit_list *common = NULL;
struct commit_list *remotes = NULL;

res = write_message(msgbuf.buf, msgbuf.len,
git_path_merge_msg(), 0);
git_path_merge_msg(the_repository), 0);

commit_list_insert(base, &common);
commit_list_insert(next, &remotes);
@@ -2394,8 +2395,8 @@ static int rollback_single_pick(void)
{
struct object_id head_oid;

if (!file_exists(git_path_cherry_pick_head()) &&
!file_exists(git_path_revert_head()))
if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
!file_exists(git_path_revert_head(the_repository)))
return error(_("no cherry-pick or revert in progress"));
if (read_ref_full("HEAD", 0, &head_oid, NULL))
return error(_("cannot resolve HEAD"));
@@ -2620,10 +2621,11 @@ static int error_failed_squash(struct commit *commit,
if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666))
return error(_("could not copy '%s' to '%s'"),
rebase_path_squash_msg(), rebase_path_message());
unlink(git_path_merge_msg());
if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666))
unlink(git_path_merge_msg(the_repository));
if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))
return error(_("could not copy '%s' to '%s'"),
rebase_path_message(), git_path_merge_msg());
rebase_path_message(),
git_path_merge_msg(the_repository));
return error_with_patch(commit, subject, subject_len, opts, 1, 0);
}

@@ -2913,11 +2915,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
write_author_script(message);
find_commit_subject(message, &body);
len = strlen(body);
ret = write_message(body, len, git_path_merge_msg(), 0);
ret = write_message(body, len, git_path_merge_msg(the_repository), 0);
unuse_commit_buffer(commit, message);
if (ret) {
error_errno(_("could not write '%s'"),
git_path_merge_msg());
git_path_merge_msg(the_repository));
goto leave_merge;
}
} else {
@@ -2938,11 +2940,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
len = buf.len;
}

ret = write_message(p, len, git_path_merge_msg(), 0);
ret = write_message(p, len, git_path_merge_msg(the_repository), 0);
strbuf_release(&buf);
if (ret) {
error_errno(_("could not write '%s'"),
git_path_merge_msg());
git_path_merge_msg(the_repository));
goto leave_merge;
}
}
@@ -2979,8 +2981,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
}

write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
git_path_merge_head(), 0);
write_message("no-ff", 5, git_path_merge_mode(), 0);
git_path_merge_head(the_repository), 0);
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);

bases = get_merge_bases(head_commit, merge_commit);
if (bases && !oidcmp(&merge_commit->object.oid,
@@ -3034,7 +3036,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
* value (a negative one would indicate that the `merge`
* command needs to be rescheduled).
*/
ret = !!run_git_commit(git_path_merge_msg(), opts,
ret = !!run_git_commit(git_path_merge_msg(the_repository), opts,
run_commit_flags);

leave_merge:
@@ -3401,8 +3403,8 @@ static int continue_single_pick(void)
{
const char *argv[] = { "commit", NULL };

if (!file_exists(git_path_cherry_pick_head()) &&
!file_exists(git_path_revert_head()))
if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
!file_exists(git_path_revert_head(the_repository)))
return error(_("no cherry-pick or revert in progress"));
return run_command_v_opt(argv, RUN_GIT_CMD);
}
@@ -3505,7 +3507,7 @@ static int commit_staged_changes(struct replay_opts *opts,
}

if (is_clean) {
const char *cherry_pick_head = git_path_cherry_pick_head();
const char *cherry_pick_head = git_path_cherry_pick_head(the_repository);

if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
return error(_("could not remove CHERRY_PICK_HEAD"));
@@ -3555,8 +3557,8 @@ int sequencer_continue(struct replay_opts *opts)

if (!is_rebase_i(opts)) {
/* Verify that the conflict has been resolved */
if (file_exists(git_path_cherry_pick_head()) ||
file_exists(git_path_revert_head())) {
if (file_exists(git_path_cherry_pick_head(the_repository)) ||
file_exists(git_path_revert_head(the_repository))) {
res = continue_single_pick();
if (res)
goto release_todo_list;

+ 38
- 36
shallow.c View File

@@ -1,6 +1,8 @@
#include "cache.h"
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
#include "object-store.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
@@ -13,22 +15,19 @@
#include "revision.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "repository.h"