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

Function updateSnapshot

programs/git-import/git-import.cpp:686–754  ·  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

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

Callers 1

processCommitFunction · 0.85

Calls 5

removeLineMethod · 0.80
addLineMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected