-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.rs
More file actions
139 lines (121 loc) · 4.64 KB
/
Copy pathpython.rs
File metadata and controls
139 lines (121 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! PyO3 surface — compiled ONLY with the `python` feature. Thin wrappers that
//! call into the pure-Rust `repo` / `status` cores and convert types/errors for
//! Python. Each M1 method task replaces that method's `todo!()` wrapper with a
//! call into `crate::repo::<method>` (soft-fail methods map errors to the
//! sentinel; the rest propagate `GitxtendError` → `PyRuntimeError`).
//!
//! Soft-fail methods (see `docs/API.md`) must return sentinels (None/0/[]/{})
//! instead of raising, to stay drop-in compatible with git-tend's GitService.
use pyo3::prelude::*;
use std::collections::HashMap;
/// Roll-up mirroring `StatusService.check_repo` / `models.RepoStatus`.
///
/// `skip_from_py_object`: this type is returned to Python, never parsed from it,
/// so we opt out of the (now-opt-in) `FromPyObject` derive.
#[pyclass(skip_from_py_object)]
#[derive(Clone, Default)]
pub struct RepoStatus {
#[pyo3(get)]
pub path: String,
#[pyo3(get)]
pub state: String, // SyncState value, see docs/API.md
#[pyo3(get)]
pub local_branch: Option<String>,
#[pyo3(get)]
pub tracking_branch: Option<String>,
#[pyo3(get)]
pub local_sha: Option<String>,
#[pyo3(get)]
pub remote_sha: Option<String>,
#[pyo3(get)]
pub ahead_count: usize,
#[pyo3(get)]
pub behind_count: usize,
#[pyo3(get)]
pub new_remote_commits: Vec<String>,
#[pyo3(get)]
pub is_dirty: bool,
#[pyo3(get)]
pub error: Option<String>,
}
// ---- Read primitives — Python wrappers (todo! until each method lands) ----
//
// As each `crate::repo::<method>` lands, replace the matching `todo!()` body
// with a call into it. The pure-Rust core is what carries the gix logic + tests.
#[pyfunction]
fn is_git_repo(path: String) -> PyResult<bool> {
Ok(crate::repo::is_git_repo(std::path::Path::new(&path)))
}
#[pyfunction]
fn is_clean(_path: String) -> PyResult<bool> {
todo!("repo::is_clean (gix status, empty)")
}
#[pyfunction]
fn current_branch(path: String) -> PyResult<Option<String>> {
// soft-fail: any error -> None (API.md)
Ok(crate::repo::current_branch(std::path::Path::new(&path)).unwrap_or(None))
}
#[pyfunction]
fn tracking_branch(_path: String) -> PyResult<Option<String>> {
todo!("repo::tracking_branch (configured upstream)")
}
#[pyfunction]
fn head_sha(path: String) -> PyResult<Option<String>> {
// soft-fail: any error -> None (API.md)
Ok(crate::repo::head_sha(std::path::Path::new(&path)).unwrap_or(None))
}
#[pyfunction]
fn remote_head_sha(_path: String, _remote_ref: String) -> PyResult<Option<String>> {
todo!("repo::remote_head_sha (resolve remote-tracking ref)")
}
#[pyfunction]
fn ahead_behind(_path: String, _upstream: String) -> PyResult<(usize, usize)> {
todo!("repo::ahead_behind (single graph walk)")
}
#[pyfunction]
fn rev_list_count(_path: String, _range_spec: String) -> PyResult<usize> {
todo!("repo::rev_list_count (soft-fail 0)")
}
#[pyfunction]
fn log_subjects(_path: String, _range_spec: String, _max_count: usize) -> PyResult<Vec<String>> {
todo!("repo::log_subjects (summaries, newest first)")
}
#[pyfunction]
fn remote_urls(_path: String) -> PyResult<HashMap<String, String>> {
todo!("repo::remote_urls (name -> fetch url)")
}
#[pyfunction]
fn last_commit_date(_path: String) -> PyResult<Option<String>> {
todo!("repo::last_commit_date (ISO 8601 %aI)")
}
#[pyfunction]
fn status_counts(_path: String) -> PyResult<(usize, usize)> {
todo!("repo::status_counts (modified, untracked)")
}
#[pyfunction]
fn fetch(_path: String, _remote: Option<String>) -> PyResult<bool> {
todo!("repo::fetch (gix fetch, contained shell-out fallback)")
}
#[pyfunction]
fn repo_status(_path: String, _fetch: bool) -> PyResult<RepoStatus> {
todo!("status::repo_status (full SyncState decision tree)")
}
#[pymodule]
fn _gitxtend(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<RepoStatus>()?;
m.add_function(wrap_pyfunction!(is_git_repo, m)?)?;
m.add_function(wrap_pyfunction!(is_clean, m)?)?;
m.add_function(wrap_pyfunction!(current_branch, m)?)?;
m.add_function(wrap_pyfunction!(tracking_branch, m)?)?;
m.add_function(wrap_pyfunction!(head_sha, m)?)?;
m.add_function(wrap_pyfunction!(remote_head_sha, m)?)?;
m.add_function(wrap_pyfunction!(ahead_behind, m)?)?;
m.add_function(wrap_pyfunction!(rev_list_count, m)?)?;
m.add_function(wrap_pyfunction!(log_subjects, m)?)?;
m.add_function(wrap_pyfunction!(remote_urls, m)?)?;
m.add_function(wrap_pyfunction!(last_commit_date, m)?)?;
m.add_function(wrap_pyfunction!(status_counts, m)?)?;
m.add_function(wrap_pyfunction!(fetch, m)?)?;
m.add_function(wrap_pyfunction!(repo_status, m)?)?;
Ok(())
}