git_indexer/models.rs
1//! Data models for git repository information.
2//!
3//! This module contains the core data structures used to represent
4//! git repository information including branches, commits, tags, and file changes.
5
6use serde::{Deserialize, Serialize};
7
8/// Complete git repository information.
9///
10/// Contains all branches, tags, and commits extracted from a git repository.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct GitInfo {
13 /// All branches (local and remote) in the repository.
14 pub branches: Vec<BranchInfo>,
15 /// All tags in the repository.
16 pub tags: Vec<TagInfo>,
17 /// All commits reachable from any branch.
18 pub commits: Vec<CommitInfo>,
19}
20
21/// Information about a git branch.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct BranchInfo {
24 /// Branch name (e.g., "main", "feature/foo", "origin/main").
25 pub name: String,
26 /// Whether this branch is the current HEAD.
27 pub is_head: bool,
28 /// SHA hash of the commit this branch points to.
29 pub commit_id: String,
30 /// Whether this is a remote-tracking branch.
31 pub is_remote: bool,
32}
33
34/// Information about a git tag.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct TagInfo {
37 /// Tag name (e.g., "v1.0.0").
38 pub name: String,
39 /// SHA hash of the object this tag points to (usually a commit).
40 pub target_id: String,
41 /// Whether this is an annotated tag (vs lightweight).
42 pub is_annotated: bool,
43 /// Tagger name and email (for annotated tags).
44 pub tagger: Option<String>,
45 /// Tag message (for annotated tags).
46 pub message: Option<String>,
47}
48
49/// Information about a git commit.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct CommitInfo {
52 /// SHA hash of the commit.
53 pub id: String,
54 /// SHA hash of the tree object (represents directory state at this commit).
55 pub tree_id: String,
56 /// Commit message (first line/title).
57 pub message: String,
58 /// Author in `Name <email>` format.
59 pub author: String,
60 /// Commit timestamp (seconds since Unix epoch).
61 pub timestamp: i64,
62 /// SHA hashes of parent commits.
63 pub parent_ids: Vec<String>,
64 /// Files changed in this commit.
65 pub file_changes: Vec<FileChange>,
66}
67
68/// A file change within a commit.
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct FileChange {
71 /// Path to the file.
72 pub path: String,
73 /// Previous path (for renames/copies).
74 pub old_path: Option<String>,
75 /// Type of change made to the file.
76 pub change_type: ChangeType,
77 /// SHA hash of the old blob (None for added files).
78 pub old_blob_sha: Option<String>,
79 /// SHA hash of the new blob (None for deleted files).
80 pub new_blob_sha: Option<String>,
81 /// Diff hunks showing the actual changes.
82 pub hunks: Vec<DiffHunk>,
83}
84
85/// Type of change made to a file.
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub enum ChangeType {
88 /// File was added in this commit.
89 Added,
90 /// File was deleted in this commit.
91 Deleted,
92 /// File was modified in this commit.
93 Modified,
94 /// File was renamed (with similarity percentage).
95 Renamed {
96 /// Percentage of content similarity (0-100).
97 similarity: u8,
98 },
99 /// File was copied (with similarity percentage).
100 Copied {
101 /// Percentage of content similarity (0-100).
102 similarity: u8,
103 },
104}
105
106/// A single diff hunk representing a contiguous change.
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct DiffHunk {
109 /// Starting line number in the old file.
110 pub old_start: u32,
111 /// Number of lines from the old file.
112 pub old_lines: u32,
113 /// Starting line number in the new file.
114 pub new_start: u32,
115 /// Number of lines in the new file.
116 pub new_lines: u32,
117 /// The actual diff content (lines prefixed with +, -, or space).
118 pub content: String,
119}