From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Christian Couder" <christian.couder@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Jeff King" <peff@peff.net>,
"Jeff Hostetler" <jeffhost@microsoft.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Derrick Stolee" <derrickstolee@github.com>,
"Johannes Schindelin" <johannes.schindelin@gmx.de>,
"ZheNing Hu" <adlternative@gmail.com>,
"ZheNing Hu" <adlternative@gmail.com>
Subject: [PATCH 1/3] commit-graph: let commit graph respect commit graft
Date: Thu, 01 Sep 2022 09:41:10 +0000 [thread overview]
Message-ID: <19fd72c34dcd1332df638d76b0b028e9d9da3d41.1662025272.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1343.git.1662025272.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>
In repo_parse_commit_internal(), if we want to use
commit graph, it will call parse_commit_in_graph() to
parse commit's content from commit graph, otherwise
call repo_read_object_file() to parse commit's content
from commit object.
repo_read_object_file() will respect commit graft,
which can correctly amend commit's parents. But
parse_commit_in_graph() not. Inconsistencies here may
result in incorrect processing of shallow clone.
So let parse_commit_in_graph() respect commit graft as
repo_read_object_file() does, which can solve this problem.
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
commit-graph.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index f2a36032f84..89bb6f87079 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -820,6 +820,7 @@ static int fill_commit_in_graph(struct repository *r,
struct commit_list **pptr;
const unsigned char *commit_data;
uint32_t lex_index;
+ struct commit_graft *graft;
while (pos < g->num_commits_in_base)
g = g->base_graph;
@@ -833,31 +834,54 @@ static int fill_commit_in_graph(struct repository *r,
set_commit_tree(item, NULL);
+ graft = lookup_commit_graft(r, &item->object.oid);
+ if (graft)
+ r->parsed_objects->substituted_parent = 1;
+
pptr = &item->parents;
edge_value = get_be32(commit_data + g->hash_len);
if (edge_value == GRAPH_PARENT_NONE)
return 1;
- pptr = insert_parent_or_die(r, g, edge_value, pptr);
+ if (!(graft && (graft->nr_parent < 0 || grafts_replace_parents)))
+ pptr = insert_parent_or_die(r, g, edge_value, pptr);
edge_value = get_be32(commit_data + g->hash_len + 4);
if (edge_value == GRAPH_PARENT_NONE)
return 1;
if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) {
- pptr = insert_parent_or_die(r, g, edge_value, pptr);
- return 1;
+ if (!(graft && (graft->nr_parent < 0 || grafts_replace_parents))) {
+ pptr = insert_parent_or_die(r, g, edge_value, pptr);
+ return 1;
+ }
}
parent_data_ptr = (uint32_t*)(g->chunk_extra_edges +
4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
do {
edge_value = get_be32(parent_data_ptr);
- pptr = insert_parent_or_die(r, g,
- edge_value & GRAPH_EDGE_LAST_MASK,
- pptr);
+ if (!(graft && (graft->nr_parent < 0 || grafts_replace_parents))) {
+ pptr = insert_parent_or_die(r, g,
+ edge_value & GRAPH_EDGE_LAST_MASK,
+ pptr);
+ }
parent_data_ptr++;
} while (!(edge_value & GRAPH_LAST_EDGE));
+ if (graft) {
+ int i;
+ struct commit *new_parent;
+ for (i = 0; i < graft->nr_parent; i++) {
+ new_parent = lookup_commit(r,
+ &graft->parent[i]);
+ if (!new_parent)
+ die(_("bad graft parent %s in commit %s"),
+ oid_to_hex(&graft->parent[i]),
+ oid_to_hex(&item->object.oid));
+ pptr = &commit_list_insert(new_parent, pptr)->next;
+ }
+ }
+
return 1;
}
--
gitgitgadget
next prev parent reply other threads:[~2022-09-01 9:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-01 9:41 [PATCH 0/3] list-object-filter: introduce depth filter ZheNing Hu via GitGitGadget
2022-09-01 9:41 ` ZheNing Hu via GitGitGadget [this message]
2022-09-01 19:18 ` [PATCH 1/3] commit-graph: let commit graph respect commit graft Derrick Stolee
2022-09-04 5:57 ` ZheNing Hu
2022-09-01 9:41 ` [PATCH 2/3] list-object-filter: pass traversal_context in filter_init_fn ZheNing Hu via GitGitGadget
2022-09-01 9:41 ` [PATCH 3/3] list-object-filter: introduce depth filter ZheNing Hu via GitGitGadget
2022-09-01 19:24 ` [PATCH 0/3] " Derrick Stolee
2022-09-02 13:48 ` Johannes Schindelin
2022-09-04 9:14 ` ZheNing Hu
2022-09-07 10:18 ` Johannes Schindelin
2022-09-11 10:59 ` ZheNing Hu
2022-09-04 7:27 ` ZheNing Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19fd72c34dcd1332df638d76b0b028e9d9da3d41.1662025272.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=adlternative@gmail.com \
--cc=avarab@gmail.com \
--cc=christian.couder@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.com \
--cc=johannes.schindelin@gmx.de \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).