Add more info to chunk lines
parent: tbd commit: 7ae7f1f
1 | use ; |
2 | use FromStr; |
3 | |
4 | use ; |
5 | |
6 | use crate GiteratedObject; |
7 | |
8 | use ; |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | pub use *; |
15 | pub use *; |
16 | pub use *; |
17 | |
18 | /// A repository, defined by the instance it exists on along with |
19 | /// its owner and name. |
20 | /// |
21 | /// # Textual Format |
22 | /// A repository's textual reference is defined as: |
23 | /// |
24 | /// `{owner: User}/{name: String}@{instance: Instance}` |
25 | /// |
26 | /// # Examples |
27 | /// For the repository named `foo` owned by `barson:giterated.dev` on the instance |
28 | /// `giterated.dev`, the following [`Repository`] initialization would |
29 | /// be valid: |
30 | /// |
31 | /// ``` |
32 | //# use giterated_models::model::repository::Repository; |
33 | //# use giterated_models::model::instance::Instance; |
34 | //# use giterated_models::model::user::User; |
35 | /// let repository = Repository { |
36 | /// owner: User::from_str("barson:giterated.dev").unwrap(), |
37 | /// name: String::from("foo"), |
38 | /// instance: Instance::from_str("giterated.dev").unwrap() |
39 | /// }; |
40 | /// |
41 | /// // This is correct |
42 | /// assert_eq!(Repository::from_str("barson:giterated.dev/[email protected]").unwrap(), repository); |
43 | /// ``` |
44 | |
45 | |
46 | pub owner: User, |
47 | pub name: String, |
48 | /// Instance the repository is on |
49 | pub instance: Instance, |
50 | |
51 | |
52 | |
53 | |
54 | f.write_str |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | "repository" |
61 | |
62 | |
63 | |
64 | Ok |
65 | |
66 | |
67 | |
68 | |
69 | type Error = RepositoryParseError; |
70 | |
71 | |
72 | Self from_str |
73 | |
74 | |
75 | |
76 | |
77 | type Err = RepositoryParseError; |
78 | |
79 | |
80 | let mut by_ampersand = s.split; |
81 | let mut path_split = by_ampersand.next .ok_or?.split; |
82 | |
83 | let instance = from_str |
84 | .map_err?; |
85 | let owner = from_str |
86 | .map_err?; |
87 | let name = path_split.next .ok_or?.to_string; |
88 | |
89 | Ok |
90 | instance, |
91 | owner, |
92 | name, |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | ; |
100 | |
101 | /// Visibility of the repository to the general eye |
102 | |
103 | |
104 | |
105 | Public, |
106 | Unlisted, |
107 | Private, |
108 | |
109 | |
110 | /// Implements [`Display`] for [`RepositoryVisiblity`] using [`Debug`] |
111 | |
112 | |
113 | write! |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | /// Name of the repository |
120 | /// |
121 | /// This is different than the [`Repository`] name, |
122 | /// which may be a path. |
123 | pub name: String, |
124 | /// Owner of the Repository |
125 | pub owner: User, |
126 | /// Repository description |
127 | pub description: , |
128 | /// Repository visibility |
129 | pub visibility: Visibility, |
130 | /// Default branch of the repository |
131 | pub default_branch: DefaultBranch, |
132 | /// Last commit made to the repository |
133 | pub latest_commit: , |
134 | /// Revision of the displayed tree |
135 | pub tree_rev: , |
136 | /// Repository tree |
137 | pub tree: , |
138 | |
139 | |
140 | |
141 | |
142 | /// Content of the file |
143 | pub content: , |
144 | /// If the file is binary or not |
145 | pub binary: bool, |
146 | /// File size in bytes |
147 | pub size: usize, |
148 | |
149 | |
150 | |
151 | |
152 | /// "to" side of the diff commit |
153 | pub new_commit: Commit, |
154 | /// Total number of files changed |
155 | pub files_changed: usize, |
156 | /// Total number of insertions |
157 | pub insertions: usize, |
158 | /// Total number of deletions |
159 | pub deletions: usize, |
160 | /// List of changed files |
161 | pub files: , |
162 | |
163 | |
164 | /// Represents the type of change made to a [`RepositoryDiffFile`] |
165 | |
166 | |
167 | /// No changes |
168 | Unmodified, |
169 | Added, |
170 | Deleted, |
171 | /// Content changed between old and new |
172 | Modified, |
173 | /// Renamed between old and new |
174 | Renamed, |
175 | /// Copied from another old entry |
176 | Copied, |
177 | /// Ignored item in workdir |
178 | Ignored, |
179 | /// Untracked item in workdir |
180 | Untracked, |
181 | /// Type of file changed between old and new |
182 | Typechange, |
183 | /// File is unreadable |
184 | Unreadable, |
185 | /// File in the index is conflicted |
186 | Conflicted, |
187 | |
188 | |
189 | |
190 | |
191 | match status |
192 | => Self Unmodified, | Unmodified
193 | => Self Added, | Added
194 | => Self Deleted, | Deleted
195 | => Self Modified, | Modified
196 | => Self Renamed, | Renamed
197 | => Self Copied, | Copied
198 | => Self Ignored, | Ignored
199 | => Self Untracked, | Untracked
200 | => Self Typechange, | Typechange
201 | => Self Unreadable, | Unreadable
202 | => Self Conflicted, | Conflicted
203 | |
204 | |
205 | |
206 | |
207 | /// Represents a single file of a diff |
208 | |
209 | |
210 | /// The type of change made to this file |
211 | pub status: RepositoryDiffFileStatus, |
212 | /// "From" side of the diff, can be nonexistent if file for example got added for the first time |
213 | pub old_file_info: , |
214 | /// "To" side of the diff, can be nonexistent if file got removed |
215 | pub new_file_info: , |
216 | /// Individual chunks of changes in this file |
217 | pub chunks: , |
218 | |
219 | |
220 | /// Represents one side of a file diff [`RepositoryDiffFile`] |
221 | |
222 | |
223 | /// ID of the file |
224 | pub id: String, |
225 | /// Path of the entry relative to the working directory of the repository |
226 | pub path: String, |
227 | /// Size in bytes |
228 | pub size: u64, |
229 | /// If the file is binary or not |
230 | pub binary: bool, |
231 | |
232 | |
233 | /// Represents a single chunk of a file diff [`RepositoryDiffFile`] |
234 | |
235 | |
236 | /// Header of the chunk |
237 | pub header: , |
238 | /// Starting line number of the old file |
239 | pub old_start: u32, |
240 | /// Number of lines in "from" side of this chunk |
241 | pub old_lines: u32, |
242 | /// Starting line number of the new file |
243 | pub new_start: u32, |
244 | /// Number of lines in "to" side of this chunk |
245 | pub new_lines: u32, |
246 | /// Lines of the chunk |
247 | pub lines: , |
248 | |
249 | |
250 | /// Represents the change type of the [`RepositoryChunkLine`], incomplete of what git actually provides. |
251 | |
252 | |
253 | Context, |
254 | Addition, |
255 | Deletion, |
256 | |
257 | |
258 | |
259 | |
260 | match line_type |
261 | => Self Context, | Context
262 | => Self Addition, | Addition
263 | => Self Deletion, | Deletion
264 | _ => Self Context, |
265 | |
266 | |
267 | |
268 | |
269 | /// Represents a single line of a [`RepositoryDiffFileChunk`] |
270 | |
271 | |
272 | /// Type of change the line is |
273 | pub change_type: RepositoryChunkLineType, |
274 | /// Content of the line |
275 | pub content: String, |
276 | /// Line number in old file |
277 | pub old_line_num: , |
278 | /// Line number in new file |
279 | pub new_line_num: , |
280 | |
281 | |
282 | |
283 | |
284 | Tree, |
285 | Blob, |
286 | |
287 | |
288 | /// Stored info for our tree entries |
289 | |
290 | |
291 | /// ID of the tree/blob |
292 | pub id: String, |
293 | /// Name of the tree/blob |
294 | pub name: String, |
295 | /// Type of the tree entry |
296 | pub object_type: RepositoryObjectType, |
297 | /// Git supplies us with the mode at all times, and people like it displayed. |
298 | pub mode: i32, |
299 | /// File size |
300 | pub size: , |
301 | /// Last commit made to the tree/blob |
302 | pub last_commit: , |
303 | |
304 | |
305 | |
306 | // I love you Emilia <3 |
307 | |
308 | Self |
309 | id: id.to_string, |
310 | name: name.to_string, |
311 | object_type, |
312 | mode, |
313 | size: None, |
314 | last_commit: None, |
315 | |
316 | |
317 | |
318 | |
319 | |
320 | |
321 | pub tree_entry: RepositoryTreeEntry, |
322 | pub commit: Commit, |
323 | |
324 | |
325 | /// Info about a git commit |
326 | |
327 | |
328 | /// Unique commit ID |
329 | pub oid: String, |
330 | /// Shortened abbreviated OID |
331 | /// This starts at the git config's "core.abbrev" length (default 7 characters) and |
332 | /// iteratively extends to a longer string if that length is ambiguous. The |
333 | /// result will be unambiguous (at least until new objects are added to the repository). |
334 | pub short_oid: String, |
335 | /// First paragraph of the full message |
336 | pub summary: , |
337 | /// Everything in the full message apart from the first paragraph |
338 | pub body: , |
339 | /// All commit id's of the parents of this commit |
340 | pub parents: , |
341 | /// Who created the commit |
342 | pub author: CommitSignature, |
343 | /// Who committed the commit |
344 | pub committer: CommitSignature, |
345 | /// Time when the commit happened |
346 | pub time: NaiveDateTime, |
347 | |
348 | |
349 | /// Gets all info from [`git2::Commit`] for easy use |
350 | |
351 | |
352 | Self |
353 | oid: commit.id .to_string, |
354 | // This shouldn't ever fail, as we already know the object has an oid. |
355 | short_oid: commit |
356 | .as_object |
357 | .short_id |
358 | .unwrap |
359 | .as_str |
360 | .unwrap |
361 | .to_string, |
362 | summary: commit.summary .map, |
363 | body: commit.body .map, |
364 | parents: commit |
365 | .parents |
366 | .map |
367 | ., |
368 | author: commit.author .into, |
369 | committer: commit.committer .into, |
370 | time: from_timestamp_opt .unwrap, |
371 | |
372 | |
373 | |
374 | |
375 | /// Git commit signature |
376 | |
377 | |
378 | pub name: , |
379 | pub email: , |
380 | pub time: NaiveDateTime, |
381 | |
382 | |
383 | /// Converts the signature from git2 into something usable without explicit lifetimes. |
384 | |
385 | |
386 | Self |
387 | name: signature.name .map, |
388 | email: signature.email .map, |
389 | time: from_timestamp_opt .unwrap, |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | pub repository: Repository, |
397 | pub owner: User, |
398 | pub visibility: RepositoryVisibility, |
399 | pub description: , |
400 | pub last_commit: , |
401 | |
402 | |
403 | |
404 | |
405 | pub name: String, |
406 | pub color: String, |
407 | |
408 | |
409 | |
410 | |
411 | pub author: User, |
412 | pub id: u64, |
413 | pub title: String, |
414 | pub contents: String, |
415 | pub labels: , |
416 | |
417 |