Skip to content

Commit ceb7a01

Browse files
committed
Merge branch 'jn/per-repo-object-store-fixes'
Step #0 of a planned & larger series to make the in-core object store per in-core repository object. * jn/per-repo-object-store-fixes: replace-objects: evaluate replacement refs without using the object store push, fetch: error out for submodule entries not pointing to commits pack: make packed_git_mru global a value instead of a pointer
2 parents c50424a + 006f3f2 commit ceb7a01

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ static int want_object_in_pack(const unsigned char *sha1,
10121012
return want;
10131013
}
10141014

1015-
for (entry = packed_git_mru->head; entry; entry = entry->next) {
1015+
for (entry = packed_git_mru.head; entry; entry = entry->next) {
10161016
struct packed_git *p = entry->item;
10171017
off_t offset;
10181018

@@ -1030,7 +1030,7 @@ static int want_object_in_pack(const unsigned char *sha1,
10301030
}
10311031
want = want_found_object(exclude, p);
10321032
if (!exclude && want > 0)
1033-
mru_mark(packed_git_mru, entry);
1033+
mru_mark(&packed_git_mru, entry);
10341034
if (want != -1)
10351035
return want;
10361036
}

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "git-compat-util.h"
55
#include "strbuf.h"
66
#include "hashmap.h"
7+
#include "mru.h"
78
#include "advice.h"
89
#include "gettext.h"
910
#include "convert.h"
@@ -1589,8 +1590,7 @@ extern struct packed_git {
15891590
* A most-recently-used ordered version of the packed_git list, which can
15901591
* be iterated instead of packed_git (and marked via mru_mark).
15911592
*/
1592-
struct mru;
1593-
extern struct mru *packed_git_mru;
1593+
extern struct mru packed_git_mru;
15941594

15951595
struct pack_entry {
15961596
off_t offset;

packfile.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ static unsigned int pack_max_fds;
4040
static size_t peak_pack_mapped;
4141
static size_t pack_mapped;
4242
struct packed_git *packed_git;
43-
44-
static struct mru packed_git_mru_storage;
45-
struct mru *packed_git_mru = &packed_git_mru_storage;
43+
struct mru packed_git_mru;
4644

4745
#define SZ_FMT PRIuMAX
4846
static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -861,9 +859,9 @@ static void prepare_packed_git_mru(void)
861859
{
862860
struct packed_git *p;
863861

864-
mru_clear(packed_git_mru);
862+
mru_clear(&packed_git_mru);
865863
for (p = packed_git; p; p = p->next)
866-
mru_append(packed_git_mru, p);
864+
mru_append(&packed_git_mru, p);
867865
}
868866

869867
static int prepare_packed_git_run_once = 0;
@@ -1832,9 +1830,9 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
18321830
if (!packed_git)
18331831
return 0;
18341832

1835-
for (p = packed_git_mru->head; p; p = p->next) {
1833+
for (p = packed_git_mru.head; p; p = p->next) {
18361834
if (fill_pack_entry(sha1, e, p->item)) {
1837-
mru_mark(packed_git_mru, p);
1835+
mru_mark(&packed_git_mru, p);
18381836
return 1;
18391837
}
18401838
}

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)
13571357
return do_for_each_ref(get_main_ref_store(),
13581358
git_replace_ref_base, fn,
13591359
strlen(git_replace_ref_base),
1360-
0, cb_data);
1360+
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
13611361
}
13621362

13631363
int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)

submodule.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,19 +774,36 @@ static int append_oid_to_argv(const struct object_id *oid, void *data)
774774
return 0;
775775
}
776776

777+
struct has_commit_data {
778+
int result;
779+
const char *path;
780+
};
781+
777782
static int check_has_commit(const struct object_id *oid, void *data)
778783
{
779-
int *has_commit = data;
784+
struct has_commit_data *cb = data;
780785

781-
if (!lookup_commit_reference(oid))
782-
*has_commit = 0;
786+
enum object_type type = sha1_object_info(oid->hash, NULL);
783787

784-
return 0;
788+
switch (type) {
789+
case OBJ_COMMIT:
790+
return 0;
791+
case OBJ_BAD:
792+
/*
793+
* Object is missing or invalid. If invalid, an error message
794+
* has already been printed.
795+
*/
796+
cb->result = 0;
797+
return 0;
798+
default:
799+
die(_("submodule entry '%s' (%s) is a %s, not a commit"),
800+
cb->path, oid_to_hex(oid), typename(type));
801+
}
785802
}
786803

787804
static int submodule_has_commits(const char *path, struct oid_array *commits)
788805
{
789-
int has_commit = 1;
806+
struct has_commit_data has_commit = { 1, path };
790807

791808
/*
792809
* Perform a cheap, but incorrect check for the existence of 'commits'.
@@ -802,7 +819,7 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
802819

803820
oid_array_for_each_unique(commits, check_has_commit, &has_commit);
804821

805-
if (has_commit) {
822+
if (has_commit.result) {
806823
/*
807824
* Even if the submodule is checked out and the commit is
808825
* present, make sure it exists in the submodule's object store
@@ -821,12 +838,12 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
821838
cp.dir = path;
822839

823840
if (capture_command(&cp, &out, GIT_MAX_HEXSZ + 1) || out.len)
824-
has_commit = 0;
841+
has_commit.result = 0;
825842

826843
strbuf_release(&out);
827844
}
828845

829-
return has_commit;
846+
return has_commit.result;
830847
}
831848

832849
static int submodule_needs_pushing(const char *path, struct oid_array *commits)

t/t5531-deep-submodule-push.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ test_expect_success 'push succeeds if submodule commit disabling recursion from
298298
)
299299
'
300300

301+
test_expect_success 'submodule entry pointing at a tag is error' '
302+
git -C work/gar/bage tag -a test1 -m "tag" &&
303+
tag=$(git -C work/gar/bage rev-parse test1^{tag}) &&
304+
git -C work update-index --cacheinfo 160000 "$tag" gar/bage &&
305+
git -C work commit -m "bad commit" &&
306+
test_when_finished "git -C work reset --hard HEAD^" &&
307+
test_must_fail git -C work push --recurse-submodules=on-demand ../pub.git master 2>err &&
308+
test_i18ngrep "is a tag, not a commit" err
309+
'
310+
301311
test_expect_success 'push fails if recurse submodules option passed as yes' '
302312
(
303313
cd work/gar/bage &&

0 commit comments

Comments
 (0)