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>
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.
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.
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>
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>
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"
43 5c860e29 2018-03-12 stsp #ifndef nitems
44 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
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;
51 99437157 2018-11-11 stsp catch_sigint(int signo)
53 99437157 2018-11-11 stsp sigint_received = 1;
57 99437157 2018-11-11 stsp catch_sigpipe(int signo)
59 99437157 2018-11-11 stsp sigpipe_received = 1;
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;
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);
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 *[]);
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" },
104 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
106 5c860e29 2018-03-12 stsp struct cmd *cmd;
107 5c860e29 2018-03-12 stsp unsigned int i;
109 1b6b95a8 2018-03-12 stsp int hflag = 0;
111 5c860e29 2018-03-12 stsp setlocale(LC_ALL, "");
113 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
114 5c860e29 2018-03-12 stsp switch (ch) {
120 5c860e29 2018-03-12 stsp /* NOTREACHED */
124 5c860e29 2018-03-12 stsp argc -= optind;
125 5c860e29 2018-03-12 stsp argv += optind;
126 1e70621d 2018-03-27 stsp optind = 0;
128 5c860e29 2018-03-12 stsp if (argc <= 0)
131 99437157 2018-11-11 stsp signal(SIGINT, catch_sigint);
132 99437157 2018-11-11 stsp signal(SIGPIPE, catch_sigpipe);
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;
137 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
139 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
143 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
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);
154 20ecf764 2018-03-12 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
158 4ed7e80c 2018-05-20 stsp __dead static void
159 5c860e29 2018-03-12 stsp usage(void)
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);
172 4ed7e80c 2018-05-20 stsp __dead static void
173 c09a553d 2018-03-12 stsp usage_checkout(void)
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());
180 92a684f4 2018-03-12 stsp static void
181 92a684f4 2018-03-12 stsp checkout_progress(void *arg, const char *path)
183 92a684f4 2018-03-12 stsp char *worktree_path = arg;
185 92a684f4 2018-03-12 stsp while (path[0] == '/')
188 92a684f4 2018-03-12 stsp printf("A %s/%s\n", worktree_path, path);
191 99437157 2018-11-11 stsp static const struct got_error *
192 99437157 2018-11-11 stsp checkout_cancel(void *arg)
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;
199 4ed7e80c 2018-05-20 stsp static const struct got_error *
200 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
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 = "";
211 0bb8a95e 2018-03-12 stsp while ((ch = getopt(argc, argv, "p:")) != -1) {
212 0bb8a95e 2018-03-12 stsp switch (ch) {
214 0bb8a95e 2018-03-12 stsp path_prefix = optarg;
218 0bb8a95e 2018-03-12 stsp /* NOTREACHED */
222 0bb8a95e 2018-03-12 stsp argc -= optind;
223 0bb8a95e 2018-03-12 stsp argv += optind;
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)
228 c09a553d 2018-03-12 stsp err(1, "pledge");
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();
240 5d7c1dab 2018-04-01 stsp if (path_prefix[0])
241 5d7c1dab 2018-04-01 stsp base = basename(path_prefix);
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();
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();
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();
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();
269 c09a553d 2018-03-12 stsp usage_checkout();
271 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
272 c09a553d 2018-03-12 stsp if (error != NULL)
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)
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)
282 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
283 c09a553d 2018-03-12 stsp if (error != NULL)
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)
291 b65ae19a 2018-04-24 stsp printf("Now shut up and hack\n");
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;
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)
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;
307 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree2, repo, commit->tree_id);
309 79109fed 2018-03-27 stsp return err;
311 79f35eb3 2018-06-11 stsp qid = SIMPLEQ_FIRST(&commit->parent_ids);
312 79f35eb3 2018-06-11 stsp if (qid != NULL) {
313 79109fed 2018-03-27 stsp struct got_commit_object *pcommit;
315 117e771c 2018-07-23 stsp err = got_object_open_as_commit(&pcommit, repo, qid->id);
317 79109fed 2018-03-27 stsp return err;
319 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree1, repo, pcommit->tree_id);
320 79109fed 2018-03-27 stsp got_object_commit_close(pcommit);
322 79109fed 2018-03-27 stsp return err;
325 c0cc5c62 2018-10-18 stsp err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
327 79109fed 2018-03-27 stsp got_object_tree_close(tree1);
328 79109fed 2018-03-27 stsp got_object_tree_close(tree2);
329 79109fed 2018-03-27 stsp return err;
332 4bb494d5 2018-06-16 stsp static char *
333 6c281f94 2018-06-11 stsp get_datestr(time_t *time, char *datebuf)
335 6c281f94 2018-06-11 stsp char *p, *s = ctime_r(time, datebuf);
336 6c281f94 2018-06-11 stsp p = strchr(s, '\n');
342 79109fed 2018-03-27 stsp static const struct got_error *
343 79109fed 2018-03-27 stsp print_commit(struct got_commit_object *commit, struct got_object_id *id,
344 c0cc5c62 2018-10-18 stsp struct got_repository *repo, int show_patch, int diff_context)
346 79109fed 2018-03-27 stsp const struct got_error *err = NULL;
347 621015ac 2018-07-23 stsp char *id_str, *datestr, *logmsg0, *logmsg, *line;
348 6c281f94 2018-06-11 stsp char datebuf[26];
350 832c249c 2018-06-10 stsp err = got_object_id_str(&id_str, id);
352 8bf5b3c9 2018-03-17 stsp return err;
354 8bf5b3c9 2018-03-17 stsp printf("-----------------------------------------------\n");
355 832c249c 2018-06-10 stsp printf("commit %s\n", id_str);
356 832c249c 2018-06-10 stsp free(id_str);
357 0dcf3e9c 2018-09-15 stsp printf("from: %s\n", commit->author);
358 ccb26ccd 2018-11-05 stsp datestr = get_datestr(&commit->committer_time, datebuf);
359 dab5fe87 2018-09-14 stsp printf("date: %s UTC\n", datestr);
360 dab5fe87 2018-09-14 stsp if (strcmp(commit->author, commit->committer) != 0)
361 0dcf3e9c 2018-09-15 stsp printf("via: %s\n", commit->committer);
362 3fe1abad 2018-06-10 stsp if (commit->nparents > 1) {
363 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
365 79f35eb3 2018-06-11 stsp SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
366 79f35eb3 2018-06-11 stsp err = got_object_id_str(&id_str, qid->id);
368 a0603db2 2018-06-10 stsp return err;
369 3fe1abad 2018-06-10 stsp printf("parent %d: %s\n", n++, id_str);
370 a0603db2 2018-06-10 stsp free(id_str);
374 621015ac 2018-07-23 stsp logmsg0 = strdup(commit->logmsg);
375 621015ac 2018-07-23 stsp if (logmsg0 == NULL)
376 832c249c 2018-06-10 stsp return got_error_from_errno();
378 621015ac 2018-07-23 stsp logmsg = logmsg0;
380 832c249c 2018-06-10 stsp line = strsep(&logmsg, "\n");
382 832c249c 2018-06-10 stsp printf(" %s\n", line);
383 832c249c 2018-06-10 stsp } while (line);
384 621015ac 2018-07-23 stsp free(logmsg0);
386 971751ac 2018-03-27 stsp if (show_patch) {
387 c0cc5c62 2018-10-18 stsp err = print_patch(commit, id, diff_context, repo);
388 971751ac 2018-03-27 stsp if (err == 0)
389 971751ac 2018-03-27 stsp printf("\n");
392 d82de447 2018-09-15 stsp fflush(stdout);
393 07862c20 2018-09-15 stsp return err;
396 f42b1b34 2018-03-12 stsp static const struct got_error *
397 8bf5b3c9 2018-03-17 stsp print_commits(struct got_object *root_obj, struct got_object_id *root_id,
398 c0cc5c62 2018-10-18 stsp struct got_repository *repo, char *path, int show_patch, int diff_context,
399 c0cc5c62 2018-10-18 stsp int limit, int first_parent_traversal)
401 f42b1b34 2018-03-12 stsp const struct got_error *err;
402 372ccdbb 2018-06-10 stsp struct got_commit_graph *graph;
404 31cedeaf 2018-09-15 stsp err = got_commit_graph_open(&graph, root_id, path,
405 31cedeaf 2018-09-15 stsp first_parent_traversal, repo);
407 f42b1b34 2018-03-12 stsp return err;
408 31cedeaf 2018-09-15 stsp err = got_commit_graph_iter_start(graph, root_id, repo);
411 31cedeaf 2018-09-15 stsp while (1) {
412 372ccdbb 2018-06-10 stsp struct got_commit_object *commit;
413 372ccdbb 2018-06-10 stsp struct got_object_id *id;
415 b43fbaa0 2018-06-11 stsp err = got_commit_graph_iter_next(&id, graph);
417 9ba79e04 2018-06-11 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
418 9ba79e04 2018-06-11 stsp err = NULL;
421 372ccdbb 2018-06-10 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
423 31cedeaf 2018-09-15 stsp err = got_commit_graph_fetch_commits(graph, 1, repo);
429 b43fbaa0 2018-06-11 stsp if (id == NULL)
432 f8e900f3 2018-06-11 stsp err = got_object_open_as_commit(&commit, repo, id);
435 c0cc5c62 2018-10-18 stsp err = print_commit(commit, id, repo, show_patch, diff_context);
436 b43fbaa0 2018-06-11 stsp got_object_commit_close(commit);
437 372ccdbb 2018-06-10 stsp if (err || (limit && --limit == 0))
441 372ccdbb 2018-06-10 stsp got_commit_graph_close(graph);
442 f42b1b34 2018-03-12 stsp return err;
445 4ed7e80c 2018-05-20 stsp __dead static void
446 6f3d1eb0 2018-03-12 stsp usage_log(void)
448 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
449 04ca23f4 2018-07-16 stsp "[-r repository-path] [path]\n", getprogname());
453 4ed7e80c 2018-05-20 stsp static const struct got_error *
454 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
456 f42b1b34 2018-03-12 stsp const struct got_error *error;
457 04ca23f4 2018-07-16 stsp struct got_repository *repo = NULL;
458 3235492e 2018-04-01 stsp struct got_object_id *id = NULL;
459 d1f2edc9 2018-06-13 stsp struct got_object *obj = NULL;
460 04ca23f4 2018-07-16 stsp char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
461 d142fc45 2018-04-01 stsp char *start_commit = NULL;
462 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
463 1fd6d7ea 2018-06-13 stsp int show_patch = 0, limit = 0, first_parent_traversal = 0;
464 64a96a6d 2018-04-01 stsp const char *errstr;
466 6715a751 2018-03-16 stsp #ifndef PROFILE
467 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
469 f42b1b34 2018-03-12 stsp err(1, "pledge");
472 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
473 79109fed 2018-03-27 stsp switch (ch) {
475 79109fed 2018-03-27 stsp show_patch = 1;
478 d142fc45 2018-04-01 stsp start_commit = optarg;
481 4a8520aa 2018-10-18 stsp diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
483 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
484 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
487 64a96a6d 2018-04-01 stsp limit = strtonum(optarg, 1, INT_MAX, &errstr);
488 64a96a6d 2018-04-01 stsp if (errstr != NULL)
489 64a96a6d 2018-04-01 stsp err(1, "-l option %s", errstr);
492 0ed6ed4c 2018-06-13 stsp first_parent_traversal = 1;
495 04ca23f4 2018-07-16 stsp repo_path = realpath(optarg, NULL);
496 04ca23f4 2018-07-16 stsp if (repo_path == NULL)
497 04ca23f4 2018-07-16 stsp err(1, "-r option");
501 79109fed 2018-03-27 stsp /* NOTREACHED */
505 79109fed 2018-03-27 stsp argc -= optind;
506 79109fed 2018-03-27 stsp argv += optind;
508 04ca23f4 2018-07-16 stsp if (argc == 0)
509 04ca23f4 2018-07-16 stsp path = strdup("");
510 04ca23f4 2018-07-16 stsp else if (argc == 1)
511 04ca23f4 2018-07-16 stsp path = strdup(argv[0]);
513 6f3d1eb0 2018-03-12 stsp usage_log();
514 04ca23f4 2018-07-16 stsp if (path == NULL)
515 04ca23f4 2018-07-16 stsp return got_error_from_errno();
517 04ca23f4 2018-07-16 stsp cwd = getcwd(NULL, 0);
518 04ca23f4 2018-07-16 stsp if (cwd == NULL) {
519 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
522 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
523 04ca23f4 2018-07-16 stsp repo_path = strdup(cwd);
524 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
525 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
530 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
531 d7d4f210 2018-03-12 stsp if (error != NULL)
534 d142fc45 2018-04-01 stsp if (start_commit == NULL) {
535 3235492e 2018-04-01 stsp struct got_reference *head_ref;
536 3235492e 2018-04-01 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
537 3235492e 2018-04-01 stsp if (error != NULL)
538 3235492e 2018-04-01 stsp return error;
539 3235492e 2018-04-01 stsp error = got_ref_resolve(&id, repo, head_ref);
540 3235492e 2018-04-01 stsp got_ref_close(head_ref);
541 3235492e 2018-04-01 stsp if (error != NULL)
542 3235492e 2018-04-01 stsp return error;
543 3235492e 2018-04-01 stsp error = got_object_open(&obj, repo, id);
545 d1f2edc9 2018-06-13 stsp struct got_reference *ref;
546 d1f2edc9 2018-06-13 stsp error = got_ref_open(&ref, repo, start_commit);
547 3235492e 2018-04-01 stsp if (error == NULL) {
548 d1f2edc9 2018-06-13 stsp error = got_ref_resolve(&id, repo, ref);
549 d1f2edc9 2018-06-13 stsp got_ref_close(ref);
550 d1f2edc9 2018-06-13 stsp if (error != NULL)
551 d1f2edc9 2018-06-13 stsp return error;
552 d1f2edc9 2018-06-13 stsp error = got_object_open(&obj, repo, id);
553 d1f2edc9 2018-06-13 stsp if (error != NULL)
554 d1f2edc9 2018-06-13 stsp return error;
556 d1f2edc9 2018-06-13 stsp if (obj == NULL) {
557 d1f2edc9 2018-06-13 stsp error = got_object_open_by_id_str(&obj, repo,
558 d1f2edc9 2018-06-13 stsp start_commit);
559 d1f2edc9 2018-06-13 stsp if (error != NULL)
560 d1f2edc9 2018-06-13 stsp return error;
561 6402fb3c 2018-09-15 stsp id = got_object_id_dup(got_object_get_id(obj));
562 3235492e 2018-04-01 stsp if (id == NULL)
563 3235492e 2018-04-01 stsp error = got_error_from_errno();
566 d7d4f210 2018-03-12 stsp if (error != NULL)
568 04ca23f4 2018-07-16 stsp if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
569 8bf5b3c9 2018-03-17 stsp error = got_error(GOT_ERR_OBJ_TYPE);
573 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
574 04ca23f4 2018-07-16 stsp if (error != NULL)
576 04ca23f4 2018-07-16 stsp if (in_repo_path) {
577 04ca23f4 2018-07-16 stsp free(path);
578 04ca23f4 2018-07-16 stsp path = in_repo_path;
581 04ca23f4 2018-07-16 stsp error = print_commits(obj, id, repo, path, show_patch,
582 c0cc5c62 2018-10-18 stsp diff_context, limit, first_parent_traversal);
584 04ca23f4 2018-07-16 stsp free(path);
585 04ca23f4 2018-07-16 stsp free(repo_path);
588 04ca23f4 2018-07-16 stsp got_object_close(obj);
590 ad242220 2018-09-08 stsp if (repo) {
591 ad242220 2018-09-08 stsp const struct got_error *repo_error;
592 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
593 ad242220 2018-09-08 stsp if (error == NULL)
594 ad242220 2018-09-08 stsp error = repo_error;
596 8bf5b3c9 2018-03-17 stsp return error;
599 4ed7e80c 2018-05-20 stsp __dead static void
600 3f8b7d6a 2018-04-01 stsp usage_diff(void)
602 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
603 c0cc5c62 2018-10-18 stsp "object1 object2\n", getprogname());
607 4ed7e80c 2018-05-20 stsp static const struct got_error *
608 b00d56cd 2018-04-01 stsp cmd_diff(int argc, char *argv[])
610 b00d56cd 2018-04-01 stsp const struct got_error *error;
611 b00d56cd 2018-04-01 stsp struct got_repository *repo = NULL;
612 b00d56cd 2018-04-01 stsp struct got_object *obj1 = NULL, *obj2 = NULL;
613 b00d56cd 2018-04-01 stsp char *repo_path = NULL;
614 b00d56cd 2018-04-01 stsp char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
615 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
616 c0cc5c62 2018-10-18 stsp const char *errstr;
618 b00d56cd 2018-04-01 stsp #ifndef PROFILE
619 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
621 b00d56cd 2018-04-01 stsp err(1, "pledge");
624 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "C:")) != -1) {
625 b00d56cd 2018-04-01 stsp switch (ch) {
627 c0cc5c62 2018-10-18 stsp diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
628 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
629 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
633 b00d56cd 2018-04-01 stsp /* NOTREACHED */
637 b00d56cd 2018-04-01 stsp argc -= optind;
638 b00d56cd 2018-04-01 stsp argv += optind;
640 b00d56cd 2018-04-01 stsp if (argc == 0) {
641 b00d56cd 2018-04-01 stsp usage_diff(); /* TODO show local worktree changes */
642 3f8b7d6a 2018-04-01 stsp } else if (argc == 2) {
643 3f8b7d6a 2018-04-01 stsp repo_path = getcwd(NULL, 0);
644 3f8b7d6a 2018-04-01 stsp if (repo_path == NULL)
645 e1e3f570 2018-04-01 stsp return got_error_from_errno();
646 3f8b7d6a 2018-04-01 stsp obj_id_str1 = argv[0];
647 3f8b7d6a 2018-04-01 stsp obj_id_str2 = argv[1];
648 b00d56cd 2018-04-01 stsp } else if (argc == 3) {
649 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
650 76089277 2018-04-01 stsp if (repo_path == NULL)
651 76089277 2018-04-01 stsp return got_error_from_errno();
652 b00d56cd 2018-04-01 stsp obj_id_str1 = argv[1];
653 b00d56cd 2018-04-01 stsp obj_id_str2 = argv[2];
655 b00d56cd 2018-04-01 stsp usage_diff();
657 b00d56cd 2018-04-01 stsp error = got_repo_open(&repo, repo_path);
658 76089277 2018-04-01 stsp free(repo_path);
659 b00d56cd 2018-04-01 stsp if (error != NULL)
662 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
666 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
670 b00d56cd 2018-04-01 stsp if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
671 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
675 b00d56cd 2018-04-01 stsp switch (got_object_get_type(obj1)) {
676 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_BLOB:
677 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_blobs(obj1, obj2, NULL, NULL,
678 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
680 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_TREE:
681 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_trees(obj1, obj2, "", "",
682 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
684 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_COMMIT:
685 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_commits(obj1, obj2, diff_context,
686 c0cc5c62 2018-10-18 stsp repo, stdout);
689 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
694 b00d56cd 2018-04-01 stsp got_object_close(obj1);
696 b00d56cd 2018-04-01 stsp got_object_close(obj2);
697 ad242220 2018-09-08 stsp if (repo) {
698 ad242220 2018-09-08 stsp const struct got_error *repo_error;
699 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
700 ad242220 2018-09-08 stsp if (error == NULL)
701 ad242220 2018-09-08 stsp error = repo_error;
703 b00d56cd 2018-04-01 stsp return error;
706 404c43c4 2018-06-21 stsp __dead static void
707 404c43c4 2018-06-21 stsp usage_blame(void)
709 66bea077 2018-08-02 stsp fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
710 404c43c4 2018-06-21 stsp getprogname());
714 404c43c4 2018-06-21 stsp static const struct got_error *
715 404c43c4 2018-06-21 stsp cmd_blame(int argc, char *argv[])
717 404c43c4 2018-06-21 stsp const struct got_error *error;
718 404c43c4 2018-06-21 stsp struct got_repository *repo = NULL;
719 66bea077 2018-08-02 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
720 404c43c4 2018-06-21 stsp struct got_object_id *commit_id = NULL;
721 404c43c4 2018-06-21 stsp char *commit_id_str = NULL;
724 404c43c4 2018-06-21 stsp #ifndef PROFILE
725 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
727 404c43c4 2018-06-21 stsp err(1, "pledge");
730 66bea077 2018-08-02 stsp while ((ch = getopt(argc, argv, "c:r:")) != -1) {
731 404c43c4 2018-06-21 stsp switch (ch) {
733 404c43c4 2018-06-21 stsp commit_id_str = optarg;
736 66bea077 2018-08-02 stsp repo_path = realpath(optarg, NULL);
737 66bea077 2018-08-02 stsp if (repo_path == NULL)
738 66bea077 2018-08-02 stsp err(1, "-r option");
742 404c43c4 2018-06-21 stsp /* NOTREACHED */
746 404c43c4 2018-06-21 stsp argc -= optind;
747 404c43c4 2018-06-21 stsp argv += optind;
749 a39318fd 2018-08-02 stsp if (argc == 1)
750 404c43c4 2018-06-21 stsp path = argv[0];
752 404c43c4 2018-06-21 stsp usage_blame();
754 66bea077 2018-08-02 stsp cwd = getcwd(NULL, 0);
755 66bea077 2018-08-02 stsp if (cwd == NULL) {
756 66bea077 2018-08-02 stsp error = got_error_from_errno();
759 66bea077 2018-08-02 stsp if (repo_path == NULL) {
760 66bea077 2018-08-02 stsp repo_path = strdup(cwd);
761 66bea077 2018-08-02 stsp if (repo_path == NULL) {
762 66bea077 2018-08-02 stsp error = got_error_from_errno();
767 404c43c4 2018-06-21 stsp error = got_repo_open(&repo, repo_path);
768 404c43c4 2018-06-21 stsp if (error != NULL)
771 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
772 66bea077 2018-08-02 stsp if (error != NULL)
775 404c43c4 2018-06-21 stsp if (commit_id_str == NULL) {
776 404c43c4 2018-06-21 stsp struct got_reference *head_ref;
777 404c43c4 2018-06-21 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
778 404c43c4 2018-06-21 stsp if (error != NULL)
780 404c43c4 2018-06-21 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
781 404c43c4 2018-06-21 stsp got_ref_close(head_ref);
782 404c43c4 2018-06-21 stsp if (error != NULL)
785 404c43c4 2018-06-21 stsp struct got_object *obj;
786 404c43c4 2018-06-21 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
787 404c43c4 2018-06-21 stsp if (error != NULL)
789 6402fb3c 2018-09-15 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
790 404c43c4 2018-06-21 stsp if (commit_id == NULL)
791 404c43c4 2018-06-21 stsp error = got_error_from_errno();
792 404c43c4 2018-06-21 stsp got_object_close(obj);
795 66bea077 2018-08-02 stsp error = got_blame(in_repo_path, commit_id, repo, stdout);
797 66bea077 2018-08-02 stsp free(in_repo_path);
798 66bea077 2018-08-02 stsp free(repo_path);
800 404c43c4 2018-06-21 stsp free(commit_id);
801 ad242220 2018-09-08 stsp if (repo) {
802 ad242220 2018-09-08 stsp const struct got_error *repo_error;
803 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
804 ad242220 2018-09-08 stsp if (error == NULL)
805 ad242220 2018-09-08 stsp error = repo_error;
807 404c43c4 2018-06-21 stsp return error;
810 5de5890b 2018-10-18 stsp __dead static void
811 5de5890b 2018-10-18 stsp usage_tree(void)
813 5de5890b 2018-10-18 stsp fprintf(stderr, "usage: %s tree [-c commit] [-r repository-path] [-i] path\n",
814 5de5890b 2018-10-18 stsp getprogname());
819 5de5890b 2018-10-18 stsp static const struct got_error *
820 5de5890b 2018-10-18 stsp print_tree(const char *path, struct got_object_id *commit_id,
821 5de5890b 2018-10-18 stsp int show_ids, struct got_repository *repo)
823 5de5890b 2018-10-18 stsp const struct got_error *err = NULL;
824 5de5890b 2018-10-18 stsp struct got_object_id *tree_id = NULL;
825 5de5890b 2018-10-18 stsp struct got_tree_object *tree = NULL;
826 5de5890b 2018-10-18 stsp const struct got_tree_entries *entries;
827 5de5890b 2018-10-18 stsp struct got_tree_entry *te;
829 5de5890b 2018-10-18 stsp err = got_object_id_by_path(&tree_id, repo, commit_id, path);
833 5de5890b 2018-10-18 stsp err = got_object_open_as_tree(&tree, repo, tree_id);
836 5de5890b 2018-10-18 stsp entries = got_object_tree_get_entries(tree);
837 5de5890b 2018-10-18 stsp te = SIMPLEQ_FIRST(&entries->head);
838 5de5890b 2018-10-18 stsp while (te) {
839 5de5890b 2018-10-18 stsp char *id = NULL;
840 5de5890b 2018-10-18 stsp if (show_ids) {
841 5de5890b 2018-10-18 stsp char *id_str;
842 5de5890b 2018-10-18 stsp err = got_object_id_str(&id_str, te->id);
845 5de5890b 2018-10-18 stsp if (asprintf(&id, "%s ", id_str) == -1) {
846 5de5890b 2018-10-18 stsp err = got_error_from_errno();
847 5de5890b 2018-10-18 stsp free(id_str);
850 5de5890b 2018-10-18 stsp free(id_str);
852 5de5890b 2018-10-18 stsp printf("%s%s%s\n", id ? id : "",
853 5de5890b 2018-10-18 stsp te->name, S_ISDIR(te->mode) ? "/" : "");
854 5de5890b 2018-10-18 stsp te = SIMPLEQ_NEXT(te, entry);
859 5de5890b 2018-10-18 stsp got_object_tree_close(tree);
860 5de5890b 2018-10-18 stsp free(tree_id);
861 5de5890b 2018-10-18 stsp return err;
864 5de5890b 2018-10-18 stsp static const struct got_error *
865 5de5890b 2018-10-18 stsp cmd_tree(int argc, char *argv[])
867 5de5890b 2018-10-18 stsp const struct got_error *error;
868 5de5890b 2018-10-18 stsp struct got_repository *repo = NULL;
869 5de5890b 2018-10-18 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
870 5de5890b 2018-10-18 stsp struct got_object_id *commit_id = NULL;
871 5de5890b 2018-10-18 stsp char *commit_id_str = NULL;
872 5de5890b 2018-10-18 stsp int show_ids = 0;
875 5de5890b 2018-10-18 stsp #ifndef PROFILE
876 5de5890b 2018-10-18 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
878 5de5890b 2018-10-18 stsp err(1, "pledge");
881 5de5890b 2018-10-18 stsp while ((ch = getopt(argc, argv, "c:r:i")) != -1) {
882 5de5890b 2018-10-18 stsp switch (ch) {
884 5de5890b 2018-10-18 stsp commit_id_str = optarg;
887 5de5890b 2018-10-18 stsp repo_path = realpath(optarg, NULL);
888 5de5890b 2018-10-18 stsp if (repo_path == NULL)
889 5de5890b 2018-10-18 stsp err(1, "-r option");
892 5de5890b 2018-10-18 stsp show_ids = 1;
896 5de5890b 2018-10-18 stsp /* NOTREACHED */
900 5de5890b 2018-10-18 stsp argc -= optind;
901 5de5890b 2018-10-18 stsp argv += optind;
903 5de5890b 2018-10-18 stsp if (argc == 1)
904 5de5890b 2018-10-18 stsp path = argv[0];
905 5de5890b 2018-10-18 stsp else if (argc > 1)
906 5de5890b 2018-10-18 stsp usage_tree();
908 5de5890b 2018-10-18 stsp path = "/";
910 5de5890b 2018-10-18 stsp cwd = getcwd(NULL, 0);
911 5de5890b 2018-10-18 stsp if (cwd == NULL) {
912 5de5890b 2018-10-18 stsp error = got_error_from_errno();
915 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
916 5de5890b 2018-10-18 stsp repo_path = strdup(cwd);
917 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
918 5de5890b 2018-10-18 stsp error = got_error_from_errno();
923 5de5890b 2018-10-18 stsp error = got_repo_open(&repo, repo_path);
924 5de5890b 2018-10-18 stsp if (error != NULL)
927 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
928 5de5890b 2018-10-18 stsp if (error != NULL)
931 5de5890b 2018-10-18 stsp if (commit_id_str == NULL) {
932 5de5890b 2018-10-18 stsp struct got_reference *head_ref;
933 5de5890b 2018-10-18 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
934 5de5890b 2018-10-18 stsp if (error != NULL)
936 5de5890b 2018-10-18 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
937 5de5890b 2018-10-18 stsp got_ref_close(head_ref);
938 5de5890b 2018-10-18 stsp if (error != NULL)
941 5de5890b 2018-10-18 stsp struct got_object *obj;
942 5de5890b 2018-10-18 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
943 5de5890b 2018-10-18 stsp if (error != NULL)
945 5de5890b 2018-10-18 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
946 5de5890b 2018-10-18 stsp if (commit_id == NULL)
947 5de5890b 2018-10-18 stsp error = got_error_from_errno();
948 5de5890b 2018-10-18 stsp got_object_close(obj);
951 5de5890b 2018-10-18 stsp error = print_tree(in_repo_path, commit_id, show_ids, repo);
953 5de5890b 2018-10-18 stsp free(in_repo_path);
954 5de5890b 2018-10-18 stsp free(repo_path);
956 5de5890b 2018-10-18 stsp free(commit_id);
957 5de5890b 2018-10-18 stsp if (repo) {
958 5de5890b 2018-10-18 stsp const struct got_error *repo_error;
959 5de5890b 2018-10-18 stsp repo_error = got_repo_close(repo);
960 5de5890b 2018-10-18 stsp if (error == NULL)
961 5de5890b 2018-10-18 stsp error = repo_error;
963 5de5890b 2018-10-18 stsp return error;
966 f42b1b34 2018-03-12 stsp #ifdef notyet
967 4ed7e80c 2018-05-20 stsp static const struct got_error *
968 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
970 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
971 5c860e29 2018-03-12 stsp git_status_list *status;
972 5c860e29 2018-03-12 stsp git_status_options statusopts;
975 5c860e29 2018-03-12 stsp git_libgit2_init();
977 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
978 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
980 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
981 5c860e29 2018-03-12 stsp errx(1, "bar repository");
983 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
984 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
986 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
987 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
988 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
989 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
991 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
992 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
994 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
995 5c860e29 2018-03-12 stsp const git_status_entry *se;
997 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
998 5c860e29 2018-03-12 stsp switch (se->status) {
999 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
1000 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
1002 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
1003 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
1005 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
1006 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
1008 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
1009 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1010 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
1011 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
1013 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
1014 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
1016 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
1017 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
1019 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
1020 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
1022 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
1023 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
1025 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
1026 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1027 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
1028 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
1030 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
1031 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
1033 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
1039 5c860e29 2018-03-12 stsp git_status_list_free(status);
1040 5c860e29 2018-03-12 stsp git_repository_free(repo);
1041 5c860e29 2018-03-12 stsp git_libgit2_shutdown();