Skip to content

Commit 5fe35fc

Browse files
committed
Merge branch 'jt/reset-grafts-when-resetting-shallow'
When "shallow" information is updated, we forgot to update the in-core equivalent, which has been corrected. * jt/reset-grafts-when-resetting-shallow: shallow: reset commit grafts when shallow is reset
2 parents d629667 + 2a69ff0 commit 5fe35fc

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
249249
return ret;
250250
}
251251

252+
void reset_commit_grafts(struct repository *r)
253+
{
254+
int i;
255+
256+
for (i = 0; i < r->parsed_objects->grafts_nr; i++)
257+
free(r->parsed_objects->grafts[i]);
258+
r->parsed_objects->grafts_nr = 0;
259+
r->parsed_objects->commit_graft_prepared = 0;
260+
}
261+
252262
struct commit_buffer {
253263
void *buffer;
254264
unsigned long size;

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ int commit_graft_pos(struct repository *r, const struct object_id *oid);
249249
int register_commit_graft(struct repository *r, struct commit_graft *, int);
250250
void prepare_commit_graft(struct repository *r);
251251
struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
252+
void reset_commit_grafts(struct repository *r);
252253

253254
struct commit *get_fork_point(const char *refname, struct commit *commit);
254255

shallow.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static void reset_repository_shallow(struct repository *r)
9090
{
9191
r->parsed_objects->is_shallow = -1;
9292
stat_validity_clear(r->parsed_objects->shallow_stat);
93+
reset_commit_grafts(r);
9394
}
9495

9596
int commit_shallow_file(struct repository *r, struct shallow_lock *lk)

submodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "parse-options.h"
2323
#include "object-store.h"
2424
#include "commit-reach.h"
25+
#include "shallow.h"
2526

2627
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
2728
static int initialized_fetch_ref_tips;

t/t5537-fetch-shallow.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ test_expect_success 'fetch --update-shallow' '
161161
)
162162
'
163163

164+
test_expect_success 'fetch --update-shallow into a repo with submodules' '
165+
git init a-submodule &&
166+
test_commit -C a-submodule foo &&
167+
git init repo-with-sub &&
168+
git -C repo-with-sub submodule add ../a-submodule a-submodule &&
169+
git -C repo-with-sub commit -m "added submodule" &&
170+
git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/*
171+
'
172+
164173
test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
165174
(
166175
cd shallow &&

0 commit comments

Comments
 (0)