Download
jcs
/amend
/repo.h
(View History)
jcs browser: Use a custom LDEF for file list to cross out deleted files | Latest amendment: 253 on 2023-11-01 |
1 | /* |
2 | * Copyright (c) 2021 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __REPO_H__ |
18 | #define __REPO_H__ |
19 | |
20 | #include <time.h> |
21 | #include "bile.h" |
22 | |
23 | #define AMEND_CREATOR 'AMND' |
24 | |
25 | #define REPO_TYPE 'AMRP' |
26 | |
27 | #define REPO_FILE_RTYPE 'AFIL' |
28 | #define REPO_AMENDMENT_RTYPE 'CMMT' |
29 | #define REPO_DIFF_RTYPE 'DIFF' |
30 | #define REPO_TEXT_RTYPE 'TEXT' |
31 | #define REPO_VERS_RTYPE 'RVER' |
32 | |
33 | #define DIFF_FILE_TYPE 'TEXT' |
34 | |
35 | #define REPO_DIFF_TOO_BIG "\r[ Diff too large to view, %lu bytes not shown ]" |
36 | |
37 | #define REPO_CUR_VERS 3 |
38 | |
39 | struct repo_file { |
40 | short id; |
41 | char sort_filename[2]; |
42 | char filename[256]; |
43 | OSType type; |
44 | OSType creator; |
45 | unsigned long ctime; |
46 | unsigned long mtime; |
47 | unsigned char flags; |
48 | #define REPO_FILE_DELETED (1 << 0) |
49 | }; |
50 | |
51 | struct repo_file_attrs { |
52 | char type[4]; |
53 | char creator[4]; |
54 | unsigned long ctime; |
55 | unsigned long mtime; |
56 | }; |
57 | |
58 | struct diffed_file { |
59 | struct repo_file *file; |
60 | short flags; |
61 | #define DIFFED_FILE_TEXT (1 << 0) |
62 | #define DIFFED_FILE_METADATA (1 << 1) |
63 | }; |
64 | |
65 | struct repo_amendment { |
66 | short id; |
67 | time_t date; |
68 | char author[32]; |
69 | short nfiles; |
70 | short *file_ids; |
71 | short adds; |
72 | short subs; |
73 | short log_len; |
74 | Handle log; |
75 | }; |
76 | |
77 | struct repo { |
78 | struct bile *bile; |
79 | short nfiles; |
80 | struct repo_file **files; |
81 | short next_file_id; |
82 | short namendments; |
83 | struct repo_amendment **amendments; |
84 | short next_amendment_id; |
85 | bool unloaded_amendments; |
86 | }; |
87 | |
88 | struct repo *repo_open(AppFile *file); |
89 | struct repo *repo_create(void); |
90 | void repo_close(struct repo *repo); |
91 | void repo_load_amendments(struct repo *repo, bool fill_in); |
92 | struct repo_amendment *repo_parse_amendment(unsigned long id, unsigned char *data, |
93 | size_t size); |
94 | struct repo_file * repo_parse_file(unsigned long id, unsigned char *data, |
95 | size_t size); |
96 | struct repo_file *repo_file_with_id(struct repo *repo, short id); |
97 | void repo_show_diff_text(struct repo *repo, struct repo_amendment *amendment, |
98 | TEHandle te); |
99 | struct repo_file *repo_add_file(struct repo *repo); |
100 | void repo_file_mark_for_deletion(struct repo *repo, struct repo_file *file); |
101 | short repo_diff_file(struct repo *repo, struct repo_file *file); |
102 | short repo_file_changed(struct repo *repo, struct repo_file *file); |
103 | short repo_checkout_file(struct repo *repo, struct repo_file *file, |
104 | short vrefnum, Str255 filename); |
105 | void repo_export_amendment(struct repo *repo, |
106 | struct repo_amendment *amendment, short vrefnum, Str255 filename); |
107 | void repo_amend(struct repo *repo, struct diffed_file *diffed_files, |
108 | short nfiles, short adds, short subs, char *author, Handle log, |
109 | short loglen, Handle diff, unsigned long difflen); |
110 | void repo_marshall_amendment(struct repo_amendment *amendment, |
111 | char **retdata, unsigned long *retlen); |
112 | void repo_backup(struct repo *repo); |
113 | |
114 | #endif |