Blame


1 5c860e29 2018-03-12 stsp /*
2 f42b1b34 2018-03-12 stsp * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 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 63219cd2 2019-01-04 stsp #include "got_privsep.h"
43 5c860e29 2018-03-12 stsp
44 5c860e29 2018-03-12 stsp #ifndef nitems
45 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
46 5c860e29 2018-03-12 stsp #endif
47 99437157 2018-11-11 stsp
48 99437157 2018-11-11 stsp static volatile sig_atomic_t sigint_received;
49 99437157 2018-11-11 stsp static volatile sig_atomic_t sigpipe_received;
50 99437157 2018-11-11 stsp
51 99437157 2018-11-11 stsp static void
52 99437157 2018-11-11 stsp catch_sigint(int signo)
53 99437157 2018-11-11 stsp {
54 99437157 2018-11-11 stsp sigint_received = 1;
55 99437157 2018-11-11 stsp }
56 99437157 2018-11-11 stsp
57 99437157 2018-11-11 stsp static void
58 99437157 2018-11-11 stsp catch_sigpipe(int signo)
59 99437157 2018-11-11 stsp {
60 99437157 2018-11-11 stsp sigpipe_received = 1;
61 99437157 2018-11-11 stsp }
62 5c860e29 2018-03-12 stsp
63 99437157 2018-11-11 stsp
64 5c860e29 2018-03-12 stsp struct cmd {
65 5c860e29 2018-03-12 stsp const char *cmd_name;
66 d7d4f210 2018-03-12 stsp const struct got_error *(*cmd_main)(int, char *[]);
67 1b6b95a8 2018-03-12 stsp void (*cmd_usage)(void);
68 46a0db7d 2018-03-12 stsp const char *cmd_descr;
69 5c860e29 2018-03-12 stsp };
70 5c860e29 2018-03-12 stsp
71 4ed7e80c 2018-05-20 stsp __dead static void usage(void);
72 4ed7e80c 2018-05-20 stsp __dead static void usage_checkout(void);
73 507dc3bb 2018-12-29 stsp __dead static void usage_update(void);
74 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
75 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
76 404c43c4 2018-06-21 stsp __dead static void usage_blame(void);
77 5de5890b 2018-10-18 stsp __dead static void usage_tree(void);
78 5c860e29 2018-03-12 stsp
79 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_checkout(int, char *[]);
80 507dc3bb 2018-12-29 stsp static const struct got_error* cmd_update(int, char *[]);
81 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
82 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
83 404c43c4 2018-06-21 stsp static const struct got_error* cmd_blame(int, char *[]);
84 5de5890b 2018-10-18 stsp static const struct got_error* cmd_tree(int, char *[]);
85 4ed7e80c 2018-05-20 stsp #ifdef notyet
86 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_status(int, char *[]);
87 4ed7e80c 2018-05-20 stsp #endif
88 5c860e29 2018-03-12 stsp
89 4ed7e80c 2018-05-20 stsp static struct cmd got_commands[] = {
90 c09a553d 2018-03-12 stsp { "checkout", cmd_checkout, usage_checkout,
91 0bb8a95e 2018-03-12 stsp "check out a new work tree from a repository" },
92 507dc3bb 2018-12-29 stsp { "update", cmd_update, usage_update,
93 507dc3bb 2018-12-29 stsp "update a work tree to a different commit" },
94 1b6b95a8 2018-03-12 stsp { "log", cmd_log, usage_log,
95 1b6b95a8 2018-03-12 stsp "show repository history" },
96 b00d56cd 2018-04-01 stsp { "diff", cmd_diff, usage_diff,
97 b00d56cd 2018-04-01 stsp "compare files and directories" },
98 404c43c4 2018-06-21 stsp { "blame", cmd_blame, usage_blame,
99 404c43c4 2018-06-21 stsp " show when lines in a file were changed" },
100 5de5890b 2018-10-18 stsp { "tree", cmd_tree, usage_tree,
101 5de5890b 2018-10-18 stsp " list files and directories in repository" },
102 f42b1b34 2018-03-12 stsp #ifdef notyet
103 1b6b95a8 2018-03-12 stsp { "status", cmd_status, usage_status,
104 1b6b95a8 2018-03-12 stsp "show modification status of files" },
105 f42b1b34 2018-03-12 stsp #endif
106 5c860e29 2018-03-12 stsp };
107 5c860e29 2018-03-12 stsp
108 5c860e29 2018-03-12 stsp int
109 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
110 5c860e29 2018-03-12 stsp {
111 5c860e29 2018-03-12 stsp struct cmd *cmd;
112 5c860e29 2018-03-12 stsp unsigned int i;
113 5c860e29 2018-03-12 stsp int ch;
114 1b6b95a8 2018-03-12 stsp int hflag = 0;
115 5c860e29 2018-03-12 stsp
116 289e3cbf 2019-02-04 stsp setlocale(LC_CTYPE, "");
117 5c860e29 2018-03-12 stsp
118 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
119 5c860e29 2018-03-12 stsp switch (ch) {
120 1b6b95a8 2018-03-12 stsp case 'h':
121 1b6b95a8 2018-03-12 stsp hflag = 1;
122 1b6b95a8 2018-03-12 stsp break;
123 5c860e29 2018-03-12 stsp default:
124 5c860e29 2018-03-12 stsp usage();
125 5c860e29 2018-03-12 stsp /* NOTREACHED */
126 5c860e29 2018-03-12 stsp }
127 5c860e29 2018-03-12 stsp }
128 5c860e29 2018-03-12 stsp
129 5c860e29 2018-03-12 stsp argc -= optind;
130 5c860e29 2018-03-12 stsp argv += optind;
131 1e70621d 2018-03-27 stsp optind = 0;
132 5c860e29 2018-03-12 stsp
133 5c860e29 2018-03-12 stsp if (argc <= 0)
134 5c860e29 2018-03-12 stsp usage();
135 5c860e29 2018-03-12 stsp
136 99437157 2018-11-11 stsp signal(SIGINT, catch_sigint);
137 99437157 2018-11-11 stsp signal(SIGPIPE, catch_sigpipe);
138 99437157 2018-11-11 stsp
139 5c860e29 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
140 d7d4f210 2018-03-12 stsp const struct got_error *error;
141 d7d4f210 2018-03-12 stsp
142 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
143 5c860e29 2018-03-12 stsp
144 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
145 5c860e29 2018-03-12 stsp continue;
146 5c860e29 2018-03-12 stsp
147 1b6b95a8 2018-03-12 stsp if (hflag)
148 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
149 1b6b95a8 2018-03-12 stsp
150 d7d4f210 2018-03-12 stsp error = got_commands[i].cmd_main(argc, argv);
151 80d5f134 2018-11-11 stsp if (error && !(sigint_received || sigpipe_received)) {
152 d7d4f210 2018-03-12 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
153 d7d4f210 2018-03-12 stsp return 1;
154 d7d4f210 2018-03-12 stsp }
155 d7d4f210 2018-03-12 stsp
156 d7d4f210 2018-03-12 stsp return 0;
157 5c860e29 2018-03-12 stsp }
158 5c860e29 2018-03-12 stsp
159 20ecf764 2018-03-12 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
160 5c860e29 2018-03-12 stsp return 1;
161 5c860e29 2018-03-12 stsp }
162 5c860e29 2018-03-12 stsp
163 4ed7e80c 2018-05-20 stsp __dead static void
164 5c860e29 2018-03-12 stsp usage(void)
165 5c860e29 2018-03-12 stsp {
166 46a0db7d 2018-03-12 stsp int i;
167 46a0db7d 2018-03-12 stsp
168 987e94ba 2018-03-12 stsp fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
169 987e94ba 2018-03-12 stsp "Available commands:\n", getprogname());
170 46a0db7d 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
171 46a0db7d 2018-03-12 stsp struct cmd *cmd = &got_commands[i];
172 46a0db7d 2018-03-12 stsp fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
173 46a0db7d 2018-03-12 stsp }
174 5c860e29 2018-03-12 stsp exit(1);
175 5c860e29 2018-03-12 stsp }
176 5c860e29 2018-03-12 stsp
177 0266afb7 2019-01-04 stsp static const struct got_error *
178 0266afb7 2019-01-04 stsp apply_unveil(const char *repo_path, const char *worktree_path)
179 0266afb7 2019-01-04 stsp {
180 0266afb7 2019-01-04 stsp const struct got_error *error;
181 0266afb7 2019-01-04 stsp
182 0266afb7 2019-01-04 stsp if (repo_path && unveil(repo_path, "r") != 0)
183 0266afb7 2019-01-04 stsp return got_error_from_errno();
184 0266afb7 2019-01-04 stsp
185 0266afb7 2019-01-04 stsp if (worktree_path && unveil(worktree_path, "rwc") != 0)
186 0266afb7 2019-01-04 stsp return got_error_from_errno();
187 0266afb7 2019-01-04 stsp
188 f12d0dbe 2019-01-04 stsp if (unveil("/tmp", "rwc") != 0)
189 0266afb7 2019-01-04 stsp return got_error_from_errno();
190 0266afb7 2019-01-04 stsp
191 0266afb7 2019-01-04 stsp error = got_privsep_unveil_exec_helpers();
192 0266afb7 2019-01-04 stsp if (error != NULL)
193 0266afb7 2019-01-04 stsp return error;
194 0266afb7 2019-01-04 stsp
195 0266afb7 2019-01-04 stsp if (unveil(NULL, NULL) != 0)
196 0266afb7 2019-01-04 stsp return got_error_from_errno();
197 0266afb7 2019-01-04 stsp
198 0266afb7 2019-01-04 stsp return NULL;
199 0266afb7 2019-01-04 stsp }
200 0266afb7 2019-01-04 stsp
201 4ed7e80c 2018-05-20 stsp __dead static void
202 c09a553d 2018-03-12 stsp usage_checkout(void)
203 c09a553d 2018-03-12 stsp {
204 0bb8a95e 2018-03-12 stsp fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
205 0bb8a95e 2018-03-12 stsp "[worktree-path]\n", getprogname());
206 c09a553d 2018-03-12 stsp exit(1);
207 92a684f4 2018-03-12 stsp }
208 92a684f4 2018-03-12 stsp
209 92a684f4 2018-03-12 stsp static void
210 a0eb853d 2018-12-29 stsp checkout_progress(void *arg, unsigned char status, const char *path)
211 92a684f4 2018-03-12 stsp {
212 92a684f4 2018-03-12 stsp char *worktree_path = arg;
213 92a684f4 2018-03-12 stsp
214 92a684f4 2018-03-12 stsp while (path[0] == '/')
215 92a684f4 2018-03-12 stsp path++;
216 92a684f4 2018-03-12 stsp
217 d7b62c98 2018-12-27 stsp printf("%c %s/%s\n", status, worktree_path, path);
218 99437157 2018-11-11 stsp }
219 99437157 2018-11-11 stsp
220 99437157 2018-11-11 stsp static const struct got_error *
221 99437157 2018-11-11 stsp checkout_cancel(void *arg)
222 99437157 2018-11-11 stsp {
223 99437157 2018-11-11 stsp if (sigint_received || sigpipe_received)
224 99437157 2018-11-11 stsp return got_error(GOT_ERR_CANCELLED);
225 99437157 2018-11-11 stsp return NULL;
226 8069f636 2019-01-12 stsp }
227 8069f636 2019-01-12 stsp
228 8069f636 2019-01-12 stsp static const struct got_error *
229 8069f636 2019-01-12 stsp check_ancestry(struct got_worktree *worktree, struct got_object_id *commit_id,
230 8069f636 2019-01-12 stsp struct got_repository *repo)
231 8069f636 2019-01-12 stsp {
232 8069f636 2019-01-12 stsp const struct got_error *err;
233 8069f636 2019-01-12 stsp struct got_reference *head_ref = NULL;
234 8069f636 2019-01-12 stsp struct got_object_id *head_commit_id = NULL;
235 8069f636 2019-01-12 stsp struct got_commit_graph *graph = NULL;
236 8069f636 2019-01-12 stsp
237 8069f636 2019-01-12 stsp head_ref = got_worktree_get_head_ref(worktree);
238 8069f636 2019-01-12 stsp if (head_ref == NULL)
239 8069f636 2019-01-12 stsp return got_error_from_errno();
240 8069f636 2019-01-12 stsp
241 8069f636 2019-01-12 stsp /* TODO: Check the reflog. The head ref may have been rebased. */
242 8069f636 2019-01-12 stsp err = got_ref_resolve(&head_commit_id, repo, head_ref);
243 8069f636 2019-01-12 stsp if (err)
244 8069f636 2019-01-12 stsp goto done;
245 8069f636 2019-01-12 stsp
246 8069f636 2019-01-12 stsp err = got_commit_graph_open(&graph, head_commit_id, "/", 1, repo);
247 8069f636 2019-01-12 stsp if (err)
248 8069f636 2019-01-12 stsp goto done;
249 8069f636 2019-01-12 stsp
250 8069f636 2019-01-12 stsp err = got_commit_graph_iter_start(graph, head_commit_id, repo);
251 8069f636 2019-01-12 stsp if (err)
252 8069f636 2019-01-12 stsp goto done;
253 8069f636 2019-01-12 stsp while (1) {
254 8069f636 2019-01-12 stsp struct got_object_id *id;
255 8069f636 2019-01-12 stsp
256 8069f636 2019-01-12 stsp if (sigint_received || sigpipe_received)
257 8069f636 2019-01-12 stsp break;
258 8069f636 2019-01-12 stsp
259 8069f636 2019-01-12 stsp err = got_commit_graph_iter_next(&id, graph);
260 8069f636 2019-01-12 stsp if (err) {
261 8069f636 2019-01-12 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
262 8069f636 2019-01-12 stsp err = got_error(GOT_ERR_ANCESTRY);
263 8069f636 2019-01-12 stsp break;
264 8069f636 2019-01-12 stsp }
265 8069f636 2019-01-12 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
266 8069f636 2019-01-12 stsp break;
267 8069f636 2019-01-12 stsp err = got_commit_graph_fetch_commits(graph, 1, repo);
268 8069f636 2019-01-12 stsp if (err)
269 8069f636 2019-01-12 stsp break;
270 8069f636 2019-01-12 stsp else
271 8069f636 2019-01-12 stsp continue;
272 8069f636 2019-01-12 stsp }
273 8069f636 2019-01-12 stsp if (id == NULL)
274 8069f636 2019-01-12 stsp break;
275 8069f636 2019-01-12 stsp if (got_object_id_cmp(id, commit_id) == 0)
276 8069f636 2019-01-12 stsp break;
277 8069f636 2019-01-12 stsp }
278 8069f636 2019-01-12 stsp done:
279 8069f636 2019-01-12 stsp if (head_ref)
280 8069f636 2019-01-12 stsp got_ref_close(head_ref);
281 8069f636 2019-01-12 stsp if (graph)
282 8069f636 2019-01-12 stsp got_commit_graph_close(graph);
283 8069f636 2019-01-12 stsp return err;
284 c09a553d 2018-03-12 stsp }
285 c09a553d 2018-03-12 stsp
286 8069f636 2019-01-12 stsp
287 4ed7e80c 2018-05-20 stsp static const struct got_error *
288 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
289 c09a553d 2018-03-12 stsp {
290 c09a553d 2018-03-12 stsp const struct got_error *error = NULL;
291 c09a553d 2018-03-12 stsp struct got_repository *repo = NULL;
292 c09a553d 2018-03-12 stsp struct got_reference *head_ref = NULL;
293 c09a553d 2018-03-12 stsp struct got_worktree *worktree = NULL;
294 c09a553d 2018-03-12 stsp char *repo_path = NULL;
295 c09a553d 2018-03-12 stsp char *worktree_path = NULL;
296 0bb8a95e 2018-03-12 stsp const char *path_prefix = "";
297 8069f636 2019-01-12 stsp char *commit_id_str = NULL;
298 e5dc7198 2018-12-29 stsp int ch, same_path_prefix;
299 c09a553d 2018-03-12 stsp
300 8069f636 2019-01-12 stsp while ((ch = getopt(argc, argv, "c:p:")) != -1) {
301 0bb8a95e 2018-03-12 stsp switch (ch) {
302 8069f636 2019-01-12 stsp case 'c':
303 8069f636 2019-01-12 stsp commit_id_str = strdup(optarg);
304 8069f636 2019-01-12 stsp if (commit_id_str == NULL)
305 8069f636 2019-01-12 stsp return got_error_from_errno();
306 8069f636 2019-01-12 stsp break;
307 0bb8a95e 2018-03-12 stsp case 'p':
308 0bb8a95e 2018-03-12 stsp path_prefix = optarg;
309 0bb8a95e 2018-03-12 stsp break;
310 0bb8a95e 2018-03-12 stsp default:
311 0bb8a95e 2018-03-12 stsp usage();
312 0bb8a95e 2018-03-12 stsp /* NOTREACHED */
313 0bb8a95e 2018-03-12 stsp }
314 0bb8a95e 2018-03-12 stsp }
315 0bb8a95e 2018-03-12 stsp
316 0bb8a95e 2018-03-12 stsp argc -= optind;
317 0bb8a95e 2018-03-12 stsp argv += optind;
318 0bb8a95e 2018-03-12 stsp
319 6715a751 2018-03-16 stsp #ifndef PROFILE
320 63219cd2 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
321 63219cd2 2019-01-04 stsp NULL) == -1)
322 c09a553d 2018-03-12 stsp err(1, "pledge");
323 6715a751 2018-03-16 stsp #endif
324 0bb8a95e 2018-03-12 stsp if (argc == 1) {
325 c09a553d 2018-03-12 stsp char *cwd, *base, *dotgit;
326 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
327 76089277 2018-04-01 stsp if (repo_path == NULL)
328 76089277 2018-04-01 stsp return got_error_from_errno();
329 c09a553d 2018-03-12 stsp cwd = getcwd(NULL, 0);
330 76089277 2018-04-01 stsp if (cwd == NULL) {
331 76089277 2018-04-01 stsp error = got_error_from_errno();
332 76089277 2018-04-01 stsp goto done;
333 76089277 2018-04-01 stsp }
334 5d7c1dab 2018-04-01 stsp if (path_prefix[0])
335 5d7c1dab 2018-04-01 stsp base = basename(path_prefix);
336 5d7c1dab 2018-04-01 stsp else
337 5d7c1dab 2018-04-01 stsp base = basename(repo_path);
338 76089277 2018-04-01 stsp if (base == NULL) {
339 76089277 2018-04-01 stsp error = got_error_from_errno();
340 76089277 2018-04-01 stsp goto done;
341 76089277 2018-04-01 stsp }
342 c09a553d 2018-03-12 stsp dotgit = strstr(base, ".git");
343 c09a553d 2018-03-12 stsp if (dotgit)
344 c09a553d 2018-03-12 stsp *dotgit = '\0';
345 c09a553d 2018-03-12 stsp if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
346 0a585a0d 2018-03-17 stsp error = got_error_from_errno();
347 c09a553d 2018-03-12 stsp free(cwd);
348 76089277 2018-04-01 stsp goto done;
349 c09a553d 2018-03-12 stsp }
350 c09a553d 2018-03-12 stsp free(cwd);
351 0bb8a95e 2018-03-12 stsp } else if (argc == 2) {
352 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
353 76089277 2018-04-01 stsp if (repo_path == NULL) {
354 76089277 2018-04-01 stsp error = got_error_from_errno();
355 76089277 2018-04-01 stsp goto done;
356 76089277 2018-04-01 stsp }
357 f7b38925 2018-04-01 stsp worktree_path = realpath(argv[1], NULL);
358 76089277 2018-04-01 stsp if (worktree_path == NULL) {
359 76089277 2018-04-01 stsp error = got_error_from_errno();
360 76089277 2018-04-01 stsp goto done;
361 76089277 2018-04-01 stsp }
362 c09a553d 2018-03-12 stsp } else
363 c09a553d 2018-03-12 stsp usage_checkout();
364 63219cd2 2019-01-04 stsp
365 0266afb7 2019-01-04 stsp error = apply_unveil(repo_path, worktree_path);
366 0266afb7 2019-01-04 stsp if (error)
367 63219cd2 2019-01-04 stsp goto done;
368 c09a553d 2018-03-12 stsp
369 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
370 c09a553d 2018-03-12 stsp if (error != NULL)
371 c09a553d 2018-03-12 stsp goto done;
372 8069f636 2019-01-12 stsp
373 c09a553d 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
374 c09a553d 2018-03-12 stsp if (error != NULL)
375 c09a553d 2018-03-12 stsp goto done;
376 c09a553d 2018-03-12 stsp
377 0bb8a95e 2018-03-12 stsp error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
378 d70b8e30 2018-12-27 stsp if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
379 c09a553d 2018-03-12 stsp goto done;
380 c09a553d 2018-03-12 stsp
381 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
382 c09a553d 2018-03-12 stsp if (error != NULL)
383 c09a553d 2018-03-12 stsp goto done;
384 c09a553d 2018-03-12 stsp
385 e5dc7198 2018-12-29 stsp error = got_worktree_match_path_prefix(&same_path_prefix, worktree,
386 e5dc7198 2018-12-29 stsp path_prefix);
387 e5dc7198 2018-12-29 stsp if (error != NULL)
388 e5dc7198 2018-12-29 stsp goto done;
389 e5dc7198 2018-12-29 stsp if (!same_path_prefix) {
390 49520a32 2018-12-29 stsp error = got_error(GOT_ERR_PATH_PREFIX);
391 49520a32 2018-12-29 stsp goto done;
392 49520a32 2018-12-29 stsp }
393 49520a32 2018-12-29 stsp
394 8069f636 2019-01-12 stsp if (commit_id_str) {
395 8069f636 2019-01-12 stsp struct got_object_id *commit_id;
396 8069f636 2019-01-12 stsp error = got_object_resolve_id_str(&commit_id, repo,
397 8069f636 2019-01-12 stsp commit_id_str);
398 8069f636 2019-01-12 stsp if (error != NULL)
399 8069f636 2019-01-12 stsp goto done;
400 8069f636 2019-01-12 stsp error = check_ancestry(worktree, commit_id, repo);
401 8069f636 2019-01-12 stsp if (error != NULL) {
402 8069f636 2019-01-12 stsp free(commit_id);
403 8069f636 2019-01-12 stsp goto done;
404 8069f636 2019-01-12 stsp }
405 8069f636 2019-01-12 stsp error = got_worktree_set_base_commit_id(worktree, repo,
406 8069f636 2019-01-12 stsp commit_id);
407 8069f636 2019-01-12 stsp free(commit_id);
408 8069f636 2019-01-12 stsp if (error)
409 8069f636 2019-01-12 stsp goto done;
410 8069f636 2019-01-12 stsp }
411 8069f636 2019-01-12 stsp
412 93a30277 2018-12-24 stsp error = got_worktree_checkout_files(worktree, repo,
413 99437157 2018-11-11 stsp checkout_progress, worktree_path, checkout_cancel, NULL);
414 c09a553d 2018-03-12 stsp if (error != NULL)
415 c09a553d 2018-03-12 stsp goto done;
416 c09a553d 2018-03-12 stsp
417 b65ae19a 2018-04-24 stsp printf("Now shut up and hack\n");
418 c09a553d 2018-03-12 stsp
419 c09a553d 2018-03-12 stsp done:
420 8069f636 2019-01-12 stsp free(commit_id_str);
421 76089277 2018-04-01 stsp free(repo_path);
422 507dc3bb 2018-12-29 stsp free(worktree_path);
423 507dc3bb 2018-12-29 stsp return error;
424 507dc3bb 2018-12-29 stsp }
425 507dc3bb 2018-12-29 stsp
426 507dc3bb 2018-12-29 stsp __dead static void
427 507dc3bb 2018-12-29 stsp usage_update(void)
428 507dc3bb 2018-12-29 stsp {
429 507dc3bb 2018-12-29 stsp fprintf(stderr, "usage: %s update [-c commit] [worktree-path]\n",
430 507dc3bb 2018-12-29 stsp getprogname());
431 507dc3bb 2018-12-29 stsp exit(1);
432 507dc3bb 2018-12-29 stsp }
433 507dc3bb 2018-12-29 stsp
434 507dc3bb 2018-12-29 stsp static void
435 507dc3bb 2018-12-29 stsp update_progress(void *arg, unsigned char status, const char *path)
436 507dc3bb 2018-12-29 stsp {
437 784955db 2019-01-12 stsp int *did_something = arg;
438 784955db 2019-01-12 stsp
439 507dc3bb 2018-12-29 stsp if (status == GOT_STATUS_EXISTS)
440 507dc3bb 2018-12-29 stsp return;
441 507dc3bb 2018-12-29 stsp
442 784955db 2019-01-12 stsp *did_something = 1;
443 507dc3bb 2018-12-29 stsp while (path[0] == '/')
444 507dc3bb 2018-12-29 stsp path++;
445 507dc3bb 2018-12-29 stsp printf("%c %s\n", status, path);
446 be7061eb 2018-12-30 stsp }
447 be7061eb 2018-12-30 stsp
448 be7061eb 2018-12-30 stsp static const struct got_error *
449 507dc3bb 2018-12-29 stsp cmd_update(int argc, char *argv[])
450 507dc3bb 2018-12-29 stsp {
451 507dc3bb 2018-12-29 stsp const struct got_error *error = NULL;
452 507dc3bb 2018-12-29 stsp struct got_repository *repo = NULL;
453 507dc3bb 2018-12-29 stsp struct got_worktree *worktree = NULL;
454 507dc3bb 2018-12-29 stsp char *worktree_path = NULL;
455 507dc3bb 2018-12-29 stsp struct got_object_id *commit_id = NULL;
456 9c4b8182 2019-01-02 stsp char *commit_id_str = NULL;
457 784955db 2019-01-12 stsp int ch, did_something = 0;
458 507dc3bb 2018-12-29 stsp
459 507dc3bb 2018-12-29 stsp while ((ch = getopt(argc, argv, "c:")) != -1) {
460 507dc3bb 2018-12-29 stsp switch (ch) {
461 507dc3bb 2018-12-29 stsp case 'c':
462 9c4b8182 2019-01-02 stsp commit_id_str = strdup(optarg);
463 9c4b8182 2019-01-02 stsp if (commit_id_str == NULL)
464 9c4b8182 2019-01-02 stsp return got_error_from_errno();
465 507dc3bb 2018-12-29 stsp break;
466 507dc3bb 2018-12-29 stsp default:
467 507dc3bb 2018-12-29 stsp usage();
468 507dc3bb 2018-12-29 stsp /* NOTREACHED */
469 507dc3bb 2018-12-29 stsp }
470 507dc3bb 2018-12-29 stsp }
471 507dc3bb 2018-12-29 stsp
472 507dc3bb 2018-12-29 stsp argc -= optind;
473 507dc3bb 2018-12-29 stsp argv += optind;
474 507dc3bb 2018-12-29 stsp
475 507dc3bb 2018-12-29 stsp #ifndef PROFILE
476 0266afb7 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
477 0266afb7 2019-01-04 stsp NULL) == -1)
478 507dc3bb 2018-12-29 stsp err(1, "pledge");
479 507dc3bb 2018-12-29 stsp #endif
480 507dc3bb 2018-12-29 stsp if (argc == 0) {
481 507dc3bb 2018-12-29 stsp worktree_path = getcwd(NULL, 0);
482 507dc3bb 2018-12-29 stsp if (worktree_path == NULL) {
483 507dc3bb 2018-12-29 stsp error = got_error_from_errno();
484 507dc3bb 2018-12-29 stsp goto done;
485 507dc3bb 2018-12-29 stsp }
486 507dc3bb 2018-12-29 stsp } else if (argc == 1) {
487 507dc3bb 2018-12-29 stsp worktree_path = realpath(argv[0], NULL);
488 507dc3bb 2018-12-29 stsp if (worktree_path == NULL) {
489 507dc3bb 2018-12-29 stsp error = got_error_from_errno();
490 507dc3bb 2018-12-29 stsp goto done;
491 507dc3bb 2018-12-29 stsp }
492 507dc3bb 2018-12-29 stsp } else
493 507dc3bb 2018-12-29 stsp usage_update();
494 507dc3bb 2018-12-29 stsp
495 507dc3bb 2018-12-29 stsp error = got_worktree_open(&worktree, worktree_path);
496 507dc3bb 2018-12-29 stsp if (error != NULL)
497 507dc3bb 2018-12-29 stsp goto done;
498 507dc3bb 2018-12-29 stsp
499 507dc3bb 2018-12-29 stsp error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
500 507dc3bb 2018-12-29 stsp if (error != NULL)
501 507dc3bb 2018-12-29 stsp goto done;
502 507dc3bb 2018-12-29 stsp
503 7839bc15 2019-01-06 stsp error = apply_unveil(got_repo_get_path(repo), worktree_path);
504 0266afb7 2019-01-04 stsp if (error)
505 0266afb7 2019-01-04 stsp goto done;
506 0266afb7 2019-01-04 stsp
507 507dc3bb 2018-12-29 stsp if (commit_id_str == NULL) {
508 507dc3bb 2018-12-29 stsp struct got_reference *head_ref;
509 507dc3bb 2018-12-29 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
510 507dc3bb 2018-12-29 stsp if (error != NULL)
511 507dc3bb 2018-12-29 stsp goto done;
512 507dc3bb 2018-12-29 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
513 9c4b8182 2019-01-02 stsp if (error != NULL)
514 9c4b8182 2019-01-02 stsp goto done;
515 9c4b8182 2019-01-02 stsp error = got_object_id_str(&commit_id_str, commit_id);
516 507dc3bb 2018-12-29 stsp if (error != NULL)
517 507dc3bb 2018-12-29 stsp goto done;
518 507dc3bb 2018-12-29 stsp } else {
519 507dc3bb 2018-12-29 stsp error = got_object_resolve_id_str(&commit_id, repo,
520 507dc3bb 2018-12-29 stsp commit_id_str);
521 507dc3bb 2018-12-29 stsp if (error != NULL)
522 507dc3bb 2018-12-29 stsp goto done;
523 507dc3bb 2018-12-29 stsp }
524 35c965b2 2018-12-29 stsp
525 be7061eb 2018-12-30 stsp error = check_ancestry(worktree, commit_id, repo);
526 be7061eb 2018-12-30 stsp if (error != NULL)
527 be7061eb 2018-12-30 stsp goto done;
528 507dc3bb 2018-12-29 stsp
529 507dc3bb 2018-12-29 stsp if (got_object_id_cmp(got_worktree_get_base_commit_id(worktree),
530 507dc3bb 2018-12-29 stsp commit_id) != 0) {
531 507dc3bb 2018-12-29 stsp error = got_worktree_set_base_commit_id(worktree, repo,
532 507dc3bb 2018-12-29 stsp commit_id);
533 507dc3bb 2018-12-29 stsp if (error)
534 507dc3bb 2018-12-29 stsp goto done;
535 507dc3bb 2018-12-29 stsp }
536 507dc3bb 2018-12-29 stsp
537 507dc3bb 2018-12-29 stsp error = got_worktree_checkout_files(worktree, repo,
538 784955db 2019-01-12 stsp update_progress, &did_something, checkout_cancel, NULL);
539 507dc3bb 2018-12-29 stsp if (error != NULL)
540 507dc3bb 2018-12-29 stsp goto done;
541 9c4b8182 2019-01-02 stsp
542 784955db 2019-01-12 stsp if (did_something)
543 784955db 2019-01-12 stsp printf("Updated to commit %s\n", commit_id_str);
544 784955db 2019-01-12 stsp else
545 784955db 2019-01-12 stsp printf("Already up-to-date\n");
546 507dc3bb 2018-12-29 stsp done:
547 c09a553d 2018-03-12 stsp free(worktree_path);
548 507dc3bb 2018-12-29 stsp free(commit_id);
549 9c4b8182 2019-01-02 stsp free(commit_id_str);
550 c09a553d 2018-03-12 stsp return error;
551 c09a553d 2018-03-12 stsp }
552 c09a553d 2018-03-12 stsp
553 f42b1b34 2018-03-12 stsp static const struct got_error *
554 79109fed 2018-03-27 stsp print_patch(struct got_commit_object *commit, struct got_object_id *id,
555 c0cc5c62 2018-10-18 stsp int diff_context, struct got_repository *repo)
556 5c860e29 2018-03-12 stsp {
557 f42b1b34 2018-03-12 stsp const struct got_error *err = NULL;
558 79109fed 2018-03-27 stsp struct got_tree_object *tree1 = NULL, *tree2;
559 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
560 0f2b3dca 2018-12-22 stsp char *id_str1 = NULL, *id_str2;
561 79109fed 2018-03-27 stsp
562 45d799e2 2018-12-23 stsp err = got_object_open_as_tree(&tree2, repo,
563 45d799e2 2018-12-23 stsp got_object_commit_get_tree_id(commit));
564 79109fed 2018-03-27 stsp if (err)
565 79109fed 2018-03-27 stsp return err;
566 79109fed 2018-03-27 stsp
567 45d799e2 2018-12-23 stsp qid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
568 79f35eb3 2018-06-11 stsp if (qid != NULL) {
569 79109fed 2018-03-27 stsp struct got_commit_object *pcommit;
570 79109fed 2018-03-27 stsp
571 117e771c 2018-07-23 stsp err = got_object_open_as_commit(&pcommit, repo, qid->id);
572 79109fed 2018-03-27 stsp if (err)
573 79109fed 2018-03-27 stsp return err;
574 79109fed 2018-03-27 stsp
575 45d799e2 2018-12-23 stsp err = got_object_open_as_tree(&tree1, repo,
576 45d799e2 2018-12-23 stsp got_object_commit_get_tree_id(pcommit));
577 79109fed 2018-03-27 stsp got_object_commit_close(pcommit);
578 0f2b3dca 2018-12-22 stsp if (err)
579 0f2b3dca 2018-12-22 stsp return err;
580 0f2b3dca 2018-12-22 stsp
581 0f2b3dca 2018-12-22 stsp err = got_object_id_str(&id_str1, qid->id);
582 79109fed 2018-03-27 stsp if (err)
583 79109fed 2018-03-27 stsp return err;
584 79109fed 2018-03-27 stsp }
585 79109fed 2018-03-27 stsp
586 0f2b3dca 2018-12-22 stsp err = got_object_id_str(&id_str2, id);
587 0f2b3dca 2018-12-22 stsp if (err)
588 0f2b3dca 2018-12-22 stsp goto done;
589 0f2b3dca 2018-12-22 stsp
590 56765ebb 2018-12-23 stsp printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
591 54156555 2018-12-24 stsp err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
592 0f2b3dca 2018-12-22 stsp done:
593 79109fed 2018-03-27 stsp if (tree1)
594 79109fed 2018-03-27 stsp got_object_tree_close(tree1);
595 79109fed 2018-03-27 stsp got_object_tree_close(tree2);
596 0f2b3dca 2018-12-22 stsp free(id_str1);
597 0f2b3dca 2018-12-22 stsp free(id_str2);
598 79109fed 2018-03-27 stsp return err;
599 79109fed 2018-03-27 stsp }
600 79109fed 2018-03-27 stsp
601 4bb494d5 2018-06-16 stsp static char *
602 6c281f94 2018-06-11 stsp get_datestr(time_t *time, char *datebuf)
603 6c281f94 2018-06-11 stsp {
604 6c281f94 2018-06-11 stsp char *p, *s = ctime_r(time, datebuf);
605 6c281f94 2018-06-11 stsp p = strchr(s, '\n');
606 6c281f94 2018-06-11 stsp if (p)
607 6c281f94 2018-06-11 stsp *p = '\0';
608 6c281f94 2018-06-11 stsp return s;
609 6c281f94 2018-06-11 stsp }
610 6c281f94 2018-06-11 stsp
611 79109fed 2018-03-27 stsp static const struct got_error *
612 79109fed 2018-03-27 stsp print_commit(struct got_commit_object *commit, struct got_object_id *id,
613 199a4027 2019-02-02 stsp struct got_repository *repo, int show_patch, int diff_context,
614 199a4027 2019-02-02 stsp struct got_reflist_head *refs)
615 79109fed 2018-03-27 stsp {
616 79109fed 2018-03-27 stsp const struct got_error *err = NULL;
617 621015ac 2018-07-23 stsp char *id_str, *datestr, *logmsg0, *logmsg, *line;
618 6c281f94 2018-06-11 stsp char datebuf[26];
619 45d799e2 2018-12-23 stsp time_t committer_time;
620 45d799e2 2018-12-23 stsp const char *author, *committer;
621 199a4027 2019-02-02 stsp char *refs_str = NULL;
622 199a4027 2019-02-02 stsp struct got_reflist_entry *re;
623 5c860e29 2018-03-12 stsp
624 199a4027 2019-02-02 stsp SIMPLEQ_FOREACH(re, refs, entry) {
625 199a4027 2019-02-02 stsp char *s;
626 199a4027 2019-02-02 stsp const char *name;
627 199a4027 2019-02-02 stsp if (got_object_id_cmp(re->id, id) != 0)
628 199a4027 2019-02-02 stsp continue;
629 199a4027 2019-02-02 stsp name = got_ref_get_name(re->ref);
630 199a4027 2019-02-02 stsp if (strncmp(name, "refs/", 5) == 0)
631 199a4027 2019-02-02 stsp name += 5;
632 e34f9ed6 2019-02-02 stsp if (strncmp(name, "heads/", 6) == 0)
633 e34f9ed6 2019-02-02 stsp name += 6;
634 141c2bff 2019-02-04 stsp if (strncmp(name, "remotes/", 8) == 0)
635 141c2bff 2019-02-04 stsp name += 8;
636 199a4027 2019-02-02 stsp s = refs_str;
637 199a4027 2019-02-02 stsp if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
638 199a4027 2019-02-02 stsp name) == -1) {
639 199a4027 2019-02-02 stsp err = got_error_from_errno();
640 199a4027 2019-02-02 stsp free(s);
641 199a4027 2019-02-02 stsp break;
642 199a4027 2019-02-02 stsp }
643 199a4027 2019-02-02 stsp free(s);
644 199a4027 2019-02-02 stsp }
645 832c249c 2018-06-10 stsp err = got_object_id_str(&id_str, id);
646 8bf5b3c9 2018-03-17 stsp if (err)
647 8bf5b3c9 2018-03-17 stsp return err;
648 788c352e 2018-06-16 stsp
649 33d869be 2018-12-22 stsp printf("-----------------------------------------------\n");
650 199a4027 2019-02-02 stsp printf("commit %s%s%s%s\n", id_str, refs_str ? " (" : "",
651 199a4027 2019-02-02 stsp refs_str ? refs_str : "", refs_str ? ")" : "");
652 832c249c 2018-06-10 stsp free(id_str);
653 45d799e2 2018-12-23 stsp printf("from: %s\n", got_object_commit_get_author(commit));
654 45d799e2 2018-12-23 stsp committer_time = got_object_commit_get_committer_time(commit);
655 45d799e2 2018-12-23 stsp datestr = get_datestr(&committer_time, datebuf);
656 dab5fe87 2018-09-14 stsp printf("date: %s UTC\n", datestr);
657 45d799e2 2018-12-23 stsp author = got_object_commit_get_author(commit);
658 45d799e2 2018-12-23 stsp committer = got_object_commit_get_committer(commit);
659 45d799e2 2018-12-23 stsp if (strcmp(author, committer) != 0)
660 45d799e2 2018-12-23 stsp printf("via: %s\n", committer);
661 45d799e2 2018-12-23 stsp if (got_object_commit_get_nparents(commit) > 1) {
662 45d799e2 2018-12-23 stsp const struct got_object_id_queue *parent_ids;
663 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
664 3fe1abad 2018-06-10 stsp int n = 1;
665 45d799e2 2018-12-23 stsp parent_ids = got_object_commit_get_parent_ids(commit);
666 45d799e2 2018-12-23 stsp SIMPLEQ_FOREACH(qid, parent_ids, entry) {
667 79f35eb3 2018-06-11 stsp err = got_object_id_str(&id_str, qid->id);
668 a0603db2 2018-06-10 stsp if (err)
669 a0603db2 2018-06-10 stsp return err;
670 3fe1abad 2018-06-10 stsp printf("parent %d: %s\n", n++, id_str);
671 a0603db2 2018-06-10 stsp free(id_str);
672 a0603db2 2018-06-10 stsp }
673 a0603db2 2018-06-10 stsp }
674 832c249c 2018-06-10 stsp
675 45d799e2 2018-12-23 stsp logmsg0 = strdup(got_object_commit_get_logmsg(commit));
676 621015ac 2018-07-23 stsp if (logmsg0 == NULL)
677 832c249c 2018-06-10 stsp return got_error_from_errno();
678 8bf5b3c9 2018-03-17 stsp
679 621015ac 2018-07-23 stsp logmsg = logmsg0;
680 832c249c 2018-06-10 stsp do {
681 832c249c 2018-06-10 stsp line = strsep(&logmsg, "\n");
682 832c249c 2018-06-10 stsp if (line)
683 832c249c 2018-06-10 stsp printf(" %s\n", line);
684 832c249c 2018-06-10 stsp } while (line);
685 621015ac 2018-07-23 stsp free(logmsg0);
686 832c249c 2018-06-10 stsp
687 971751ac 2018-03-27 stsp if (show_patch) {
688 c0cc5c62 2018-10-18 stsp err = print_patch(commit, id, diff_context, repo);
689 971751ac 2018-03-27 stsp if (err == 0)
690 971751ac 2018-03-27 stsp printf("\n");
691 971751ac 2018-03-27 stsp }
692 07862c20 2018-09-15 stsp
693 d82de447 2018-09-15 stsp fflush(stdout);
694 07862c20 2018-09-15 stsp return err;
695 f42b1b34 2018-03-12 stsp }
696 5c860e29 2018-03-12 stsp
697 f42b1b34 2018-03-12 stsp static const struct got_error *
698 15a94983 2018-12-23 stsp print_commits(struct got_object_id *root_id, struct got_repository *repo,
699 15a94983 2018-12-23 stsp char *path, int show_patch, int diff_context, int limit,
700 199a4027 2019-02-02 stsp int first_parent_traversal, struct got_reflist_head *refs)
701 f42b1b34 2018-03-12 stsp {
702 f42b1b34 2018-03-12 stsp const struct got_error *err;
703 372ccdbb 2018-06-10 stsp struct got_commit_graph *graph;
704 372ccdbb 2018-06-10 stsp
705 31cedeaf 2018-09-15 stsp err = got_commit_graph_open(&graph, root_id, path,
706 31cedeaf 2018-09-15 stsp first_parent_traversal, repo);
707 f42b1b34 2018-03-12 stsp if (err)
708 f42b1b34 2018-03-12 stsp return err;
709 31cedeaf 2018-09-15 stsp err = got_commit_graph_iter_start(graph, root_id, repo);
710 372ccdbb 2018-06-10 stsp if (err)
711 fcc85cad 2018-07-22 stsp goto done;
712 31cedeaf 2018-09-15 stsp while (1) {
713 372ccdbb 2018-06-10 stsp struct got_commit_object *commit;
714 372ccdbb 2018-06-10 stsp struct got_object_id *id;
715 8bf5b3c9 2018-03-17 stsp
716 84453469 2018-11-11 stsp if (sigint_received || sigpipe_received)
717 84453469 2018-11-11 stsp break;
718 84453469 2018-11-11 stsp
719 b43fbaa0 2018-06-11 stsp err = got_commit_graph_iter_next(&id, graph);
720 372ccdbb 2018-06-10 stsp if (err) {
721 9ba79e04 2018-06-11 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
722 9ba79e04 2018-06-11 stsp err = NULL;
723 9ba79e04 2018-06-11 stsp break;
724 9ba79e04 2018-06-11 stsp }
725 372ccdbb 2018-06-10 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
726 372ccdbb 2018-06-10 stsp break;
727 31cedeaf 2018-09-15 stsp err = got_commit_graph_fetch_commits(graph, 1, repo);
728 372ccdbb 2018-06-10 stsp if (err)
729 372ccdbb 2018-06-10 stsp break;
730 372ccdbb 2018-06-10 stsp else
731 372ccdbb 2018-06-10 stsp continue;
732 7e665116 2018-04-02 stsp }
733 b43fbaa0 2018-06-11 stsp if (id == NULL)
734 7e665116 2018-04-02 stsp break;
735 b43fbaa0 2018-06-11 stsp
736 f8e900f3 2018-06-11 stsp err = got_object_open_as_commit(&commit, repo, id);
737 b43fbaa0 2018-06-11 stsp if (err)
738 fcc85cad 2018-07-22 stsp break;
739 199a4027 2019-02-02 stsp err = print_commit(commit, id, repo, show_patch, diff_context,
740 199a4027 2019-02-02 stsp refs);
741 b43fbaa0 2018-06-11 stsp got_object_commit_close(commit);
742 372ccdbb 2018-06-10 stsp if (err || (limit && --limit == 0))
743 7e665116 2018-04-02 stsp break;
744 31cedeaf 2018-09-15 stsp }
745 fcc85cad 2018-07-22 stsp done:
746 372ccdbb 2018-06-10 stsp got_commit_graph_close(graph);
747 f42b1b34 2018-03-12 stsp return err;
748 f42b1b34 2018-03-12 stsp }
749 5c860e29 2018-03-12 stsp
750 4ed7e80c 2018-05-20 stsp __dead static void
751 6f3d1eb0 2018-03-12 stsp usage_log(void)
752 6f3d1eb0 2018-03-12 stsp {
753 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
754 04ca23f4 2018-07-16 stsp "[-r repository-path] [path]\n", getprogname());
755 6f3d1eb0 2018-03-12 stsp exit(1);
756 6f3d1eb0 2018-03-12 stsp }
757 6f3d1eb0 2018-03-12 stsp
758 4ed7e80c 2018-05-20 stsp static const struct got_error *
759 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
760 f42b1b34 2018-03-12 stsp {
761 f42b1b34 2018-03-12 stsp const struct got_error *error;
762 04ca23f4 2018-07-16 stsp struct got_repository *repo = NULL;
763 15a94983 2018-12-23 stsp struct got_commit_object *commit = NULL;
764 3235492e 2018-04-01 stsp struct got_object_id *id = NULL;
765 04ca23f4 2018-07-16 stsp char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
766 d142fc45 2018-04-01 stsp char *start_commit = NULL;
767 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
768 1fd6d7ea 2018-06-13 stsp int show_patch = 0, limit = 0, first_parent_traversal = 0;
769 64a96a6d 2018-04-01 stsp const char *errstr;
770 199a4027 2019-02-02 stsp struct got_reflist_head refs;
771 5c860e29 2018-03-12 stsp
772 6715a751 2018-03-16 stsp #ifndef PROFILE
773 6098196c 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
774 6098196c 2019-01-04 stsp NULL)
775 ad242220 2018-09-08 stsp == -1)
776 f42b1b34 2018-03-12 stsp err(1, "pledge");
777 6715a751 2018-03-16 stsp #endif
778 79109fed 2018-03-27 stsp
779 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
780 79109fed 2018-03-27 stsp switch (ch) {
781 79109fed 2018-03-27 stsp case 'p':
782 79109fed 2018-03-27 stsp show_patch = 1;
783 d142fc45 2018-04-01 stsp break;
784 d142fc45 2018-04-01 stsp case 'c':
785 d142fc45 2018-04-01 stsp start_commit = optarg;
786 64a96a6d 2018-04-01 stsp break;
787 c0cc5c62 2018-10-18 stsp case 'C':
788 4a8520aa 2018-10-18 stsp diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
789 4a8520aa 2018-10-18 stsp &errstr);
790 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
791 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
792 c0cc5c62 2018-10-18 stsp break;
793 64a96a6d 2018-04-01 stsp case 'l':
794 64a96a6d 2018-04-01 stsp limit = strtonum(optarg, 1, INT_MAX, &errstr);
795 64a96a6d 2018-04-01 stsp if (errstr != NULL)
796 64a96a6d 2018-04-01 stsp err(1, "-l option %s", errstr);
797 79109fed 2018-03-27 stsp break;
798 0ed6ed4c 2018-06-13 stsp case 'f':
799 0ed6ed4c 2018-06-13 stsp first_parent_traversal = 1;
800 a0603db2 2018-06-10 stsp break;
801 04ca23f4 2018-07-16 stsp case 'r':
802 04ca23f4 2018-07-16 stsp repo_path = realpath(optarg, NULL);
803 04ca23f4 2018-07-16 stsp if (repo_path == NULL)
804 04ca23f4 2018-07-16 stsp err(1, "-r option");
805 04ca23f4 2018-07-16 stsp break;
806 79109fed 2018-03-27 stsp default:
807 79109fed 2018-03-27 stsp usage();
808 79109fed 2018-03-27 stsp /* NOTREACHED */
809 79109fed 2018-03-27 stsp }
810 79109fed 2018-03-27 stsp }
811 79109fed 2018-03-27 stsp
812 79109fed 2018-03-27 stsp argc -= optind;
813 79109fed 2018-03-27 stsp argv += optind;
814 79109fed 2018-03-27 stsp
815 04ca23f4 2018-07-16 stsp if (argc == 0)
816 04ca23f4 2018-07-16 stsp path = strdup("");
817 04ca23f4 2018-07-16 stsp else if (argc == 1)
818 04ca23f4 2018-07-16 stsp path = strdup(argv[0]);
819 04ca23f4 2018-07-16 stsp else
820 6f3d1eb0 2018-03-12 stsp usage_log();
821 04ca23f4 2018-07-16 stsp if (path == NULL)
822 04ca23f4 2018-07-16 stsp return got_error_from_errno();
823 f42b1b34 2018-03-12 stsp
824 04ca23f4 2018-07-16 stsp cwd = getcwd(NULL, 0);
825 04ca23f4 2018-07-16 stsp if (cwd == NULL) {
826 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
827 04ca23f4 2018-07-16 stsp goto done;
828 04ca23f4 2018-07-16 stsp }
829 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
830 04ca23f4 2018-07-16 stsp repo_path = strdup(cwd);
831 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
832 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
833 04ca23f4 2018-07-16 stsp goto done;
834 04ca23f4 2018-07-16 stsp }
835 04ca23f4 2018-07-16 stsp }
836 04ca23f4 2018-07-16 stsp
837 6098196c 2019-01-04 stsp error = apply_unveil(repo_path, NULL);
838 6098196c 2019-01-04 stsp if (error)
839 6098196c 2019-01-04 stsp goto done;
840 6098196c 2019-01-04 stsp
841 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
842 d7d4f210 2018-03-12 stsp if (error != NULL)
843 04ca23f4 2018-07-16 stsp goto done;
844 f42b1b34 2018-03-12 stsp
845 d142fc45 2018-04-01 stsp if (start_commit == NULL) {
846 3235492e 2018-04-01 stsp struct got_reference *head_ref;
847 3235492e 2018-04-01 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
848 3235492e 2018-04-01 stsp if (error != NULL)
849 3235492e 2018-04-01 stsp return error;
850 3235492e 2018-04-01 stsp error = got_ref_resolve(&id, repo, head_ref);
851 3235492e 2018-04-01 stsp got_ref_close(head_ref);
852 3235492e 2018-04-01 stsp if (error != NULL)
853 3235492e 2018-04-01 stsp return error;
854 15a94983 2018-12-23 stsp error = got_object_open_as_commit(&commit, repo, id);
855 3235492e 2018-04-01 stsp } else {
856 d1f2edc9 2018-06-13 stsp struct got_reference *ref;
857 d1f2edc9 2018-06-13 stsp error = got_ref_open(&ref, repo, start_commit);
858 3235492e 2018-04-01 stsp if (error == NULL) {
859 1caad61b 2019-02-01 stsp int obj_type;
860 d1f2edc9 2018-06-13 stsp error = got_ref_resolve(&id, repo, ref);
861 d1f2edc9 2018-06-13 stsp got_ref_close(ref);
862 d1f2edc9 2018-06-13 stsp if (error != NULL)
863 1caad61b 2019-02-01 stsp goto done;
864 1caad61b 2019-02-01 stsp error = got_object_get_type(&obj_type, repo, id);
865 1caad61b 2019-02-01 stsp if (error != NULL)
866 1caad61b 2019-02-01 stsp goto done;
867 1caad61b 2019-02-01 stsp if (obj_type == GOT_OBJ_TYPE_TAG) {
868 1caad61b 2019-02-01 stsp struct got_tag_object *tag;
869 1caad61b 2019-02-01 stsp error = got_object_open_as_tag(&tag, repo, id);
870 1caad61b 2019-02-01 stsp if (error != NULL)
871 1caad61b 2019-02-01 stsp goto done;
872 1caad61b 2019-02-01 stsp if (got_object_tag_get_object_type(tag) !=
873 1caad61b 2019-02-01 stsp GOT_OBJ_TYPE_COMMIT) {
874 1caad61b 2019-02-01 stsp got_object_tag_close(tag);
875 1caad61b 2019-02-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
876 1caad61b 2019-02-01 stsp goto done;
877 1caad61b 2019-02-01 stsp }
878 1caad61b 2019-02-01 stsp free(id);
879 1caad61b 2019-02-01 stsp id = got_object_id_dup(
880 1caad61b 2019-02-01 stsp got_object_tag_get_object_id(tag));
881 1caad61b 2019-02-01 stsp if (id == NULL)
882 1caad61b 2019-02-01 stsp error = got_error_from_errno();
883 1caad61b 2019-02-01 stsp got_object_tag_close(tag);
884 1caad61b 2019-02-01 stsp if (error)
885 1caad61b 2019-02-01 stsp goto done;
886 1caad61b 2019-02-01 stsp } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
887 1caad61b 2019-02-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
888 1caad61b 2019-02-01 stsp goto done;
889 1caad61b 2019-02-01 stsp }
890 15a94983 2018-12-23 stsp error = got_object_open_as_commit(&commit, repo, id);
891 d1f2edc9 2018-06-13 stsp if (error != NULL)
892 1caad61b 2019-02-01 stsp goto done;
893 d1f2edc9 2018-06-13 stsp }
894 15a94983 2018-12-23 stsp if (commit == NULL) {
895 15a94983 2018-12-23 stsp error = got_object_resolve_id_str(&id, repo,
896 d1f2edc9 2018-06-13 stsp start_commit);
897 d1f2edc9 2018-06-13 stsp if (error != NULL)
898 d1f2edc9 2018-06-13 stsp return error;
899 3235492e 2018-04-01 stsp }
900 3235492e 2018-04-01 stsp }
901 d7d4f210 2018-03-12 stsp if (error != NULL)
902 04ca23f4 2018-07-16 stsp goto done;
903 04ca23f4 2018-07-16 stsp
904 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
905 04ca23f4 2018-07-16 stsp if (error != NULL)
906 04ca23f4 2018-07-16 stsp goto done;
907 04ca23f4 2018-07-16 stsp if (in_repo_path) {
908 04ca23f4 2018-07-16 stsp free(path);
909 04ca23f4 2018-07-16 stsp path = in_repo_path;
910 04ca23f4 2018-07-16 stsp }
911 199a4027 2019-02-02 stsp
912 199a4027 2019-02-02 stsp SIMPLEQ_INIT(&refs);
913 199a4027 2019-02-02 stsp error = got_ref_list(&refs, repo);
914 199a4027 2019-02-02 stsp if (error)
915 199a4027 2019-02-02 stsp goto done;
916 04ca23f4 2018-07-16 stsp
917 15a94983 2018-12-23 stsp error = print_commits(id, repo, path, show_patch,
918 199a4027 2019-02-02 stsp diff_context, limit, first_parent_traversal, &refs);
919 04ca23f4 2018-07-16 stsp done:
920 04ca23f4 2018-07-16 stsp free(path);
921 04ca23f4 2018-07-16 stsp free(repo_path);
922 04ca23f4 2018-07-16 stsp free(cwd);
923 f42b1b34 2018-03-12 stsp free(id);
924 ad242220 2018-09-08 stsp if (repo) {
925 ad242220 2018-09-08 stsp const struct got_error *repo_error;
926 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
927 ad242220 2018-09-08 stsp if (error == NULL)
928 ad242220 2018-09-08 stsp error = repo_error;
929 ad242220 2018-09-08 stsp }
930 8bf5b3c9 2018-03-17 stsp return error;
931 5c860e29 2018-03-12 stsp }
932 5c860e29 2018-03-12 stsp
933 4ed7e80c 2018-05-20 stsp __dead static void
934 3f8b7d6a 2018-04-01 stsp usage_diff(void)
935 3f8b7d6a 2018-04-01 stsp {
936 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
937 c0cc5c62 2018-10-18 stsp "object1 object2\n", getprogname());
938 3f8b7d6a 2018-04-01 stsp exit(1);
939 b00d56cd 2018-04-01 stsp }
940 b00d56cd 2018-04-01 stsp
941 4ed7e80c 2018-05-20 stsp static const struct got_error *
942 b00d56cd 2018-04-01 stsp cmd_diff(int argc, char *argv[])
943 b00d56cd 2018-04-01 stsp {
944 b00d56cd 2018-04-01 stsp const struct got_error *error;
945 b00d56cd 2018-04-01 stsp struct got_repository *repo = NULL;
946 b00d56cd 2018-04-01 stsp char *repo_path = NULL;
947 15a94983 2018-12-23 stsp struct got_object_id *id1 = NULL, *id2 = NULL;
948 15a94983 2018-12-23 stsp char *id_str1 = NULL, *id_str2 = NULL;
949 15a94983 2018-12-23 stsp int type1, type2;
950 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
951 c0cc5c62 2018-10-18 stsp const char *errstr;
952 b00d56cd 2018-04-01 stsp
953 b00d56cd 2018-04-01 stsp #ifndef PROFILE
954 25eccc22 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
955 25eccc22 2019-01-04 stsp NULL) == -1)
956 b00d56cd 2018-04-01 stsp err(1, "pledge");
957 b00d56cd 2018-04-01 stsp #endif
958 b00d56cd 2018-04-01 stsp
959 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "C:")) != -1) {
960 b00d56cd 2018-04-01 stsp switch (ch) {
961 c0cc5c62 2018-10-18 stsp case 'C':
962 c0cc5c62 2018-10-18 stsp diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
963 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
964 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
965 c0cc5c62 2018-10-18 stsp break;
966 b00d56cd 2018-04-01 stsp default:
967 b00d56cd 2018-04-01 stsp usage();
968 b00d56cd 2018-04-01 stsp /* NOTREACHED */
969 b00d56cd 2018-04-01 stsp }
970 b00d56cd 2018-04-01 stsp }
971 b00d56cd 2018-04-01 stsp
972 b00d56cd 2018-04-01 stsp argc -= optind;
973 b00d56cd 2018-04-01 stsp argv += optind;
974 b00d56cd 2018-04-01 stsp
975 b00d56cd 2018-04-01 stsp if (argc == 0) {
976 b00d56cd 2018-04-01 stsp usage_diff(); /* TODO show local worktree changes */
977 3f8b7d6a 2018-04-01 stsp } else if (argc == 2) {
978 3f8b7d6a 2018-04-01 stsp repo_path = getcwd(NULL, 0);
979 3f8b7d6a 2018-04-01 stsp if (repo_path == NULL)
980 e1e3f570 2018-04-01 stsp return got_error_from_errno();
981 15a94983 2018-12-23 stsp id_str1 = argv[0];
982 15a94983 2018-12-23 stsp id_str2 = argv[1];
983 b00d56cd 2018-04-01 stsp } else if (argc == 3) {
984 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
985 76089277 2018-04-01 stsp if (repo_path == NULL)
986 76089277 2018-04-01 stsp return got_error_from_errno();
987 15a94983 2018-12-23 stsp id_str1 = argv[1];
988 15a94983 2018-12-23 stsp id_str2 = argv[2];
989 b00d56cd 2018-04-01 stsp } else
990 b00d56cd 2018-04-01 stsp usage_diff();
991 25eccc22 2019-01-04 stsp
992 25eccc22 2019-01-04 stsp error = apply_unveil(repo_path, NULL);
993 25eccc22 2019-01-04 stsp if (error)
994 25eccc22 2019-01-04 stsp goto done;
995 b00d56cd 2018-04-01 stsp
996 b00d56cd 2018-04-01 stsp error = got_repo_open(&repo, repo_path);
997 76089277 2018-04-01 stsp free(repo_path);
998 b00d56cd 2018-04-01 stsp if (error != NULL)
999 b00d56cd 2018-04-01 stsp goto done;
1000 b00d56cd 2018-04-01 stsp
1001 15a94983 2018-12-23 stsp error = got_object_resolve_id_str(&id1, repo, id_str1);
1002 6402fb3c 2018-09-15 stsp if (error)
1003 b00d56cd 2018-04-01 stsp goto done;
1004 b00d56cd 2018-04-01 stsp
1005 15a94983 2018-12-23 stsp error = got_object_resolve_id_str(&id2, repo, id_str2);
1006 6402fb3c 2018-09-15 stsp if (error)
1007 b00d56cd 2018-04-01 stsp goto done;
1008 b00d56cd 2018-04-01 stsp
1009 15a94983 2018-12-23 stsp error = got_object_get_type(&type1, repo, id1);
1010 15a94983 2018-12-23 stsp if (error)
1011 15a94983 2018-12-23 stsp goto done;
1012 15a94983 2018-12-23 stsp
1013 15a94983 2018-12-23 stsp error = got_object_get_type(&type2, repo, id2);
1014 15a94983 2018-12-23 stsp if (error)
1015 15a94983 2018-12-23 stsp goto done;
1016 15a94983 2018-12-23 stsp
1017 15a94983 2018-12-23 stsp if (type1 != type2) {
1018 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
1019 b00d56cd 2018-04-01 stsp goto done;
1020 b00d56cd 2018-04-01 stsp }
1021 b00d56cd 2018-04-01 stsp
1022 15a94983 2018-12-23 stsp switch (type1) {
1023 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_BLOB:
1024 15a94983 2018-12-23 stsp error = got_diff_objects_as_blobs(id1, id2, NULL, NULL,
1025 54156555 2018-12-24 stsp diff_context, repo, stdout);
1026 b00d56cd 2018-04-01 stsp break;
1027 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_TREE:
1028 15a94983 2018-12-23 stsp error = got_diff_objects_as_trees(id1, id2, "", "",
1029 54156555 2018-12-24 stsp diff_context, repo, stdout);
1030 b00d56cd 2018-04-01 stsp break;
1031 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_COMMIT:
1032 15a94983 2018-12-23 stsp printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null",
1033 15a94983 2018-12-23 stsp id_str2);
1034 15a94983 2018-12-23 stsp error = got_diff_objects_as_commits(id1, id2, diff_context,
1035 c0cc5c62 2018-10-18 stsp repo, stdout);
1036 b00d56cd 2018-04-01 stsp break;
1037 b00d56cd 2018-04-01 stsp default:
1038 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
1039 b00d56cd 2018-04-01 stsp }
1040 b00d56cd 2018-04-01 stsp
1041 b00d56cd 2018-04-01 stsp done:
1042 15a94983 2018-12-23 stsp free(id1);
1043 15a94983 2018-12-23 stsp free(id2);
1044 ad242220 2018-09-08 stsp if (repo) {
1045 ad242220 2018-09-08 stsp const struct got_error *repo_error;
1046 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
1047 ad242220 2018-09-08 stsp if (error == NULL)
1048 ad242220 2018-09-08 stsp error = repo_error;
1049 ad242220 2018-09-08 stsp }
1050 b00d56cd 2018-04-01 stsp return error;
1051 404c43c4 2018-06-21 stsp }
1052 404c43c4 2018-06-21 stsp
1053 404c43c4 2018-06-21 stsp __dead static void
1054 404c43c4 2018-06-21 stsp usage_blame(void)
1055 404c43c4 2018-06-21 stsp {
1056 66bea077 2018-08-02 stsp fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
1057 404c43c4 2018-06-21 stsp getprogname());
1058 404c43c4 2018-06-21 stsp exit(1);
1059 b00d56cd 2018-04-01 stsp }
1060 b00d56cd 2018-04-01 stsp
1061 404c43c4 2018-06-21 stsp static const struct got_error *
1062 404c43c4 2018-06-21 stsp cmd_blame(int argc, char *argv[])
1063 404c43c4 2018-06-21 stsp {
1064 404c43c4 2018-06-21 stsp const struct got_error *error;
1065 404c43c4 2018-06-21 stsp struct got_repository *repo = NULL;
1066 66bea077 2018-08-02 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1067 404c43c4 2018-06-21 stsp struct got_object_id *commit_id = NULL;
1068 404c43c4 2018-06-21 stsp char *commit_id_str = NULL;
1069 404c43c4 2018-06-21 stsp int ch;
1070 404c43c4 2018-06-21 stsp
1071 404c43c4 2018-06-21 stsp #ifndef PROFILE
1072 36e2fb66 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1073 36e2fb66 2019-01-04 stsp NULL) == -1)
1074 404c43c4 2018-06-21 stsp err(1, "pledge");
1075 404c43c4 2018-06-21 stsp #endif
1076 404c43c4 2018-06-21 stsp
1077 66bea077 2018-08-02 stsp while ((ch = getopt(argc, argv, "c:r:")) != -1) {
1078 404c43c4 2018-06-21 stsp switch (ch) {
1079 404c43c4 2018-06-21 stsp case 'c':
1080 404c43c4 2018-06-21 stsp commit_id_str = optarg;
1081 404c43c4 2018-06-21 stsp break;
1082 66bea077 2018-08-02 stsp case 'r':
1083 66bea077 2018-08-02 stsp repo_path = realpath(optarg, NULL);
1084 66bea077 2018-08-02 stsp if (repo_path == NULL)
1085 66bea077 2018-08-02 stsp err(1, "-r option");
1086 66bea077 2018-08-02 stsp break;
1087 404c43c4 2018-06-21 stsp default:
1088 404c43c4 2018-06-21 stsp usage();
1089 404c43c4 2018-06-21 stsp /* NOTREACHED */
1090 404c43c4 2018-06-21 stsp }
1091 404c43c4 2018-06-21 stsp }
1092 404c43c4 2018-06-21 stsp
1093 404c43c4 2018-06-21 stsp argc -= optind;
1094 404c43c4 2018-06-21 stsp argv += optind;
1095 404c43c4 2018-06-21 stsp
1096 a39318fd 2018-08-02 stsp if (argc == 1)
1097 404c43c4 2018-06-21 stsp path = argv[0];
1098 a39318fd 2018-08-02 stsp else
1099 404c43c4 2018-06-21 stsp usage_blame();
1100 404c43c4 2018-06-21 stsp
1101 66bea077 2018-08-02 stsp cwd = getcwd(NULL, 0);
1102 66bea077 2018-08-02 stsp if (cwd == NULL) {
1103 66bea077 2018-08-02 stsp error = got_error_from_errno();
1104 66bea077 2018-08-02 stsp goto done;
1105 66bea077 2018-08-02 stsp }
1106 66bea077 2018-08-02 stsp if (repo_path == NULL) {
1107 66bea077 2018-08-02 stsp repo_path = strdup(cwd);
1108 66bea077 2018-08-02 stsp if (repo_path == NULL) {
1109 66bea077 2018-08-02 stsp error = got_error_from_errno();
1110 66bea077 2018-08-02 stsp goto done;
1111 66bea077 2018-08-02 stsp }
1112 66bea077 2018-08-02 stsp }
1113 36e2fb66 2019-01-04 stsp
1114 36e2fb66 2019-01-04 stsp error = apply_unveil(repo_path, NULL);
1115 36e2fb66 2019-01-04 stsp if (error)
1116 36e2fb66 2019-01-04 stsp goto done;
1117 66bea077 2018-08-02 stsp
1118 404c43c4 2018-06-21 stsp error = got_repo_open(&repo, repo_path);
1119 404c43c4 2018-06-21 stsp if (error != NULL)
1120 404c43c4 2018-06-21 stsp goto done;
1121 404c43c4 2018-06-21 stsp
1122 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
1123 66bea077 2018-08-02 stsp if (error != NULL)
1124 66bea077 2018-08-02 stsp goto done;
1125 66bea077 2018-08-02 stsp
1126 404c43c4 2018-06-21 stsp if (commit_id_str == NULL) {
1127 404c43c4 2018-06-21 stsp struct got_reference *head_ref;
1128 404c43c4 2018-06-21 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
1129 404c43c4 2018-06-21 stsp if (error != NULL)
1130 66bea077 2018-08-02 stsp goto done;
1131 404c43c4 2018-06-21 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
1132 404c43c4 2018-06-21 stsp got_ref_close(head_ref);
1133 404c43c4 2018-06-21 stsp if (error != NULL)
1134 66bea077 2018-08-02 stsp goto done;
1135 404c43c4 2018-06-21 stsp } else {
1136 15a94983 2018-12-23 stsp error = got_object_resolve_id_str(&commit_id, repo,
1137 15a94983 2018-12-23 stsp commit_id_str);
1138 404c43c4 2018-06-21 stsp if (error != NULL)
1139 66bea077 2018-08-02 stsp goto done;
1140 404c43c4 2018-06-21 stsp }
1141 404c43c4 2018-06-21 stsp
1142 66bea077 2018-08-02 stsp error = got_blame(in_repo_path, commit_id, repo, stdout);
1143 404c43c4 2018-06-21 stsp done:
1144 66bea077 2018-08-02 stsp free(in_repo_path);
1145 66bea077 2018-08-02 stsp free(repo_path);
1146 66bea077 2018-08-02 stsp free(cwd);
1147 404c43c4 2018-06-21 stsp free(commit_id);
1148 ad242220 2018-09-08 stsp if (repo) {
1149 ad242220 2018-09-08 stsp const struct got_error *repo_error;
1150 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
1151 ad242220 2018-09-08 stsp if (error == NULL)
1152 ad242220 2018-09-08 stsp error = repo_error;
1153 ad242220 2018-09-08 stsp }
1154 404c43c4 2018-06-21 stsp return error;
1155 5de5890b 2018-10-18 stsp }
1156 5de5890b 2018-10-18 stsp
1157 5de5890b 2018-10-18 stsp __dead static void
1158 5de5890b 2018-10-18 stsp usage_tree(void)
1159 5de5890b 2018-10-18 stsp {
1160 c1669e2e 2019-01-09 stsp fprintf(stderr,
1161 c1669e2e 2019-01-09 stsp "usage: %s tree [-c commit] [-r repository-path] [-iR] path\n",
1162 5de5890b 2018-10-18 stsp getprogname());
1163 5de5890b 2018-10-18 stsp exit(1);
1164 5de5890b 2018-10-18 stsp }
1165 5de5890b 2018-10-18 stsp
1166 c1669e2e 2019-01-09 stsp static void
1167 c1669e2e 2019-01-09 stsp print_entry(struct got_tree_entry *te, const char *id, const char *path,
1168 c1669e2e 2019-01-09 stsp const char *root_path)
1169 c1669e2e 2019-01-09 stsp {
1170 c1669e2e 2019-01-09 stsp int is_root_path = (strcmp(path, root_path) == 0);
1171 5de5890b 2018-10-18 stsp
1172 c1669e2e 2019-01-09 stsp path += strlen(root_path);
1173 c1669e2e 2019-01-09 stsp while (path[0] == '/')
1174 c1669e2e 2019-01-09 stsp path++;
1175 c1669e2e 2019-01-09 stsp
1176 c1669e2e 2019-01-09 stsp printf("%s%s%s%s%s\n", id ? id : "", path,
1177 c1669e2e 2019-01-09 stsp is_root_path ? "" : "/",
1178 c1669e2e 2019-01-09 stsp te->name, S_ISDIR(te->mode) ? "/" : "");
1179 c1669e2e 2019-01-09 stsp }
1180 c1669e2e 2019-01-09 stsp
1181 5de5890b 2018-10-18 stsp static const struct got_error *
1182 5de5890b 2018-10-18 stsp print_tree(const char *path, struct got_object_id *commit_id,
1183 c1669e2e 2019-01-09 stsp int show_ids, int recurse, const char *root_path,
1184 c1669e2e 2019-01-09 stsp struct got_repository *repo)
1185 5de5890b 2018-10-18 stsp {
1186 5de5890b 2018-10-18 stsp const struct got_error *err = NULL;
1187 5de5890b 2018-10-18 stsp struct got_object_id *tree_id = NULL;
1188 5de5890b 2018-10-18 stsp struct got_tree_object *tree = NULL;
1189 5de5890b 2018-10-18 stsp const struct got_tree_entries *entries;
1190 5de5890b 2018-10-18 stsp struct got_tree_entry *te;
1191 5de5890b 2018-10-18 stsp
1192 5de5890b 2018-10-18 stsp err = got_object_id_by_path(&tree_id, repo, commit_id, path);
1193 5de5890b 2018-10-18 stsp if (err)
1194 5de5890b 2018-10-18 stsp goto done;
1195 5de5890b 2018-10-18 stsp
1196 5de5890b 2018-10-18 stsp err = got_object_open_as_tree(&tree, repo, tree_id);
1197 5de5890b 2018-10-18 stsp if (err)
1198 5de5890b 2018-10-18 stsp goto done;
1199 5de5890b 2018-10-18 stsp entries = got_object_tree_get_entries(tree);
1200 5de5890b 2018-10-18 stsp te = SIMPLEQ_FIRST(&entries->head);
1201 5de5890b 2018-10-18 stsp while (te) {
1202 5de5890b 2018-10-18 stsp char *id = NULL;
1203 84453469 2018-11-11 stsp
1204 84453469 2018-11-11 stsp if (sigint_received || sigpipe_received)
1205 84453469 2018-11-11 stsp break;
1206 84453469 2018-11-11 stsp
1207 5de5890b 2018-10-18 stsp if (show_ids) {
1208 5de5890b 2018-10-18 stsp char *id_str;
1209 5de5890b 2018-10-18 stsp err = got_object_id_str(&id_str, te->id);
1210 5de5890b 2018-10-18 stsp if (err)
1211 5de5890b 2018-10-18 stsp goto done;
1212 5de5890b 2018-10-18 stsp if (asprintf(&id, "%s ", id_str) == -1) {
1213 5de5890b 2018-10-18 stsp err = got_error_from_errno();
1214 5de5890b 2018-10-18 stsp free(id_str);
1215 5de5890b 2018-10-18 stsp goto done;
1216 5de5890b 2018-10-18 stsp }
1217 5de5890b 2018-10-18 stsp free(id_str);
1218 5de5890b 2018-10-18 stsp }
1219 c1669e2e 2019-01-09 stsp print_entry(te, id, path, root_path);
1220 5de5890b 2018-10-18 stsp free(id);
1221 c1669e2e 2019-01-09 stsp
1222 c1669e2e 2019-01-09 stsp if (recurse && S_ISDIR(te->mode)) {
1223 c1669e2e 2019-01-09 stsp char *child_path;
1224 c1669e2e 2019-01-09 stsp if (asprintf(&child_path, "%s%s%s", path,
1225 c1669e2e 2019-01-09 stsp path[0] == '/' && path[1] == '\0' ? "" : "/",
1226 c1669e2e 2019-01-09 stsp te->name) == -1) {
1227 c1669e2e 2019-01-09 stsp err = got_error_from_errno();
1228 c1669e2e 2019-01-09 stsp goto done;
1229 c1669e2e 2019-01-09 stsp }
1230 c1669e2e 2019-01-09 stsp err = print_tree(child_path, commit_id, show_ids, 1,
1231 c1669e2e 2019-01-09 stsp root_path, repo);
1232 c1669e2e 2019-01-09 stsp free(child_path);
1233 c1669e2e 2019-01-09 stsp if (err)
1234 c1669e2e 2019-01-09 stsp goto done;
1235 c1669e2e 2019-01-09 stsp }
1236 c1669e2e 2019-01-09 stsp
1237 c1669e2e 2019-01-09 stsp te = SIMPLEQ_NEXT(te, entry);
1238 5de5890b 2018-10-18 stsp }
1239 5de5890b 2018-10-18 stsp done:
1240 5de5890b 2018-10-18 stsp if (tree)
1241 5de5890b 2018-10-18 stsp got_object_tree_close(tree);
1242 5de5890b 2018-10-18 stsp free(tree_id);
1243 5de5890b 2018-10-18 stsp return err;
1244 404c43c4 2018-06-21 stsp }
1245 404c43c4 2018-06-21 stsp
1246 5de5890b 2018-10-18 stsp static const struct got_error *
1247 5de5890b 2018-10-18 stsp cmd_tree(int argc, char *argv[])
1248 5de5890b 2018-10-18 stsp {
1249 5de5890b 2018-10-18 stsp const struct got_error *error;
1250 5de5890b 2018-10-18 stsp struct got_repository *repo = NULL;
1251 5de5890b 2018-10-18 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1252 5de5890b 2018-10-18 stsp struct got_object_id *commit_id = NULL;
1253 5de5890b 2018-10-18 stsp char *commit_id_str = NULL;
1254 c1669e2e 2019-01-09 stsp int show_ids = 0, recurse = 0;
1255 5de5890b 2018-10-18 stsp int ch;
1256 5de5890b 2018-10-18 stsp
1257 5de5890b 2018-10-18 stsp #ifndef PROFILE
1258 0f8d269b 2019-01-04 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
1259 0f8d269b 2019-01-04 stsp NULL) == -1)
1260 5de5890b 2018-10-18 stsp err(1, "pledge");
1261 5de5890b 2018-10-18 stsp #endif
1262 5de5890b 2018-10-18 stsp
1263 c1669e2e 2019-01-09 stsp while ((ch = getopt(argc, argv, "c:r:iR")) != -1) {
1264 5de5890b 2018-10-18 stsp switch (ch) {
1265 5de5890b 2018-10-18 stsp case 'c':
1266 5de5890b 2018-10-18 stsp commit_id_str = optarg;
1267 5de5890b 2018-10-18 stsp break;
1268 5de5890b 2018-10-18 stsp case 'r':
1269 5de5890b 2018-10-18 stsp repo_path = realpath(optarg, NULL);
1270 5de5890b 2018-10-18 stsp if (repo_path == NULL)
1271 5de5890b 2018-10-18 stsp err(1, "-r option");
1272 5de5890b 2018-10-18 stsp break;
1273 5de5890b 2018-10-18 stsp case 'i':
1274 5de5890b 2018-10-18 stsp show_ids = 1;
1275 5de5890b 2018-10-18 stsp break;
1276 c1669e2e 2019-01-09 stsp case 'R':
1277 c1669e2e 2019-01-09 stsp recurse = 1;
1278 c1669e2e 2019-01-09 stsp break;
1279 5de5890b 2018-10-18 stsp default:
1280 5de5890b 2018-10-18 stsp usage();
1281 5de5890b 2018-10-18 stsp /* NOTREACHED */
1282 5de5890b 2018-10-18 stsp }
1283 5de5890b 2018-10-18 stsp }
1284 5de5890b 2018-10-18 stsp
1285 5de5890b 2018-10-18 stsp argc -= optind;
1286 5de5890b 2018-10-18 stsp argv += optind;
1287 5de5890b 2018-10-18 stsp
1288 5de5890b 2018-10-18 stsp if (argc == 1)
1289 5de5890b 2018-10-18 stsp path = argv[0];
1290 5de5890b 2018-10-18 stsp else if (argc > 1)
1291 5de5890b 2018-10-18 stsp usage_tree();
1292 5de5890b 2018-10-18 stsp else
1293 5de5890b 2018-10-18 stsp path = "/";
1294 5de5890b 2018-10-18 stsp
1295 5de5890b 2018-10-18 stsp cwd = getcwd(NULL, 0);
1296 5de5890b 2018-10-18 stsp if (cwd == NULL) {
1297 5de5890b 2018-10-18 stsp error = got_error_from_errno();
1298 5de5890b 2018-10-18 stsp goto done;
1299 5de5890b 2018-10-18 stsp }
1300 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
1301 5de5890b 2018-10-18 stsp repo_path = strdup(cwd);
1302 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
1303 5de5890b 2018-10-18 stsp error = got_error_from_errno();
1304 5de5890b 2018-10-18 stsp goto done;
1305 5de5890b 2018-10-18 stsp }
1306 5de5890b 2018-10-18 stsp }
1307 5de5890b 2018-10-18 stsp
1308 0f8d269b 2019-01-04 stsp error = apply_unveil(repo_path, NULL);
1309 0f8d269b 2019-01-04 stsp if (error)
1310 0f8d269b 2019-01-04 stsp goto done;
1311 0f8d269b 2019-01-04 stsp
1312 5de5890b 2018-10-18 stsp error = got_repo_open(&repo, repo_path);
1313 5de5890b 2018-10-18 stsp if (error != NULL)
1314 5de5890b 2018-10-18 stsp goto done;
1315 5de5890b 2018-10-18 stsp
1316 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
1317 5de5890b 2018-10-18 stsp if (error != NULL)
1318 5de5890b 2018-10-18 stsp goto done;
1319 5de5890b 2018-10-18 stsp
1320 5de5890b 2018-10-18 stsp if (commit_id_str == NULL) {
1321 5de5890b 2018-10-18 stsp struct got_reference *head_ref;
1322 5de5890b 2018-10-18 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
1323 5de5890b 2018-10-18 stsp if (error != NULL)
1324 5de5890b 2018-10-18 stsp goto done;
1325 5de5890b 2018-10-18 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
1326 5de5890b 2018-10-18 stsp got_ref_close(head_ref);
1327 5de5890b 2018-10-18 stsp if (error != NULL)
1328 5de5890b 2018-10-18 stsp goto done;
1329 5de5890b 2018-10-18 stsp } else {
1330 15a94983 2018-12-23 stsp error = got_object_resolve_id_str(&commit_id, repo,
1331 15a94983 2018-12-23 stsp commit_id_str);
1332 5de5890b 2018-10-18 stsp if (error != NULL)
1333 5de5890b 2018-10-18 stsp goto done;
1334 5de5890b 2018-10-18 stsp }
1335 5de5890b 2018-10-18 stsp
1336 c1669e2e 2019-01-09 stsp error = print_tree(in_repo_path, commit_id, show_ids, recurse,
1337 c1669e2e 2019-01-09 stsp in_repo_path, repo);
1338 5de5890b 2018-10-18 stsp done:
1339 5de5890b 2018-10-18 stsp free(in_repo_path);
1340 5de5890b 2018-10-18 stsp free(repo_path);
1341 5de5890b 2018-10-18 stsp free(cwd);
1342 5de5890b 2018-10-18 stsp free(commit_id);
1343 5de5890b 2018-10-18 stsp if (repo) {
1344 5de5890b 2018-10-18 stsp const struct got_error *repo_error;
1345 5de5890b 2018-10-18 stsp repo_error = got_repo_close(repo);
1346 5de5890b 2018-10-18 stsp if (error == NULL)
1347 5de5890b 2018-10-18 stsp error = repo_error;
1348 5de5890b 2018-10-18 stsp }
1349 5de5890b 2018-10-18 stsp return error;
1350 5de5890b 2018-10-18 stsp }
1351 5de5890b 2018-10-18 stsp
1352 f42b1b34 2018-03-12 stsp #ifdef notyet
1353 4ed7e80c 2018-05-20 stsp static const struct got_error *
1354 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
1355 5c860e29 2018-03-12 stsp {
1356 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
1357 5c860e29 2018-03-12 stsp git_status_list *status;
1358 5c860e29 2018-03-12 stsp git_status_options statusopts;
1359 5c860e29 2018-03-12 stsp size_t i;
1360 5c860e29 2018-03-12 stsp
1361 5c860e29 2018-03-12 stsp git_libgit2_init();
1362 5c860e29 2018-03-12 stsp
1363 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
1364 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
1365 5c860e29 2018-03-12 stsp
1366 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
1367 5c860e29 2018-03-12 stsp errx(1, "bar repository");
1368 5c860e29 2018-03-12 stsp
1369 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
1370 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
1371 5c860e29 2018-03-12 stsp
1372 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1373 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
1374 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
1375 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
1376 5c860e29 2018-03-12 stsp
1377 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
1378 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
1379 5c860e29 2018-03-12 stsp
1380 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
1381 5c860e29 2018-03-12 stsp const git_status_entry *se;
1382 5c860e29 2018-03-12 stsp
1383 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
1384 5c860e29 2018-03-12 stsp switch (se->status) {
1385 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
1386 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
1387 5c860e29 2018-03-12 stsp break;
1388 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
1389 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
1390 5c860e29 2018-03-12 stsp break;
1391 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
1392 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
1393 5c860e29 2018-03-12 stsp break;
1394 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
1395 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1396 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
1397 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
1398 5c860e29 2018-03-12 stsp break;
1399 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
1400 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
1401 5c860e29 2018-03-12 stsp break;
1402 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
1403 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
1404 5c860e29 2018-03-12 stsp break;
1405 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
1406 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
1407 5c860e29 2018-03-12 stsp break;
1408 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
1409 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
1410 5c860e29 2018-03-12 stsp break;
1411 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
1412 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1413 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
1414 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
1415 5c860e29 2018-03-12 stsp break;
1416 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
1417 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
1418 5c860e29 2018-03-12 stsp break;
1419 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
1420 5c860e29 2018-03-12 stsp default:
1421 5c860e29 2018-03-12 stsp break;
1422 5c860e29 2018-03-12 stsp }
1423 5c860e29 2018-03-12 stsp }
1424 5c860e29 2018-03-12 stsp
1425 5c860e29 2018-03-12 stsp git_status_list_free(status);
1426 5c860e29 2018-03-12 stsp git_repository_free(repo);
1427 5c860e29 2018-03-12 stsp git_libgit2_shutdown();
1428 5c860e29 2018-03-12 stsp
1429 5c860e29 2018-03-12 stsp return 0;
1430 5c860e29 2018-03-12 stsp }
1431 f42b1b34 2018-03-12 stsp #endif