summaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-05-01 20:39:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-05-01 20:39:51 (GMT)
commit2b4ff3d3dc64d4abcded7caa9bcdf063aea5ec3f (patch)
treed92a6b80a57a024256b1306665e629ae1d4b8185 /shallow.c
parentcc0c732f6ba533ed4ee9f8a29f30628b04dba373 (diff)
parent37b9dcabfc48b0cbce638140279878dac37aec73 (diff)
downloadgit-2b4ff3d3dc64d4abcded7caa9bcdf063aea5ec3f.zip
git-2b4ff3d3dc64d4abcded7caa9bcdf063aea5ec3f.tar.gz
git-2b4ff3d3dc64d4abcded7caa9bcdf063aea5ec3f.tar.bz2
Merge branch 'tb/reset-shallow'
Fix in-core inconsistency after fetching into a shallow repository that broke the code to write out commit-graph. * tb/reset-shallow: shallow.c: use '{commit,rollback}_shallow_file' t5537: use test_write_lines and indented heredocs for readability
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/shallow.c b/shallow.c
index 14f7fa6..321a276 100644
--- a/shallow.c
+++ b/shallow.c
@@ -40,13 +40,6 @@ int register_shallow(struct repository *r, const struct object_id *oid)
int is_repository_shallow(struct repository *r)
{
- /*
- * NEEDSWORK: This function updates
- * r->parsed_objects->{is_shallow,shallow_stat} as a side effect but
- * there is no corresponding function to clear them when the shallow
- * file is updated.
- */
-
FILE *fp;
char buf[1024];
const char *path = r->parsed_objects->alternate_shallow_file;
@@ -79,6 +72,25 @@ int is_repository_shallow(struct repository *r)
return r->parsed_objects->is_shallow;
}
+static void reset_repository_shallow(struct repository *r)
+{
+ r->parsed_objects->is_shallow = -1;
+ stat_validity_clear(r->parsed_objects->shallow_stat);
+}
+
+int commit_shallow_file(struct repository *r, struct lock_file *lk)
+{
+ int res = commit_lock_file(lk);
+ reset_repository_shallow(r);
+ return res;
+}
+
+void rollback_shallow_file(struct repository *r, struct lock_file *lk)
+{
+ rollback_lock_file(lk);
+ reset_repository_shallow(r);
+}
+
/*
* TODO: use "int" elemtype instead of "int *" when/if commit-slab
* supports a "valid" flag.
@@ -410,10 +422,10 @@ void prune_shallow(unsigned options)
if (write_in_full(fd, sb.buf, sb.len) < 0)
die_errno("failed to write to %s",
get_lock_file_path(&shallow_lock));
- commit_lock_file(&shallow_lock);
+ commit_shallow_file(the_repository, &shallow_lock);
} else {
unlink(git_path_shallow(the_repository));
- rollback_lock_file(&shallow_lock);
+ rollback_shallow_file(the_repository, &shallow_lock);
}
strbuf_release(&sb);
}