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, and file changes.
5
6use serde::{Deserialize, Serialize};
7
8/// Complete git repository information.
9///
10/// Contains all branches 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 commits reachable from any branch.
16 pub commits: Vec<CommitInfo>,
17}
18
19/// Information about a git branch.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct BranchInfo {
22 /// Branch name (e.g., "main", "feature/foo", "origin/main").
23 pub name: String,
24 /// Whether this branch is the current HEAD.
25 pub is_head: bool,
26 /// SHA hash of the commit this branch points to.
27 pub commit_id: String,
28 /// Whether this is a remote-tracking branch.
29 pub is_remote: bool,
30}
31
32/// Information about a git commit.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct CommitInfo {
35 /// SHA hash of the commit.
36 pub id: String,
37 /// Commit message (first line/title).
38 pub message: String,
39 /// Author in `Name <email>` format.
40 pub author: String,
41 /// Commit timestamp (seconds since Unix epoch).
42 pub timestamp: i64,
43 /// SHA hashes of parent commits.
44 pub parent_ids: Vec<String>,
45 /// Files changed in this commit.
46 pub file_changes: Vec<FileChange>,
47}
48
49/// A file change within a commit.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct FileChange {
52 /// Path to the file.
53 pub path: String,
54 /// Previous path (for renames/copies).
55 pub old_path: Option<String>,
56 /// Type of change made to the file.
57 pub change_type: ChangeType,
58 /// Diff hunks showing the actual changes.
59 pub hunks: Vec<DiffHunk>,
60}
61
62/// Type of change made to a file.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub enum ChangeType {
65 /// File was added in this commit.
66 Added,
67 /// File was deleted in this commit.
68 Deleted,
69 /// File was modified in this commit.
70 Modified,
71 /// File was renamed (with similarity percentage).
72 Renamed {
73 /// Percentage of content similarity (0-100).
74 similarity: u8,
75 },
76 /// File was copied (with similarity percentage).
77 Copied {
78 /// Percentage of content similarity (0-100).
79 similarity: u8,
80 },
81}
82
83/// A single diff hunk representing a contiguous change.
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct DiffHunk {
86 /// Starting line number in the old file.
87 pub old_start: u32,
88 /// Number of lines from the old file.
89 pub old_lines: u32,
90 /// Starting line number in the new file.
91 pub new_start: u32,
92 /// Number of lines in the new file.
93 pub new_lines: u32,
94 /// The actual diff content (lines prefixed with +, -, or space).
95 pub content: String,
96}