MCPcopy Create free account
hub / github.com/ByConity/ByConity / updateSnapshot

Function updateSnapshot

programs/git-import/git-import.cpp:677–745  ·  view source on GitHub ↗

Enrich the line changes data with the history info from the snapshot * - the author, time and commit of the previous change to every found line (blame). * And update the snapshot. */

Source from the content-addressed store, hash-verified

675 * And update the snapshot.
676 */
677void updateSnapshot(Snapshot & snapshot, const Commit & commit, CommitDiff & file_changes)
678{
679 /// Renames and copies.
680 for (auto & elem : file_changes)
681 {
682 auto & file = elem.second.file_change;
683 if (!file.old_path.empty() && file.path != file.old_path)
684 snapshot[file.path] = snapshot[file.old_path];
685 }
686
687 for (auto & elem : file_changes)
688 {
689// std::cerr << elem.first << "\n";
690
691 FileBlame & file_snapshot = snapshot[elem.first];
692 std::unordered_map<uint32_t, Commit> deleted_lines;
693
694 /// Obtain blame info from previous state of the snapshot
695
696 for (auto & line_change : elem.second.line_changes)
697 {
698 if (line_change.sign == -1)
699 {
700 if (const Commit * prev_commit = file_snapshot.find(line_change.line_number_old);
701 prev_commit && prev_commit->time <= commit.time)
702 {
703 line_change.prev_commit_hash = prev_commit->hash;
704 line_change.prev_author = prev_commit->author;
705 line_change.prev_time = prev_commit->time;
706 deleted_lines[line_change.line_number_old] = *prev_commit;
707 }
708 else
709 {
710 // std::cerr << "Did not find line " << line_change.line_number_old << " from file " << elem.first << ": " << line_change.line << "\n";
711 }
712 }
713 else if (line_change.sign == 1)
714 {
715 uint32_t this_line_in_prev_commit = line_change.hunk_start_line_number_old
716 + (line_change.line_number_new - line_change.hunk_start_line_number_new);
717
718 if (deleted_lines.count(this_line_in_prev_commit))
719 {
720 const auto & prev_commit = deleted_lines[this_line_in_prev_commit];
721 if (prev_commit.time <= commit.time)
722 {
723 line_change.prev_commit_hash = prev_commit.hash;
724 line_change.prev_author = prev_commit.author;
725 line_change.prev_time = prev_commit.time;
726 }
727 }
728 }
729 }
730
731 /// Update the snapshot
732
733 for (const auto & line_change : elem.second.line_changes)
734 {

Callers 1

processCommitFunction · 0.85

Calls 5

removeLineMethod · 0.80
addLineMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected