Blame


1 5c860e29 2018-03-12 stsp /*
2 f42b1b34 2018-03-12 stsp * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 f42b1b34 2018-03-12 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 5c860e29 2018-03-12 stsp *
5 5c860e29 2018-03-12 stsp * Permission to use, copy, modify, and distribute this software for any
6 5c860e29 2018-03-12 stsp * purpose with or without fee is hereby granted, provided that the above
7 5c860e29 2018-03-12 stsp * copyright notice and this permission notice appear in all copies.
8 5c860e29 2018-03-12 stsp *
9 5c860e29 2018-03-12 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 5c860e29 2018-03-12 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 5c860e29 2018-03-12 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 5c860e29 2018-03-12 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 5c860e29 2018-03-12 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 5c860e29 2018-03-12 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 5c860e29 2018-03-12 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 5c860e29 2018-03-12 stsp */
17 5c860e29 2018-03-12 stsp
18 f42b1b34 2018-03-12 stsp #include <sys/queue.h>
19 64a96a6d 2018-04-01 stsp #include <sys/limits.h>
20 c0768b0f 2018-06-10 stsp #include <sys/types.h>
21 5de5890b 2018-10-18 stsp #include <sys/stat.h>
22 f42b1b34 2018-03-12 stsp
23 5c860e29 2018-03-12 stsp #include <err.h>
24 5c860e29 2018-03-12 stsp #include <errno.h>
25 5c860e29 2018-03-12 stsp #include <locale.h>
26 99437157 2018-11-11 stsp #include <signal.h>
27 5c860e29 2018-03-12 stsp #include <stdio.h>
28 5c860e29 2018-03-12 stsp #include <stdlib.h>
29 5c860e29 2018-03-12 stsp #include <string.h>
30 5c860e29 2018-03-12 stsp #include <unistd.h>
31 c09a553d 2018-03-12 stsp #include <libgen.h>
32 c0768b0f 2018-06-10 stsp #include <time.h>
33 5c860e29 2018-03-12 stsp
34 f42b1b34 2018-03-12 stsp #include "got_error.h"
35 f42b1b34 2018-03-12 stsp #include "got_object.h"
36 5261c201 2018-04-01 stsp #include "got_reference.h"
37 f42b1b34 2018-03-12 stsp #include "got_repository.h"
38 c09a553d 2018-03-12 stsp #include "got_worktree.h"
39 79109fed 2018-03-27 stsp #include "got_diff.h"
40 372ccdbb 2018-06-10 stsp #include "got_commit_graph.h"
41 404c43c4 2018-06-21 stsp #include "got_blame.h"
42 5c860e29 2018-03-12 stsp
43 5c860e29 2018-03-12 stsp #ifndef nitems
44 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
45 5c860e29 2018-03-12 stsp #endif
46 99437157 2018-11-11 stsp
47 99437157 2018-11-11 stsp static volatile sig_atomic_t sigint_received;
48 99437157 2018-11-11 stsp static volatile sig_atomic_t sigpipe_received;
49 99437157 2018-11-11 stsp
50 99437157 2018-11-11 stsp static void
51 99437157 2018-11-11 stsp catch_sigint(int signo)
52 99437157 2018-11-11 stsp {
53 99437157 2018-11-11 stsp sigint_received = 1;
54 99437157 2018-11-11 stsp }
55 99437157 2018-11-11 stsp
56 99437157 2018-11-11 stsp static void
57 99437157 2018-11-11 stsp catch_sigpipe(int signo)
58 99437157 2018-11-11 stsp {
59 99437157 2018-11-11 stsp sigpipe_received = 1;
60 99437157 2018-11-11 stsp }
61 5c860e29 2018-03-12 stsp
62 99437157 2018-11-11 stsp
63 5c860e29 2018-03-12 stsp struct cmd {
64 5c860e29 2018-03-12 stsp const char *cmd_name;
65 d7d4f210 2018-03-12 stsp const struct got_error *(*cmd_main)(int, char *[]);
66 1b6b95a8 2018-03-12 stsp void (*cmd_usage)(void);
67 46a0db7d 2018-03-12 stsp const char *cmd_descr;
68 5c860e29 2018-03-12 stsp };
69 5c860e29 2018-03-12 stsp
70 4ed7e80c 2018-05-20 stsp __dead static void usage(void);
71 4ed7e80c 2018-05-20 stsp __dead static void usage_checkout(void);
72 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
73 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
74 404c43c4 2018-06-21 stsp __dead static void usage_blame(void);
75 5de5890b 2018-10-18 stsp __dead static void usage_tree(void);
76 5c860e29 2018-03-12 stsp
77 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_checkout(int, char *[]);
78 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
79 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
80 404c43c4 2018-06-21 stsp static const struct got_error* cmd_blame(int, char *[]);
81 5de5890b 2018-10-18 stsp static const struct got_error* cmd_tree(int, char *[]);
82 4ed7e80c 2018-05-20 stsp #ifdef notyet
83 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_status(int, char *[]);
84 4ed7e80c 2018-05-20 stsp #endif
85 5c860e29 2018-03-12 stsp
86 4ed7e80c 2018-05-20 stsp static struct cmd got_commands[] = {
87 c09a553d 2018-03-12 stsp { "checkout", cmd_checkout, usage_checkout,
88 0bb8a95e 2018-03-12 stsp "check out a new work tree from a repository" },
89 1b6b95a8 2018-03-12 stsp { "log", cmd_log, usage_log,
90 1b6b95a8 2018-03-12 stsp "show repository history" },
91 b00d56cd 2018-04-01 stsp { "diff", cmd_diff, usage_diff,
92 b00d56cd 2018-04-01 stsp "compare files and directories" },
93 404c43c4 2018-06-21 stsp { "blame", cmd_blame, usage_blame,
94 404c43c4 2018-06-21 stsp " show when lines in a file were changed" },
95 5de5890b 2018-10-18 stsp { "tree", cmd_tree, usage_tree,
96 5de5890b 2018-10-18 stsp " list files and directories in repository" },
97 f42b1b34 2018-03-12 stsp #ifdef notyet
98 1b6b95a8 2018-03-12 stsp { "status", cmd_status, usage_status,
99 1b6b95a8 2018-03-12 stsp "show modification status of files" },
100 f42b1b34 2018-03-12 stsp #endif
101 5c860e29 2018-03-12 stsp };
102 5c860e29 2018-03-12 stsp
103 5c860e29 2018-03-12 stsp int
104 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
105 5c860e29 2018-03-12 stsp {
106 5c860e29 2018-03-12 stsp struct cmd *cmd;
107 5c860e29 2018-03-12 stsp unsigned int i;
108 5c860e29 2018-03-12 stsp int ch;
109 1b6b95a8 2018-03-12 stsp int hflag = 0;
110 5c860e29 2018-03-12 stsp
111 5c860e29 2018-03-12 stsp setlocale(LC_ALL, "");
112 5c860e29 2018-03-12 stsp
113 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
114 5c860e29 2018-03-12 stsp switch (ch) {
115 1b6b95a8 2018-03-12 stsp case 'h':
116 1b6b95a8 2018-03-12 stsp hflag = 1;
117 1b6b95a8 2018-03-12 stsp break;
118 5c860e29 2018-03-12 stsp default:
119 5c860e29 2018-03-12 stsp usage();
120 5c860e29 2018-03-12 stsp /* NOTREACHED */
121 5c860e29 2018-03-12 stsp }
122 5c860e29 2018-03-12 stsp }
123 5c860e29 2018-03-12 stsp
124 5c860e29 2018-03-12 stsp argc -= optind;
125 5c860e29 2018-03-12 stsp argv += optind;
126 1e70621d 2018-03-27 stsp optind = 0;
127 5c860e29 2018-03-12 stsp
128 5c860e29 2018-03-12 stsp if (argc <= 0)
129 5c860e29 2018-03-12 stsp usage();
130 5c860e29 2018-03-12 stsp
131 99437157 2018-11-11 stsp signal(SIGINT, catch_sigint);
132 99437157 2018-11-11 stsp signal(SIGPIPE, catch_sigpipe);
133 99437157 2018-11-11 stsp
134 5c860e29 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
135 d7d4f210 2018-03-12 stsp const struct got_error *error;
136 d7d4f210 2018-03-12 stsp
137 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
138 5c860e29 2018-03-12 stsp
139 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
140 5c860e29 2018-03-12 stsp continue;
141 5c860e29 2018-03-12 stsp
142 1b6b95a8 2018-03-12 stsp if (hflag)
143 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
144 1b6b95a8 2018-03-12 stsp
145 d7d4f210 2018-03-12 stsp error = got_commands[i].cmd_main(argc, argv);
146 80d5f134 2018-11-11 stsp if (error && !(sigint_received || sigpipe_received)) {
147 d7d4f210 2018-03-12 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
148 d7d4f210 2018-03-12 stsp return 1;
149 d7d4f210 2018-03-12 stsp }
150 d7d4f210 2018-03-12 stsp
151 d7d4f210 2018-03-12 stsp return 0;
152 5c860e29 2018-03-12 stsp }
153 5c860e29 2018-03-12 stsp
154 20ecf764 2018-03-12 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
155 5c860e29 2018-03-12 stsp return 1;
156 5c860e29 2018-03-12 stsp }
157 5c860e29 2018-03-12 stsp
158 4ed7e80c 2018-05-20 stsp __dead static void
159 5c860e29 2018-03-12 stsp usage(void)
160 5c860e29 2018-03-12 stsp {
161 46a0db7d 2018-03-12 stsp int i;
162 46a0db7d 2018-03-12 stsp
163 987e94ba 2018-03-12 stsp fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
164 987e94ba 2018-03-12 stsp "Available commands:\n", getprogname());
165 46a0db7d 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
166 46a0db7d 2018-03-12 stsp struct cmd *cmd = &got_commands[i];
167 46a0db7d 2018-03-12 stsp fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
168 46a0db7d 2018-03-12 stsp }
169 5c860e29 2018-03-12 stsp exit(1);
170 5c860e29 2018-03-12 stsp }
171 5c860e29 2018-03-12 stsp
172 4ed7e80c 2018-05-20 stsp __dead static void
173 c09a553d 2018-03-12 stsp usage_checkout(void)
174 c09a553d 2018-03-12 stsp {
175 0bb8a95e 2018-03-12 stsp fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
176 0bb8a95e 2018-03-12 stsp "[worktree-path]\n", getprogname());
177 c09a553d 2018-03-12 stsp exit(1);
178 92a684f4 2018-03-12 stsp }
179 92a684f4 2018-03-12 stsp
180 92a684f4 2018-03-12 stsp static void
181 92a684f4 2018-03-12 stsp checkout_progress(void *arg, const char *path)
182 92a684f4 2018-03-12 stsp {
183 92a684f4 2018-03-12 stsp char *worktree_path = arg;
184 92a684f4 2018-03-12 stsp
185 92a684f4 2018-03-12 stsp while (path[0] == '/')
186 92a684f4 2018-03-12 stsp path++;
187 92a684f4 2018-03-12 stsp
188 92a684f4 2018-03-12 stsp printf("A %s/%s\n", worktree_path, path);
189 99437157 2018-11-11 stsp }
190 99437157 2018-11-11 stsp
191 99437157 2018-11-11 stsp static const struct got_error *
192 99437157 2018-11-11 stsp checkout_cancel(void *arg)
193 99437157 2018-11-11 stsp {
194 99437157 2018-11-11 stsp if (sigint_received || sigpipe_received)
195 99437157 2018-11-11 stsp return got_error(GOT_ERR_CANCELLED);
196 99437157 2018-11-11 stsp return NULL;
197 c09a553d 2018-03-12 stsp }
198 c09a553d 2018-03-12 stsp
199 4ed7e80c 2018-05-20 stsp static const struct got_error *
200 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
201 c09a553d 2018-03-12 stsp {
202 c09a553d 2018-03-12 stsp const struct got_error *error = NULL;
203 c09a553d 2018-03-12 stsp struct got_repository *repo = NULL;
204 c09a553d 2018-03-12 stsp struct got_reference *head_ref = NULL;
205 c09a553d 2018-03-12 stsp struct got_worktree *worktree = NULL;
206 c09a553d 2018-03-12 stsp char *repo_path = NULL;
207 c09a553d 2018-03-12 stsp char *worktree_path = NULL;
208 0bb8a95e 2018-03-12 stsp const char *path_prefix = "";
209 0bb8a95e 2018-03-12 stsp int ch;
210 c09a553d 2018-03-12 stsp
211 0bb8a95e 2018-03-12 stsp while ((ch = getopt(argc, argv, "p:")) != -1) {
212 0bb8a95e 2018-03-12 stsp switch (ch) {
213 0bb8a95e 2018-03-12 stsp case 'p':
214 0bb8a95e 2018-03-12 stsp path_prefix = optarg;
215 0bb8a95e 2018-03-12 stsp break;
216 0bb8a95e 2018-03-12 stsp default:
217 0bb8a95e 2018-03-12 stsp usage();
218 0bb8a95e 2018-03-12 stsp /* NOTREACHED */
219 0bb8a95e 2018-03-12 stsp }
220 0bb8a95e 2018-03-12 stsp }
221 0bb8a95e 2018-03-12 stsp
222 0bb8a95e 2018-03-12 stsp argc -= optind;
223 0bb8a95e 2018-03-12 stsp argv += optind;
224 0bb8a95e 2018-03-12 stsp
225 6715a751 2018-03-16 stsp #ifndef PROFILE
226 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
227 ad242220 2018-09-08 stsp == -1)
228 c09a553d 2018-03-12 stsp err(1, "pledge");
229 6715a751 2018-03-16 stsp #endif
230 0bb8a95e 2018-03-12 stsp if (argc == 1) {
231 c09a553d 2018-03-12 stsp char *cwd, *base, *dotgit;
232 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
233 76089277 2018-04-01 stsp if (repo_path == NULL)
234 76089277 2018-04-01 stsp return got_error_from_errno();
235 c09a553d 2018-03-12 stsp cwd = getcwd(NULL, 0);
236 76089277 2018-04-01 stsp if (cwd == NULL) {
237 76089277 2018-04-01 stsp error = got_error_from_errno();
238 76089277 2018-04-01 stsp goto done;
239 76089277 2018-04-01 stsp }
240 5d7c1dab 2018-04-01 stsp if (path_prefix[0])
241 5d7c1dab 2018-04-01 stsp base = basename(path_prefix);
242 5d7c1dab 2018-04-01 stsp else
243 5d7c1dab 2018-04-01 stsp base = basename(repo_path);
244 76089277 2018-04-01 stsp if (base == NULL) {
245 76089277 2018-04-01 stsp error = got_error_from_errno();
246 76089277 2018-04-01 stsp goto done;
247 76089277 2018-04-01 stsp }
248 c09a553d 2018-03-12 stsp dotgit = strstr(base, ".git");
249 c09a553d 2018-03-12 stsp if (dotgit)
250 c09a553d 2018-03-12 stsp *dotgit = '\0';
251 c09a553d 2018-03-12 stsp if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
252 0a585a0d 2018-03-17 stsp error = got_error_from_errno();
253 c09a553d 2018-03-12 stsp free(cwd);
254 76089277 2018-04-01 stsp goto done;
255 c09a553d 2018-03-12 stsp }
256 c09a553d 2018-03-12 stsp free(cwd);
257 0bb8a95e 2018-03-12 stsp } else if (argc == 2) {
258 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
259 76089277 2018-04-01 stsp if (repo_path == NULL) {
260 76089277 2018-04-01 stsp error = got_error_from_errno();
261 76089277 2018-04-01 stsp goto done;
262 76089277 2018-04-01 stsp }
263 f7b38925 2018-04-01 stsp worktree_path = realpath(argv[1], NULL);
264 76089277 2018-04-01 stsp if (worktree_path == NULL) {
265 76089277 2018-04-01 stsp error = got_error_from_errno();
266 76089277 2018-04-01 stsp goto done;
267 76089277 2018-04-01 stsp }
268 c09a553d 2018-03-12 stsp } else
269 c09a553d 2018-03-12 stsp usage_checkout();
270 c09a553d 2018-03-12 stsp
271 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
272 c09a553d 2018-03-12 stsp if (error != NULL)
273 c09a553d 2018-03-12 stsp goto done;
274 c09a553d 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
275 c09a553d 2018-03-12 stsp if (error != NULL)
276 c09a553d 2018-03-12 stsp goto done;
277 c09a553d 2018-03-12 stsp
278 0bb8a95e 2018-03-12 stsp error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
279 c09a553d 2018-03-12 stsp if (error != NULL)
280 c09a553d 2018-03-12 stsp goto done;
281 c09a553d 2018-03-12 stsp
282 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
283 c09a553d 2018-03-12 stsp if (error != NULL)
284 c09a553d 2018-03-12 stsp goto done;
285 c09a553d 2018-03-12 stsp
286 92a684f4 2018-03-12 stsp error = got_worktree_checkout_files(worktree, head_ref, repo,
287 99437157 2018-11-11 stsp checkout_progress, worktree_path, checkout_cancel, NULL);
288 c09a553d 2018-03-12 stsp if (error != NULL)
289 c09a553d 2018-03-12 stsp goto done;
290 c09a553d 2018-03-12 stsp
291 b65ae19a 2018-04-24 stsp printf("Now shut up and hack\n");
292 c09a553d 2018-03-12 stsp
293 c09a553d 2018-03-12 stsp done:
294 76089277 2018-04-01 stsp free(repo_path);
295 c09a553d 2018-03-12 stsp free(worktree_path);
296 c09a553d 2018-03-12 stsp return error;
297 c09a553d 2018-03-12 stsp }
298 c09a553d 2018-03-12 stsp
299 f42b1b34 2018-03-12 stsp static const struct got_error *
300 79109fed 2018-03-27 stsp print_patch(struct got_commit_object *commit, struct got_object_id *id,
301 c0cc5c62 2018-10-18 stsp int diff_context, struct got_repository *repo)
302 5c860e29 2018-03-12 stsp {
303 f42b1b34 2018-03-12 stsp const struct got_error *err = NULL;
304 79109fed 2018-03-27 stsp struct got_tree_object *tree1 = NULL, *tree2;
305 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
306 0f2b3dca 2018-12-22 stsp char *id_str1 = NULL, *id_str2;
307 79109fed 2018-03-27 stsp
308 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree2, repo, commit->tree_id);
309 79109fed 2018-03-27 stsp if (err)
310 79109fed 2018-03-27 stsp return err;
311 79109fed 2018-03-27 stsp
312 79f35eb3 2018-06-11 stsp qid = SIMPLEQ_FIRST(&commit->parent_ids);
313 79f35eb3 2018-06-11 stsp if (qid != NULL) {
314 79109fed 2018-03-27 stsp struct got_commit_object *pcommit;
315 79109fed 2018-03-27 stsp
316 117e771c 2018-07-23 stsp err = got_object_open_as_commit(&pcommit, repo, qid->id);
317 79109fed 2018-03-27 stsp if (err)
318 79109fed 2018-03-27 stsp return err;
319 79109fed 2018-03-27 stsp
320 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree1, repo, pcommit->tree_id);
321 79109fed 2018-03-27 stsp got_object_commit_close(pcommit);
322 0f2b3dca 2018-12-22 stsp if (err)
323 0f2b3dca 2018-12-22 stsp return err;
324 0f2b3dca 2018-12-22 stsp
325 0f2b3dca 2018-12-22 stsp err = got_object_id_str(&id_str1, qid->id);
326 79109fed 2018-03-27 stsp if (err)
327 79109fed 2018-03-27 stsp return err;
328 79109fed 2018-03-27 stsp }
329 79109fed 2018-03-27 stsp
330 0f2b3dca 2018-12-22 stsp err = got_object_id_str(&id_str2, id);
331 0f2b3dca 2018-12-22 stsp if (err)
332 0f2b3dca 2018-12-22 stsp goto done;
333 0f2b3dca 2018-12-22 stsp
334 0f2b3dca 2018-12-22 stsp printf("diff: %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
335 c0cc5c62 2018-10-18 stsp err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
336 0f2b3dca 2018-12-22 stsp done:
337 79109fed 2018-03-27 stsp if (tree1)
338 79109fed 2018-03-27 stsp got_object_tree_close(tree1);
339 79109fed 2018-03-27 stsp got_object_tree_close(tree2);
340 0f2b3dca 2018-12-22 stsp free(id_str1);
341 0f2b3dca 2018-12-22 stsp free(id_str2);
342 79109fed 2018-03-27 stsp return err;
343 79109fed 2018-03-27 stsp }
344 79109fed 2018-03-27 stsp
345 4bb494d5 2018-06-16 stsp static char *
346 6c281f94 2018-06-11 stsp get_datestr(time_t *time, char *datebuf)
347 6c281f94 2018-06-11 stsp {
348 6c281f94 2018-06-11 stsp char *p, *s = ctime_r(time, datebuf);
349 6c281f94 2018-06-11 stsp p = strchr(s, '\n');
350 6c281f94 2018-06-11 stsp if (p)
351 6c281f94 2018-06-11 stsp *p = '\0';
352 6c281f94 2018-06-11 stsp return s;
353 6c281f94 2018-06-11 stsp }
354 6c281f94 2018-06-11 stsp
355 79109fed 2018-03-27 stsp static const struct got_error *
356 79109fed 2018-03-27 stsp print_commit(struct got_commit_object *commit, struct got_object_id *id,
357 c0cc5c62 2018-10-18 stsp struct got_repository *repo, int show_patch, int diff_context)
358 79109fed 2018-03-27 stsp {
359 79109fed 2018-03-27 stsp const struct got_error *err = NULL;
360 621015ac 2018-07-23 stsp char *id_str, *datestr, *logmsg0, *logmsg, *line;
361 6c281f94 2018-06-11 stsp char datebuf[26];
362 5c860e29 2018-03-12 stsp
363 832c249c 2018-06-10 stsp err = got_object_id_str(&id_str, id);
364 8bf5b3c9 2018-03-17 stsp if (err)
365 8bf5b3c9 2018-03-17 stsp return err;
366 788c352e 2018-06-16 stsp
367 33d869be 2018-12-22 stsp printf("-----------------------------------------------\n");
368 832c249c 2018-06-10 stsp printf("commit %s\n", id_str);
369 832c249c 2018-06-10 stsp free(id_str);
370 0dcf3e9c 2018-09-15 stsp printf("from: %s\n", commit->author);
371 ccb26ccd 2018-11-05 stsp datestr = get_datestr(&commit->committer_time, datebuf);
372 dab5fe87 2018-09-14 stsp printf("date: %s UTC\n", datestr);
373 dab5fe87 2018-09-14 stsp if (strcmp(commit->author, commit->committer) != 0)
374 0dcf3e9c 2018-09-15 stsp printf("via: %s\n", commit->committer);
375 3fe1abad 2018-06-10 stsp if (commit->nparents > 1) {
376 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
377 3fe1abad 2018-06-10 stsp int n = 1;
378 79f35eb3 2018-06-11 stsp SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
379 79f35eb3 2018-06-11 stsp err = got_object_id_str(&id_str, qid->id);
380 a0603db2 2018-06-10 stsp if (err)
381 a0603db2 2018-06-10 stsp return err;
382 3fe1abad 2018-06-10 stsp printf("parent %d: %s\n", n++, id_str);
383 a0603db2 2018-06-10 stsp free(id_str);
384 a0603db2 2018-06-10 stsp }
385 a0603db2 2018-06-10 stsp }
386 832c249c 2018-06-10 stsp
387 621015ac 2018-07-23 stsp logmsg0 = strdup(commit->logmsg);
388 621015ac 2018-07-23 stsp if (logmsg0 == NULL)
389 832c249c 2018-06-10 stsp return got_error_from_errno();
390 8bf5b3c9 2018-03-17 stsp
391 621015ac 2018-07-23 stsp logmsg = logmsg0;
392 832c249c 2018-06-10 stsp do {
393 832c249c 2018-06-10 stsp line = strsep(&logmsg, "\n");
394 832c249c 2018-06-10 stsp if (line)
395 832c249c 2018-06-10 stsp printf(" %s\n", line);
396 832c249c 2018-06-10 stsp } while (line);
397 621015ac 2018-07-23 stsp free(logmsg0);
398 832c249c 2018-06-10 stsp
399 971751ac 2018-03-27 stsp if (show_patch) {
400 c0cc5c62 2018-10-18 stsp err = print_patch(commit, id, diff_context, repo);
401 971751ac 2018-03-27 stsp if (err == 0)
402 971751ac 2018-03-27 stsp printf("\n");
403 971751ac 2018-03-27 stsp }
404 07862c20 2018-09-15 stsp
405 d82de447 2018-09-15 stsp fflush(stdout);
406 07862c20 2018-09-15 stsp return err;
407 f42b1b34 2018-03-12 stsp }
408 5c860e29 2018-03-12 stsp
409 f42b1b34 2018-03-12 stsp static const struct got_error *
410 8bf5b3c9 2018-03-17 stsp print_commits(struct got_object *root_obj, struct got_object_id *root_id,
411 c0cc5c62 2018-10-18 stsp struct got_repository *repo, char *path, int show_patch, int diff_context,
412 c0cc5c62 2018-10-18 stsp int limit, int first_parent_traversal)
413 f42b1b34 2018-03-12 stsp {
414 f42b1b34 2018-03-12 stsp const struct got_error *err;
415 372ccdbb 2018-06-10 stsp struct got_commit_graph *graph;
416 372ccdbb 2018-06-10 stsp
417 31cedeaf 2018-09-15 stsp err = got_commit_graph_open(&graph, root_id, path,
418 31cedeaf 2018-09-15 stsp first_parent_traversal, repo);
419 f42b1b34 2018-03-12 stsp if (err)
420 f42b1b34 2018-03-12 stsp return err;
421 31cedeaf 2018-09-15 stsp err = got_commit_graph_iter_start(graph, root_id, repo);
422 372ccdbb 2018-06-10 stsp if (err)
423 fcc85cad 2018-07-22 stsp goto done;
424 31cedeaf 2018-09-15 stsp while (1) {
425 372ccdbb 2018-06-10 stsp struct got_commit_object *commit;
426 372ccdbb 2018-06-10 stsp struct got_object_id *id;
427 8bf5b3c9 2018-03-17 stsp
428 84453469 2018-11-11 stsp if (sigint_received || sigpipe_received)
429 84453469 2018-11-11 stsp break;
430 84453469 2018-11-11 stsp
431 b43fbaa0 2018-06-11 stsp err = got_commit_graph_iter_next(&id, graph);
432 372ccdbb 2018-06-10 stsp if (err) {
433 9ba79e04 2018-06-11 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
434 9ba79e04 2018-06-11 stsp err = NULL;
435 9ba79e04 2018-06-11 stsp break;
436 9ba79e04 2018-06-11 stsp }
437 372ccdbb 2018-06-10 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
438 372ccdbb 2018-06-10 stsp break;
439 31cedeaf 2018-09-15 stsp err = got_commit_graph_fetch_commits(graph, 1, repo);
440 372ccdbb 2018-06-10 stsp if (err)
441 372ccdbb 2018-06-10 stsp break;
442 372ccdbb 2018-06-10 stsp else
443 372ccdbb 2018-06-10 stsp continue;
444 7e665116 2018-04-02 stsp }
445 b43fbaa0 2018-06-11 stsp if (id == NULL)
446 7e665116 2018-04-02 stsp break;
447 b43fbaa0 2018-06-11 stsp
448 f8e900f3 2018-06-11 stsp err = got_object_open_as_commit(&commit, repo, id);
449 b43fbaa0 2018-06-11 stsp if (err)
450 fcc85cad 2018-07-22 stsp break;
451 c0cc5c62 2018-10-18 stsp err = print_commit(commit, id, repo, show_patch, diff_context);
452 b43fbaa0 2018-06-11 stsp got_object_commit_close(commit);
453 372ccdbb 2018-06-10 stsp if (err || (limit && --limit == 0))
454 7e665116 2018-04-02 stsp break;
455 31cedeaf 2018-09-15 stsp }
456 fcc85cad 2018-07-22 stsp done:
457 372ccdbb 2018-06-10 stsp got_commit_graph_close(graph);
458 f42b1b34 2018-03-12 stsp return err;
459 f42b1b34 2018-03-12 stsp }
460 5c860e29 2018-03-12 stsp
461 4ed7e80c 2018-05-20 stsp __dead static void
462 6f3d1eb0 2018-03-12 stsp usage_log(void)
463 6f3d1eb0 2018-03-12 stsp {
464 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
465 04ca23f4 2018-07-16 stsp "[-r repository-path] [path]\n", getprogname());
466 6f3d1eb0 2018-03-12 stsp exit(1);
467 6f3d1eb0 2018-03-12 stsp }
468 6f3d1eb0 2018-03-12 stsp
469 4ed7e80c 2018-05-20 stsp static const struct got_error *
470 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
471 f42b1b34 2018-03-12 stsp {
472 f42b1b34 2018-03-12 stsp const struct got_error *error;
473 04ca23f4 2018-07-16 stsp struct got_repository *repo = NULL;
474 3235492e 2018-04-01 stsp struct got_object_id *id = NULL;
475 d1f2edc9 2018-06-13 stsp struct got_object *obj = NULL;
476 04ca23f4 2018-07-16 stsp char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
477 d142fc45 2018-04-01 stsp char *start_commit = NULL;
478 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
479 1fd6d7ea 2018-06-13 stsp int show_patch = 0, limit = 0, first_parent_traversal = 0;
480 64a96a6d 2018-04-01 stsp const char *errstr;
481 5c860e29 2018-03-12 stsp
482 6715a751 2018-03-16 stsp #ifndef PROFILE
483 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
484 ad242220 2018-09-08 stsp == -1)
485 f42b1b34 2018-03-12 stsp err(1, "pledge");
486 6715a751 2018-03-16 stsp #endif
487 79109fed 2018-03-27 stsp
488 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
489 79109fed 2018-03-27 stsp switch (ch) {
490 79109fed 2018-03-27 stsp case 'p':
491 79109fed 2018-03-27 stsp show_patch = 1;
492 d142fc45 2018-04-01 stsp break;
493 d142fc45 2018-04-01 stsp case 'c':
494 d142fc45 2018-04-01 stsp start_commit = optarg;
495 64a96a6d 2018-04-01 stsp break;
496 c0cc5c62 2018-10-18 stsp case 'C':
497 4a8520aa 2018-10-18 stsp diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
498 4a8520aa 2018-10-18 stsp &errstr);
499 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
500 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
501 c0cc5c62 2018-10-18 stsp break;
502 64a96a6d 2018-04-01 stsp case 'l':
503 64a96a6d 2018-04-01 stsp limit = strtonum(optarg, 1, INT_MAX, &errstr);
504 64a96a6d 2018-04-01 stsp if (errstr != NULL)
505 64a96a6d 2018-04-01 stsp err(1, "-l option %s", errstr);
506 79109fed 2018-03-27 stsp break;
507 0ed6ed4c 2018-06-13 stsp case 'f':
508 0ed6ed4c 2018-06-13 stsp first_parent_traversal = 1;
509 a0603db2 2018-06-10 stsp break;
510 04ca23f4 2018-07-16 stsp case 'r':
511 04ca23f4 2018-07-16 stsp repo_path = realpath(optarg, NULL);
512 04ca23f4 2018-07-16 stsp if (repo_path == NULL)
513 04ca23f4 2018-07-16 stsp err(1, "-r option");
514 04ca23f4 2018-07-16 stsp break;
515 79109fed 2018-03-27 stsp default:
516 79109fed 2018-03-27 stsp usage();
517 79109fed 2018-03-27 stsp /* NOTREACHED */
518 79109fed 2018-03-27 stsp }
519 79109fed 2018-03-27 stsp }
520 79109fed 2018-03-27 stsp
521 79109fed 2018-03-27 stsp argc -= optind;
522 79109fed 2018-03-27 stsp argv += optind;
523 79109fed 2018-03-27 stsp
524 04ca23f4 2018-07-16 stsp if (argc == 0)
525 04ca23f4 2018-07-16 stsp path = strdup("");
526 04ca23f4 2018-07-16 stsp else if (argc == 1)
527 04ca23f4 2018-07-16 stsp path = strdup(argv[0]);
528 04ca23f4 2018-07-16 stsp else
529 6f3d1eb0 2018-03-12 stsp usage_log();
530 04ca23f4 2018-07-16 stsp if (path == NULL)
531 04ca23f4 2018-07-16 stsp return got_error_from_errno();
532 f42b1b34 2018-03-12 stsp
533 04ca23f4 2018-07-16 stsp cwd = getcwd(NULL, 0);
534 04ca23f4 2018-07-16 stsp if (cwd == NULL) {
535 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
536 04ca23f4 2018-07-16 stsp goto done;
537 04ca23f4 2018-07-16 stsp }
538 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
539 04ca23f4 2018-07-16 stsp repo_path = strdup(cwd);
540 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
541 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
542 04ca23f4 2018-07-16 stsp goto done;
543 04ca23f4 2018-07-16 stsp }
544 04ca23f4 2018-07-16 stsp }
545 04ca23f4 2018-07-16 stsp
546 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
547 d7d4f210 2018-03-12 stsp if (error != NULL)
548 04ca23f4 2018-07-16 stsp goto done;
549 f42b1b34 2018-03-12 stsp
550 d142fc45 2018-04-01 stsp if (start_commit == NULL) {
551 3235492e 2018-04-01 stsp struct got_reference *head_ref;
552 3235492e 2018-04-01 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
553 3235492e 2018-04-01 stsp if (error != NULL)
554 3235492e 2018-04-01 stsp return error;
555 3235492e 2018-04-01 stsp error = got_ref_resolve(&id, repo, head_ref);
556 3235492e 2018-04-01 stsp got_ref_close(head_ref);
557 3235492e 2018-04-01 stsp if (error != NULL)
558 3235492e 2018-04-01 stsp return error;
559 3235492e 2018-04-01 stsp error = got_object_open(&obj, repo, id);
560 3235492e 2018-04-01 stsp } else {
561 d1f2edc9 2018-06-13 stsp struct got_reference *ref;
562 d1f2edc9 2018-06-13 stsp error = got_ref_open(&ref, repo, start_commit);
563 3235492e 2018-04-01 stsp if (error == NULL) {
564 d1f2edc9 2018-06-13 stsp error = got_ref_resolve(&id, repo, ref);
565 d1f2edc9 2018-06-13 stsp got_ref_close(ref);
566 d1f2edc9 2018-06-13 stsp if (error != NULL)
567 d1f2edc9 2018-06-13 stsp return error;
568 d1f2edc9 2018-06-13 stsp error = got_object_open(&obj, repo, id);
569 d1f2edc9 2018-06-13 stsp if (error != NULL)
570 d1f2edc9 2018-06-13 stsp return error;
571 d1f2edc9 2018-06-13 stsp }
572 d1f2edc9 2018-06-13 stsp if (obj == NULL) {
573 d1f2edc9 2018-06-13 stsp error = got_object_open_by_id_str(&obj, repo,
574 d1f2edc9 2018-06-13 stsp start_commit);
575 d1f2edc9 2018-06-13 stsp if (error != NULL)
576 d1f2edc9 2018-06-13 stsp return error;
577 6402fb3c 2018-09-15 stsp id = got_object_id_dup(got_object_get_id(obj));
578 3235492e 2018-04-01 stsp if (id == NULL)
579 3235492e 2018-04-01 stsp error = got_error_from_errno();
580 3235492e 2018-04-01 stsp }
581 3235492e 2018-04-01 stsp }
582 d7d4f210 2018-03-12 stsp if (error != NULL)
583 04ca23f4 2018-07-16 stsp goto done;
584 04ca23f4 2018-07-16 stsp if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
585 8bf5b3c9 2018-03-17 stsp error = got_error(GOT_ERR_OBJ_TYPE);
586 04ca23f4 2018-07-16 stsp goto done;
587 04ca23f4 2018-07-16 stsp }
588 04ca23f4 2018-07-16 stsp
589 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
590 04ca23f4 2018-07-16 stsp if (error != NULL)
591 04ca23f4 2018-07-16 stsp goto done;
592 04ca23f4 2018-07-16 stsp if (in_repo_path) {
593 04ca23f4 2018-07-16 stsp free(path);
594 04ca23f4 2018-07-16 stsp path = in_repo_path;
595 04ca23f4 2018-07-16 stsp }
596 04ca23f4 2018-07-16 stsp
597 04ca23f4 2018-07-16 stsp error = print_commits(obj, id, repo, path, show_patch,
598 c0cc5c62 2018-10-18 stsp diff_context, limit, first_parent_traversal);
599 04ca23f4 2018-07-16 stsp done:
600 04ca23f4 2018-07-16 stsp free(path);
601 04ca23f4 2018-07-16 stsp free(repo_path);
602 04ca23f4 2018-07-16 stsp free(cwd);
603 04ca23f4 2018-07-16 stsp if (obj)
604 04ca23f4 2018-07-16 stsp got_object_close(obj);
605 f42b1b34 2018-03-12 stsp free(id);
606 ad242220 2018-09-08 stsp if (repo) {
607 ad242220 2018-09-08 stsp const struct got_error *repo_error;
608 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
609 ad242220 2018-09-08 stsp if (error == NULL)
610 ad242220 2018-09-08 stsp error = repo_error;
611 ad242220 2018-09-08 stsp }
612 8bf5b3c9 2018-03-17 stsp return error;
613 5c860e29 2018-03-12 stsp }
614 5c860e29 2018-03-12 stsp
615 4ed7e80c 2018-05-20 stsp __dead static void
616 3f8b7d6a 2018-04-01 stsp usage_diff(void)
617 3f8b7d6a 2018-04-01 stsp {
618 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
619 c0cc5c62 2018-10-18 stsp "object1 object2\n", getprogname());
620 3f8b7d6a 2018-04-01 stsp exit(1);
621 b00d56cd 2018-04-01 stsp }
622 b00d56cd 2018-04-01 stsp
623 4ed7e80c 2018-05-20 stsp static const struct got_error *
624 b00d56cd 2018-04-01 stsp cmd_diff(int argc, char *argv[])
625 b00d56cd 2018-04-01 stsp {
626 b00d56cd 2018-04-01 stsp const struct got_error *error;
627 b00d56cd 2018-04-01 stsp struct got_repository *repo = NULL;
628 b00d56cd 2018-04-01 stsp struct got_object *obj1 = NULL, *obj2 = NULL;
629 b00d56cd 2018-04-01 stsp char *repo_path = NULL;
630 b00d56cd 2018-04-01 stsp char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
631 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
632 c0cc5c62 2018-10-18 stsp const char *errstr;
633 b00d56cd 2018-04-01 stsp
634 b00d56cd 2018-04-01 stsp #ifndef PROFILE
635 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
636 ad242220 2018-09-08 stsp == -1)
637 b00d56cd 2018-04-01 stsp err(1, "pledge");
638 b00d56cd 2018-04-01 stsp #endif
639 b00d56cd 2018-04-01 stsp
640 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "C:")) != -1) {
641 b00d56cd 2018-04-01 stsp switch (ch) {
642 c0cc5c62 2018-10-18 stsp case 'C':
643 c0cc5c62 2018-10-18 stsp diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
644 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
645 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
646 c0cc5c62 2018-10-18 stsp break;
647 b00d56cd 2018-04-01 stsp default:
648 b00d56cd 2018-04-01 stsp usage();
649 b00d56cd 2018-04-01 stsp /* NOTREACHED */
650 b00d56cd 2018-04-01 stsp }
651 b00d56cd 2018-04-01 stsp }
652 b00d56cd 2018-04-01 stsp
653 b00d56cd 2018-04-01 stsp argc -= optind;
654 b00d56cd 2018-04-01 stsp argv += optind;
655 b00d56cd 2018-04-01 stsp
656 b00d56cd 2018-04-01 stsp if (argc == 0) {
657 b00d56cd 2018-04-01 stsp usage_diff(); /* TODO show local worktree changes */
658 3f8b7d6a 2018-04-01 stsp } else if (argc == 2) {
659 3f8b7d6a 2018-04-01 stsp repo_path = getcwd(NULL, 0);
660 3f8b7d6a 2018-04-01 stsp if (repo_path == NULL)
661 e1e3f570 2018-04-01 stsp return got_error_from_errno();
662 3f8b7d6a 2018-04-01 stsp obj_id_str1 = argv[0];
663 3f8b7d6a 2018-04-01 stsp obj_id_str2 = argv[1];
664 b00d56cd 2018-04-01 stsp } else if (argc == 3) {
665 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
666 76089277 2018-04-01 stsp if (repo_path == NULL)
667 76089277 2018-04-01 stsp return got_error_from_errno();
668 b00d56cd 2018-04-01 stsp obj_id_str1 = argv[1];
669 b00d56cd 2018-04-01 stsp obj_id_str2 = argv[2];
670 b00d56cd 2018-04-01 stsp } else
671 b00d56cd 2018-04-01 stsp usage_diff();
672 b00d56cd 2018-04-01 stsp
673 b00d56cd 2018-04-01 stsp error = got_repo_open(&repo, repo_path);
674 76089277 2018-04-01 stsp free(repo_path);
675 b00d56cd 2018-04-01 stsp if (error != NULL)
676 b00d56cd 2018-04-01 stsp goto done;
677 b00d56cd 2018-04-01 stsp
678 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
679 6402fb3c 2018-09-15 stsp if (error)
680 b00d56cd 2018-04-01 stsp goto done;
681 b00d56cd 2018-04-01 stsp
682 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
683 6402fb3c 2018-09-15 stsp if (error)
684 b00d56cd 2018-04-01 stsp goto done;
685 b00d56cd 2018-04-01 stsp
686 b00d56cd 2018-04-01 stsp if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
687 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
688 b00d56cd 2018-04-01 stsp goto done;
689 b00d56cd 2018-04-01 stsp }
690 b00d56cd 2018-04-01 stsp
691 b00d56cd 2018-04-01 stsp switch (got_object_get_type(obj1)) {
692 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_BLOB:
693 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_blobs(obj1, obj2, NULL, NULL,
694 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
695 b00d56cd 2018-04-01 stsp break;
696 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_TREE:
697 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_trees(obj1, obj2, "", "",
698 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
699 b00d56cd 2018-04-01 stsp break;
700 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_COMMIT:
701 a9a46275 2018-12-22 stsp printf("diff: %s %s\n", obj_id_str1 ? obj_id_str1 : "/dev/null",
702 a9a46275 2018-12-22 stsp obj_id_str2);
703 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_commits(obj1, obj2, diff_context,
704 c0cc5c62 2018-10-18 stsp repo, stdout);
705 b00d56cd 2018-04-01 stsp break;
706 b00d56cd 2018-04-01 stsp default:
707 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
708 b00d56cd 2018-04-01 stsp }
709 b00d56cd 2018-04-01 stsp
710 b00d56cd 2018-04-01 stsp done:
711 b00d56cd 2018-04-01 stsp if (obj1)
712 b00d56cd 2018-04-01 stsp got_object_close(obj1);
713 b00d56cd 2018-04-01 stsp if (obj2)
714 b00d56cd 2018-04-01 stsp got_object_close(obj2);
715 ad242220 2018-09-08 stsp if (repo) {
716 ad242220 2018-09-08 stsp const struct got_error *repo_error;
717 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
718 ad242220 2018-09-08 stsp if (error == NULL)
719 ad242220 2018-09-08 stsp error = repo_error;
720 ad242220 2018-09-08 stsp }
721 b00d56cd 2018-04-01 stsp return error;
722 404c43c4 2018-06-21 stsp }
723 404c43c4 2018-06-21 stsp
724 404c43c4 2018-06-21 stsp __dead static void
725 404c43c4 2018-06-21 stsp usage_blame(void)
726 404c43c4 2018-06-21 stsp {
727 66bea077 2018-08-02 stsp fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
728 404c43c4 2018-06-21 stsp getprogname());
729 404c43c4 2018-06-21 stsp exit(1);
730 b00d56cd 2018-04-01 stsp }
731 b00d56cd 2018-04-01 stsp
732 404c43c4 2018-06-21 stsp static const struct got_error *
733 404c43c4 2018-06-21 stsp cmd_blame(int argc, char *argv[])
734 404c43c4 2018-06-21 stsp {
735 404c43c4 2018-06-21 stsp const struct got_error *error;
736 404c43c4 2018-06-21 stsp struct got_repository *repo = NULL;
737 66bea077 2018-08-02 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
738 404c43c4 2018-06-21 stsp struct got_object_id *commit_id = NULL;
739 404c43c4 2018-06-21 stsp char *commit_id_str = NULL;
740 404c43c4 2018-06-21 stsp int ch;
741 404c43c4 2018-06-21 stsp
742 404c43c4 2018-06-21 stsp #ifndef PROFILE
743 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
744 ad242220 2018-09-08 stsp == -1)
745 404c43c4 2018-06-21 stsp err(1, "pledge");
746 404c43c4 2018-06-21 stsp #endif
747 404c43c4 2018-06-21 stsp
748 66bea077 2018-08-02 stsp while ((ch = getopt(argc, argv, "c:r:")) != -1) {
749 404c43c4 2018-06-21 stsp switch (ch) {
750 404c43c4 2018-06-21 stsp case 'c':
751 404c43c4 2018-06-21 stsp commit_id_str = optarg;
752 404c43c4 2018-06-21 stsp break;
753 66bea077 2018-08-02 stsp case 'r':
754 66bea077 2018-08-02 stsp repo_path = realpath(optarg, NULL);
755 66bea077 2018-08-02 stsp if (repo_path == NULL)
756 66bea077 2018-08-02 stsp err(1, "-r option");
757 66bea077 2018-08-02 stsp break;
758 404c43c4 2018-06-21 stsp default:
759 404c43c4 2018-06-21 stsp usage();
760 404c43c4 2018-06-21 stsp /* NOTREACHED */
761 404c43c4 2018-06-21 stsp }
762 404c43c4 2018-06-21 stsp }
763 404c43c4 2018-06-21 stsp
764 404c43c4 2018-06-21 stsp argc -= optind;
765 404c43c4 2018-06-21 stsp argv += optind;
766 404c43c4 2018-06-21 stsp
767 a39318fd 2018-08-02 stsp if (argc == 1)
768 404c43c4 2018-06-21 stsp path = argv[0];
769 a39318fd 2018-08-02 stsp else
770 404c43c4 2018-06-21 stsp usage_blame();
771 404c43c4 2018-06-21 stsp
772 66bea077 2018-08-02 stsp cwd = getcwd(NULL, 0);
773 66bea077 2018-08-02 stsp if (cwd == NULL) {
774 66bea077 2018-08-02 stsp error = got_error_from_errno();
775 66bea077 2018-08-02 stsp goto done;
776 66bea077 2018-08-02 stsp }
777 66bea077 2018-08-02 stsp if (repo_path == NULL) {
778 66bea077 2018-08-02 stsp repo_path = strdup(cwd);
779 66bea077 2018-08-02 stsp if (repo_path == NULL) {
780 66bea077 2018-08-02 stsp error = got_error_from_errno();
781 66bea077 2018-08-02 stsp goto done;
782 66bea077 2018-08-02 stsp }
783 66bea077 2018-08-02 stsp }
784 66bea077 2018-08-02 stsp
785 404c43c4 2018-06-21 stsp error = got_repo_open(&repo, repo_path);
786 404c43c4 2018-06-21 stsp if (error != NULL)
787 404c43c4 2018-06-21 stsp goto done;
788 404c43c4 2018-06-21 stsp
789 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
790 66bea077 2018-08-02 stsp if (error != NULL)
791 66bea077 2018-08-02 stsp goto done;
792 66bea077 2018-08-02 stsp
793 404c43c4 2018-06-21 stsp if (commit_id_str == NULL) {
794 404c43c4 2018-06-21 stsp struct got_reference *head_ref;
795 404c43c4 2018-06-21 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
796 404c43c4 2018-06-21 stsp if (error != NULL)
797 66bea077 2018-08-02 stsp goto done;
798 404c43c4 2018-06-21 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
799 404c43c4 2018-06-21 stsp got_ref_close(head_ref);
800 404c43c4 2018-06-21 stsp if (error != NULL)
801 66bea077 2018-08-02 stsp goto done;
802 404c43c4 2018-06-21 stsp } else {
803 404c43c4 2018-06-21 stsp struct got_object *obj;
804 404c43c4 2018-06-21 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
805 404c43c4 2018-06-21 stsp if (error != NULL)
806 66bea077 2018-08-02 stsp goto done;
807 6402fb3c 2018-09-15 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
808 404c43c4 2018-06-21 stsp if (commit_id == NULL)
809 404c43c4 2018-06-21 stsp error = got_error_from_errno();
810 404c43c4 2018-06-21 stsp got_object_close(obj);
811 404c43c4 2018-06-21 stsp }
812 404c43c4 2018-06-21 stsp
813 66bea077 2018-08-02 stsp error = got_blame(in_repo_path, commit_id, repo, stdout);
814 404c43c4 2018-06-21 stsp done:
815 66bea077 2018-08-02 stsp free(in_repo_path);
816 66bea077 2018-08-02 stsp free(repo_path);
817 66bea077 2018-08-02 stsp free(cwd);
818 404c43c4 2018-06-21 stsp free(commit_id);
819 ad242220 2018-09-08 stsp if (repo) {
820 ad242220 2018-09-08 stsp const struct got_error *repo_error;
821 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
822 ad242220 2018-09-08 stsp if (error == NULL)
823 ad242220 2018-09-08 stsp error = repo_error;
824 ad242220 2018-09-08 stsp }
825 404c43c4 2018-06-21 stsp return error;
826 5de5890b 2018-10-18 stsp }
827 5de5890b 2018-10-18 stsp
828 5de5890b 2018-10-18 stsp __dead static void
829 5de5890b 2018-10-18 stsp usage_tree(void)
830 5de5890b 2018-10-18 stsp {
831 5de5890b 2018-10-18 stsp fprintf(stderr, "usage: %s tree [-c commit] [-r repository-path] [-i] path\n",
832 5de5890b 2018-10-18 stsp getprogname());
833 5de5890b 2018-10-18 stsp exit(1);
834 5de5890b 2018-10-18 stsp }
835 5de5890b 2018-10-18 stsp
836 5de5890b 2018-10-18 stsp
837 5de5890b 2018-10-18 stsp static const struct got_error *
838 5de5890b 2018-10-18 stsp print_tree(const char *path, struct got_object_id *commit_id,
839 5de5890b 2018-10-18 stsp int show_ids, struct got_repository *repo)
840 5de5890b 2018-10-18 stsp {
841 5de5890b 2018-10-18 stsp const struct got_error *err = NULL;
842 5de5890b 2018-10-18 stsp struct got_object_id *tree_id = NULL;
843 5de5890b 2018-10-18 stsp struct got_tree_object *tree = NULL;
844 5de5890b 2018-10-18 stsp const struct got_tree_entries *entries;
845 5de5890b 2018-10-18 stsp struct got_tree_entry *te;
846 5de5890b 2018-10-18 stsp
847 5de5890b 2018-10-18 stsp err = got_object_id_by_path(&tree_id, repo, commit_id, path);
848 5de5890b 2018-10-18 stsp if (err)
849 5de5890b 2018-10-18 stsp goto done;
850 5de5890b 2018-10-18 stsp
851 5de5890b 2018-10-18 stsp err = got_object_open_as_tree(&tree, repo, tree_id);
852 5de5890b 2018-10-18 stsp if (err)
853 5de5890b 2018-10-18 stsp goto done;
854 5de5890b 2018-10-18 stsp entries = got_object_tree_get_entries(tree);
855 5de5890b 2018-10-18 stsp te = SIMPLEQ_FIRST(&entries->head);
856 5de5890b 2018-10-18 stsp while (te) {
857 5de5890b 2018-10-18 stsp char *id = NULL;
858 84453469 2018-11-11 stsp
859 84453469 2018-11-11 stsp if (sigint_received || sigpipe_received)
860 84453469 2018-11-11 stsp break;
861 84453469 2018-11-11 stsp
862 5de5890b 2018-10-18 stsp if (show_ids) {
863 5de5890b 2018-10-18 stsp char *id_str;
864 5de5890b 2018-10-18 stsp err = got_object_id_str(&id_str, te->id);
865 5de5890b 2018-10-18 stsp if (err)
866 5de5890b 2018-10-18 stsp goto done;
867 5de5890b 2018-10-18 stsp if (asprintf(&id, "%s ", id_str) == -1) {
868 5de5890b 2018-10-18 stsp err = got_error_from_errno();
869 5de5890b 2018-10-18 stsp free(id_str);
870 5de5890b 2018-10-18 stsp goto done;
871 5de5890b 2018-10-18 stsp }
872 5de5890b 2018-10-18 stsp free(id_str);
873 5de5890b 2018-10-18 stsp }
874 5de5890b 2018-10-18 stsp printf("%s%s%s\n", id ? id : "",
875 5de5890b 2018-10-18 stsp te->name, S_ISDIR(te->mode) ? "/" : "");
876 5de5890b 2018-10-18 stsp te = SIMPLEQ_NEXT(te, entry);
877 5de5890b 2018-10-18 stsp free(id);
878 5de5890b 2018-10-18 stsp }
879 5de5890b 2018-10-18 stsp done:
880 5de5890b 2018-10-18 stsp if (tree)
881 5de5890b 2018-10-18 stsp got_object_tree_close(tree);
882 5de5890b 2018-10-18 stsp free(tree_id);
883 5de5890b 2018-10-18 stsp return err;
884 404c43c4 2018-06-21 stsp }
885 404c43c4 2018-06-21 stsp
886 5de5890b 2018-10-18 stsp static const struct got_error *
887 5de5890b 2018-10-18 stsp cmd_tree(int argc, char *argv[])
888 5de5890b 2018-10-18 stsp {
889 5de5890b 2018-10-18 stsp const struct got_error *error;
890 5de5890b 2018-10-18 stsp struct got_repository *repo = NULL;
891 5de5890b 2018-10-18 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
892 5de5890b 2018-10-18 stsp struct got_object_id *commit_id = NULL;
893 5de5890b 2018-10-18 stsp char *commit_id_str = NULL;
894 5de5890b 2018-10-18 stsp int show_ids = 0;
895 5de5890b 2018-10-18 stsp int ch;
896 5de5890b 2018-10-18 stsp
897 5de5890b 2018-10-18 stsp #ifndef PROFILE
898 5de5890b 2018-10-18 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
899 5de5890b 2018-10-18 stsp == -1)
900 5de5890b 2018-10-18 stsp err(1, "pledge");
901 5de5890b 2018-10-18 stsp #endif
902 5de5890b 2018-10-18 stsp
903 5de5890b 2018-10-18 stsp while ((ch = getopt(argc, argv, "c:r:i")) != -1) {
904 5de5890b 2018-10-18 stsp switch (ch) {
905 5de5890b 2018-10-18 stsp case 'c':
906 5de5890b 2018-10-18 stsp commit_id_str = optarg;
907 5de5890b 2018-10-18 stsp break;
908 5de5890b 2018-10-18 stsp case 'r':
909 5de5890b 2018-10-18 stsp repo_path = realpath(optarg, NULL);
910 5de5890b 2018-10-18 stsp if (repo_path == NULL)
911 5de5890b 2018-10-18 stsp err(1, "-r option");
912 5de5890b 2018-10-18 stsp break;
913 5de5890b 2018-10-18 stsp case 'i':
914 5de5890b 2018-10-18 stsp show_ids = 1;
915 5de5890b 2018-10-18 stsp break;
916 5de5890b 2018-10-18 stsp default:
917 5de5890b 2018-10-18 stsp usage();
918 5de5890b 2018-10-18 stsp /* NOTREACHED */
919 5de5890b 2018-10-18 stsp }
920 5de5890b 2018-10-18 stsp }
921 5de5890b 2018-10-18 stsp
922 5de5890b 2018-10-18 stsp argc -= optind;
923 5de5890b 2018-10-18 stsp argv += optind;
924 5de5890b 2018-10-18 stsp
925 5de5890b 2018-10-18 stsp if (argc == 1)
926 5de5890b 2018-10-18 stsp path = argv[0];
927 5de5890b 2018-10-18 stsp else if (argc > 1)
928 5de5890b 2018-10-18 stsp usage_tree();
929 5de5890b 2018-10-18 stsp else
930 5de5890b 2018-10-18 stsp path = "/";
931 5de5890b 2018-10-18 stsp
932 5de5890b 2018-10-18 stsp cwd = getcwd(NULL, 0);
933 5de5890b 2018-10-18 stsp if (cwd == NULL) {
934 5de5890b 2018-10-18 stsp error = got_error_from_errno();
935 5de5890b 2018-10-18 stsp goto done;
936 5de5890b 2018-10-18 stsp }
937 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
938 5de5890b 2018-10-18 stsp repo_path = strdup(cwd);
939 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
940 5de5890b 2018-10-18 stsp error = got_error_from_errno();
941 5de5890b 2018-10-18 stsp goto done;
942 5de5890b 2018-10-18 stsp }
943 5de5890b 2018-10-18 stsp }
944 5de5890b 2018-10-18 stsp
945 5de5890b 2018-10-18 stsp error = got_repo_open(&repo, repo_path);
946 5de5890b 2018-10-18 stsp if (error != NULL)
947 5de5890b 2018-10-18 stsp goto done;
948 5de5890b 2018-10-18 stsp
949 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
950 5de5890b 2018-10-18 stsp if (error != NULL)
951 5de5890b 2018-10-18 stsp goto done;
952 5de5890b 2018-10-18 stsp
953 5de5890b 2018-10-18 stsp if (commit_id_str == NULL) {
954 5de5890b 2018-10-18 stsp struct got_reference *head_ref;
955 5de5890b 2018-10-18 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
956 5de5890b 2018-10-18 stsp if (error != NULL)
957 5de5890b 2018-10-18 stsp goto done;
958 5de5890b 2018-10-18 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
959 5de5890b 2018-10-18 stsp got_ref_close(head_ref);
960 5de5890b 2018-10-18 stsp if (error != NULL)
961 5de5890b 2018-10-18 stsp goto done;
962 5de5890b 2018-10-18 stsp } else {
963 5de5890b 2018-10-18 stsp struct got_object *obj;
964 5de5890b 2018-10-18 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
965 5de5890b 2018-10-18 stsp if (error != NULL)
966 5de5890b 2018-10-18 stsp goto done;
967 5de5890b 2018-10-18 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
968 5de5890b 2018-10-18 stsp if (commit_id == NULL)
969 5de5890b 2018-10-18 stsp error = got_error_from_errno();
970 5de5890b 2018-10-18 stsp got_object_close(obj);
971 5de5890b 2018-10-18 stsp }
972 5de5890b 2018-10-18 stsp
973 5de5890b 2018-10-18 stsp error = print_tree(in_repo_path, commit_id, show_ids, repo);
974 5de5890b 2018-10-18 stsp done:
975 5de5890b 2018-10-18 stsp free(in_repo_path);
976 5de5890b 2018-10-18 stsp free(repo_path);
977 5de5890b 2018-10-18 stsp free(cwd);
978 5de5890b 2018-10-18 stsp free(commit_id);
979 5de5890b 2018-10-18 stsp if (repo) {
980 5de5890b 2018-10-18 stsp const struct got_error *repo_error;
981 5de5890b 2018-10-18 stsp repo_error = got_repo_close(repo);
982 5de5890b 2018-10-18 stsp if (error == NULL)
983 5de5890b 2018-10-18 stsp error = repo_error;
984 5de5890b 2018-10-18 stsp }
985 5de5890b 2018-10-18 stsp return error;
986 5de5890b 2018-10-18 stsp }
987 5de5890b 2018-10-18 stsp
988 f42b1b34 2018-03-12 stsp #ifdef notyet
989 4ed7e80c 2018-05-20 stsp static const struct got_error *
990 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
991 5c860e29 2018-03-12 stsp {
992 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
993 5c860e29 2018-03-12 stsp git_status_list *status;
994 5c860e29 2018-03-12 stsp git_status_options statusopts;
995 5c860e29 2018-03-12 stsp size_t i;
996 5c860e29 2018-03-12 stsp
997 5c860e29 2018-03-12 stsp git_libgit2_init();
998 5c860e29 2018-03-12 stsp
999 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
1000 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
1001 5c860e29 2018-03-12 stsp
1002 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
1003 5c860e29 2018-03-12 stsp errx(1, "bar repository");
1004 5c860e29 2018-03-12 stsp
1005 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
1006 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
1007 5c860e29 2018-03-12 stsp
1008 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1009 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
1010 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
1011 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
1012 5c860e29 2018-03-12 stsp
1013 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
1014 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
1015 5c860e29 2018-03-12 stsp
1016 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
1017 5c860e29 2018-03-12 stsp const git_status_entry *se;
1018 5c860e29 2018-03-12 stsp
1019 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
1020 5c860e29 2018-03-12 stsp switch (se->status) {
1021 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
1022 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
1023 5c860e29 2018-03-12 stsp break;
1024 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
1025 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
1026 5c860e29 2018-03-12 stsp break;
1027 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
1028 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
1029 5c860e29 2018-03-12 stsp break;
1030 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
1031 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1032 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
1033 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
1034 5c860e29 2018-03-12 stsp break;
1035 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
1036 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
1037 5c860e29 2018-03-12 stsp break;
1038 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
1039 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
1040 5c860e29 2018-03-12 stsp break;
1041 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
1042 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
1043 5c860e29 2018-03-12 stsp break;
1044 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
1045 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
1046 5c860e29 2018-03-12 stsp break;
1047 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
1048 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1049 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
1050 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
1051 5c860e29 2018-03-12 stsp break;
1052 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
1053 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
1054 5c860e29 2018-03-12 stsp break;
1055 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
1056 5c860e29 2018-03-12 stsp default:
1057 5c860e29 2018-03-12 stsp break;
1058 5c860e29 2018-03-12 stsp }
1059 5c860e29 2018-03-12 stsp }
1060 5c860e29 2018-03-12 stsp
1061 5c860e29 2018-03-12 stsp git_status_list_free(status);
1062 5c860e29 2018-03-12 stsp git_repository_free(repo);
1063 5c860e29 2018-03-12 stsp git_libgit2_shutdown();
1064 5c860e29 2018-03-12 stsp
1065 5c860e29 2018-03-12 stsp return 0;
1066 5c860e29 2018-03-12 stsp }
1067 f42b1b34 2018-03-12 stsp #endif