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 5c860e29 2018-03-12 stsp #include <stdio.h>
27 5c860e29 2018-03-12 stsp #include <stdlib.h>
28 5c860e29 2018-03-12 stsp #include <string.h>
29 5c860e29 2018-03-12 stsp #include <unistd.h>
30 c09a553d 2018-03-12 stsp #include <libgen.h>
31 c0768b0f 2018-06-10 stsp #include <time.h>
33 f42b1b34 2018-03-12 stsp #include "got_error.h"
34 f42b1b34 2018-03-12 stsp #include "got_object.h"
35 5261c201 2018-04-01 stsp #include "got_reference.h"
36 f42b1b34 2018-03-12 stsp #include "got_repository.h"
37 c09a553d 2018-03-12 stsp #include "got_worktree.h"
38 79109fed 2018-03-27 stsp #include "got_diff.h"
39 372ccdbb 2018-06-10 stsp #include "got_commit_graph.h"
40 404c43c4 2018-06-21 stsp #include "got_blame.h"
42 5c860e29 2018-03-12 stsp #ifndef nitems
43 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
46 5c860e29 2018-03-12 stsp struct cmd {
47 5c860e29 2018-03-12 stsp const char *cmd_name;
48 d7d4f210 2018-03-12 stsp const struct got_error *(*cmd_main)(int, char *[]);
49 1b6b95a8 2018-03-12 stsp void (*cmd_usage)(void);
50 46a0db7d 2018-03-12 stsp const char *cmd_descr;
53 4ed7e80c 2018-05-20 stsp __dead static void usage(void);
54 4ed7e80c 2018-05-20 stsp __dead static void usage_checkout(void);
55 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
56 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
57 404c43c4 2018-06-21 stsp __dead static void usage_blame(void);
58 5de5890b 2018-10-18 stsp __dead static void usage_tree(void);
60 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_checkout(int, char *[]);
61 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
62 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
63 404c43c4 2018-06-21 stsp static const struct got_error* cmd_blame(int, char *[]);
64 5de5890b 2018-10-18 stsp static const struct got_error* cmd_tree(int, char *[]);
65 4ed7e80c 2018-05-20 stsp #ifdef notyet
66 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_status(int, char *[]);
69 4ed7e80c 2018-05-20 stsp static struct cmd got_commands[] = {
70 c09a553d 2018-03-12 stsp { "checkout", cmd_checkout, usage_checkout,
71 0bb8a95e 2018-03-12 stsp "check out a new work tree from a repository" },
72 1b6b95a8 2018-03-12 stsp { "log", cmd_log, usage_log,
73 1b6b95a8 2018-03-12 stsp "show repository history" },
74 b00d56cd 2018-04-01 stsp { "diff", cmd_diff, usage_diff,
75 b00d56cd 2018-04-01 stsp "compare files and directories" },
76 404c43c4 2018-06-21 stsp { "blame", cmd_blame, usage_blame,
77 404c43c4 2018-06-21 stsp " show when lines in a file were changed" },
78 5de5890b 2018-10-18 stsp { "tree", cmd_tree, usage_tree,
79 5de5890b 2018-10-18 stsp " list files and directories in repository" },
80 f42b1b34 2018-03-12 stsp #ifdef notyet
81 1b6b95a8 2018-03-12 stsp { "status", cmd_status, usage_status,
82 1b6b95a8 2018-03-12 stsp "show modification status of files" },
87 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
89 5c860e29 2018-03-12 stsp struct cmd *cmd;
90 5c860e29 2018-03-12 stsp unsigned int i;
92 1b6b95a8 2018-03-12 stsp int hflag = 0;
94 5c860e29 2018-03-12 stsp setlocale(LC_ALL, "");
96 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
97 5c860e29 2018-03-12 stsp switch (ch) {
103 5c860e29 2018-03-12 stsp /* NOTREACHED */
107 5c860e29 2018-03-12 stsp argc -= optind;
108 5c860e29 2018-03-12 stsp argv += optind;
109 1e70621d 2018-03-27 stsp optind = 0;
111 5c860e29 2018-03-12 stsp if (argc <= 0)
114 5c860e29 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
115 d7d4f210 2018-03-12 stsp const struct got_error *error;
117 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
119 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
123 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
125 d7d4f210 2018-03-12 stsp error = got_commands[i].cmd_main(argc, argv);
126 d7d4f210 2018-03-12 stsp if (error) {
127 d7d4f210 2018-03-12 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
134 20ecf764 2018-03-12 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
138 4ed7e80c 2018-05-20 stsp __dead static void
139 5c860e29 2018-03-12 stsp usage(void)
143 987e94ba 2018-03-12 stsp fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
144 987e94ba 2018-03-12 stsp "Available commands:\n", getprogname());
145 46a0db7d 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
146 46a0db7d 2018-03-12 stsp struct cmd *cmd = &got_commands[i];
147 46a0db7d 2018-03-12 stsp fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
152 4ed7e80c 2018-05-20 stsp __dead static void
153 c09a553d 2018-03-12 stsp usage_checkout(void)
155 0bb8a95e 2018-03-12 stsp fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
156 0bb8a95e 2018-03-12 stsp "[worktree-path]\n", getprogname());
160 92a684f4 2018-03-12 stsp static void
161 92a684f4 2018-03-12 stsp checkout_progress(void *arg, const char *path)
163 92a684f4 2018-03-12 stsp char *worktree_path = arg;
165 92a684f4 2018-03-12 stsp while (path[0] == '/')
168 92a684f4 2018-03-12 stsp printf("A %s/%s\n", worktree_path, path);
171 4ed7e80c 2018-05-20 stsp static const struct got_error *
172 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
174 c09a553d 2018-03-12 stsp const struct got_error *error = NULL;
175 c09a553d 2018-03-12 stsp struct got_repository *repo = NULL;
176 c09a553d 2018-03-12 stsp struct got_reference *head_ref = NULL;
177 c09a553d 2018-03-12 stsp struct got_worktree *worktree = NULL;
178 c09a553d 2018-03-12 stsp char *repo_path = NULL;
179 c09a553d 2018-03-12 stsp char *worktree_path = NULL;
180 0bb8a95e 2018-03-12 stsp const char *path_prefix = "";
183 0bb8a95e 2018-03-12 stsp while ((ch = getopt(argc, argv, "p:")) != -1) {
184 0bb8a95e 2018-03-12 stsp switch (ch) {
186 0bb8a95e 2018-03-12 stsp path_prefix = optarg;
190 0bb8a95e 2018-03-12 stsp /* NOTREACHED */
194 0bb8a95e 2018-03-12 stsp argc -= optind;
195 0bb8a95e 2018-03-12 stsp argv += optind;
197 6715a751 2018-03-16 stsp #ifndef PROFILE
198 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
200 c09a553d 2018-03-12 stsp err(1, "pledge");
202 0bb8a95e 2018-03-12 stsp if (argc == 1) {
203 c09a553d 2018-03-12 stsp char *cwd, *base, *dotgit;
204 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
205 76089277 2018-04-01 stsp if (repo_path == NULL)
206 76089277 2018-04-01 stsp return got_error_from_errno();
207 c09a553d 2018-03-12 stsp cwd = getcwd(NULL, 0);
208 76089277 2018-04-01 stsp if (cwd == NULL) {
209 76089277 2018-04-01 stsp error = got_error_from_errno();
212 5d7c1dab 2018-04-01 stsp if (path_prefix[0])
213 5d7c1dab 2018-04-01 stsp base = basename(path_prefix);
215 5d7c1dab 2018-04-01 stsp base = basename(repo_path);
216 76089277 2018-04-01 stsp if (base == NULL) {
217 76089277 2018-04-01 stsp error = got_error_from_errno();
220 c09a553d 2018-03-12 stsp dotgit = strstr(base, ".git");
221 c09a553d 2018-03-12 stsp if (dotgit)
222 c09a553d 2018-03-12 stsp *dotgit = '\0';
223 c09a553d 2018-03-12 stsp if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
224 0a585a0d 2018-03-17 stsp error = got_error_from_errno();
229 0bb8a95e 2018-03-12 stsp } else if (argc == 2) {
230 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
231 76089277 2018-04-01 stsp if (repo_path == NULL) {
232 76089277 2018-04-01 stsp error = got_error_from_errno();
235 f7b38925 2018-04-01 stsp worktree_path = realpath(argv[1], NULL);
236 76089277 2018-04-01 stsp if (worktree_path == NULL) {
237 76089277 2018-04-01 stsp error = got_error_from_errno();
241 c09a553d 2018-03-12 stsp usage_checkout();
243 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
244 c09a553d 2018-03-12 stsp if (error != NULL)
246 c09a553d 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
247 c09a553d 2018-03-12 stsp if (error != NULL)
250 0bb8a95e 2018-03-12 stsp error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
251 c09a553d 2018-03-12 stsp if (error != NULL)
254 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
255 c09a553d 2018-03-12 stsp if (error != NULL)
258 92a684f4 2018-03-12 stsp error = got_worktree_checkout_files(worktree, head_ref, repo,
259 92a684f4 2018-03-12 stsp checkout_progress, worktree_path);
260 c09a553d 2018-03-12 stsp if (error != NULL)
263 b65ae19a 2018-04-24 stsp printf("Now shut up and hack\n");
266 76089277 2018-04-01 stsp free(repo_path);
267 c09a553d 2018-03-12 stsp free(worktree_path);
268 c09a553d 2018-03-12 stsp return error;
271 f42b1b34 2018-03-12 stsp static const struct got_error *
272 79109fed 2018-03-27 stsp print_patch(struct got_commit_object *commit, struct got_object_id *id,
273 c0cc5c62 2018-10-18 stsp int diff_context, struct got_repository *repo)
275 f42b1b34 2018-03-12 stsp const struct got_error *err = NULL;
276 79109fed 2018-03-27 stsp struct got_tree_object *tree1 = NULL, *tree2;
277 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
279 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree2, repo, commit->tree_id);
281 79109fed 2018-03-27 stsp return err;
283 79f35eb3 2018-06-11 stsp qid = SIMPLEQ_FIRST(&commit->parent_ids);
284 79f35eb3 2018-06-11 stsp if (qid != NULL) {
285 79109fed 2018-03-27 stsp struct got_commit_object *pcommit;
287 117e771c 2018-07-23 stsp err = got_object_open_as_commit(&pcommit, repo, qid->id);
289 79109fed 2018-03-27 stsp return err;
291 117e771c 2018-07-23 stsp err = got_object_open_as_tree(&tree1, repo, pcommit->tree_id);
292 79109fed 2018-03-27 stsp got_object_commit_close(pcommit);
294 79109fed 2018-03-27 stsp return err;
297 c0cc5c62 2018-10-18 stsp err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
299 79109fed 2018-03-27 stsp got_object_tree_close(tree1);
300 79109fed 2018-03-27 stsp got_object_tree_close(tree2);
301 79109fed 2018-03-27 stsp return err;
304 4bb494d5 2018-06-16 stsp static char *
305 6c281f94 2018-06-11 stsp get_datestr(time_t *time, char *datebuf)
307 6c281f94 2018-06-11 stsp char *p, *s = ctime_r(time, datebuf);
308 6c281f94 2018-06-11 stsp p = strchr(s, '\n');
314 79109fed 2018-03-27 stsp static const struct got_error *
315 79109fed 2018-03-27 stsp print_commit(struct got_commit_object *commit, struct got_object_id *id,
316 c0cc5c62 2018-10-18 stsp struct got_repository *repo, int show_patch, int diff_context)
318 79109fed 2018-03-27 stsp const struct got_error *err = NULL;
319 621015ac 2018-07-23 stsp char *id_str, *datestr, *logmsg0, *logmsg, *line;
320 6c281f94 2018-06-11 stsp char datebuf[26];
321 788c352e 2018-06-16 stsp time_t author_time, committer_time;
323 832c249c 2018-06-10 stsp err = got_object_id_str(&id_str, id);
325 8bf5b3c9 2018-03-17 stsp return err;
327 788c352e 2018-06-16 stsp author_time = mktime(&commit->tm_author);
328 788c352e 2018-06-16 stsp committer_time = mktime(&commit->tm_committer);
330 788c352e 2018-06-16 stsp /* This would express the date in committer's timezone. */
331 788c352e 2018-06-16 stsp author_time += commit->tm_author.tm_gmtoff;
332 788c352e 2018-06-16 stsp committer_time += commit->tm_committer.tm_gmtoff;
335 8bf5b3c9 2018-03-17 stsp printf("-----------------------------------------------\n");
336 832c249c 2018-06-10 stsp printf("commit %s\n", id_str);
337 832c249c 2018-06-10 stsp free(id_str);
338 0dcf3e9c 2018-09-15 stsp printf("from: %s\n", commit->author);
339 dab5fe87 2018-09-14 stsp datestr = get_datestr(&committer_time, datebuf);
340 dab5fe87 2018-09-14 stsp printf("date: %s UTC\n", datestr);
341 dab5fe87 2018-09-14 stsp if (strcmp(commit->author, commit->committer) != 0)
342 0dcf3e9c 2018-09-15 stsp printf("via: %s\n", commit->committer);
343 3fe1abad 2018-06-10 stsp if (commit->nparents > 1) {
344 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
346 79f35eb3 2018-06-11 stsp SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
347 79f35eb3 2018-06-11 stsp err = got_object_id_str(&id_str, qid->id);
349 a0603db2 2018-06-10 stsp return err;
350 3fe1abad 2018-06-10 stsp printf("parent %d: %s\n", n++, id_str);
351 a0603db2 2018-06-10 stsp free(id_str);
355 621015ac 2018-07-23 stsp logmsg0 = strdup(commit->logmsg);
356 621015ac 2018-07-23 stsp if (logmsg0 == NULL)
357 832c249c 2018-06-10 stsp return got_error_from_errno();
359 621015ac 2018-07-23 stsp logmsg = logmsg0;
361 832c249c 2018-06-10 stsp line = strsep(&logmsg, "\n");
363 832c249c 2018-06-10 stsp printf(" %s\n", line);
364 832c249c 2018-06-10 stsp } while (line);
365 621015ac 2018-07-23 stsp free(logmsg0);
367 971751ac 2018-03-27 stsp if (show_patch) {
368 c0cc5c62 2018-10-18 stsp err = print_patch(commit, id, diff_context, repo);
369 971751ac 2018-03-27 stsp if (err == 0)
370 971751ac 2018-03-27 stsp printf("\n");
373 d82de447 2018-09-15 stsp fflush(stdout);
374 07862c20 2018-09-15 stsp return err;
377 f42b1b34 2018-03-12 stsp static const struct got_error *
378 8bf5b3c9 2018-03-17 stsp print_commits(struct got_object *root_obj, struct got_object_id *root_id,
379 c0cc5c62 2018-10-18 stsp struct got_repository *repo, char *path, int show_patch, int diff_context,
380 c0cc5c62 2018-10-18 stsp int limit, int first_parent_traversal)
382 f42b1b34 2018-03-12 stsp const struct got_error *err;
383 372ccdbb 2018-06-10 stsp struct got_commit_graph *graph;
385 31cedeaf 2018-09-15 stsp err = got_commit_graph_open(&graph, root_id, path,
386 31cedeaf 2018-09-15 stsp first_parent_traversal, repo);
388 f42b1b34 2018-03-12 stsp return err;
389 31cedeaf 2018-09-15 stsp err = got_commit_graph_iter_start(graph, root_id, repo);
392 31cedeaf 2018-09-15 stsp while (1) {
393 372ccdbb 2018-06-10 stsp struct got_commit_object *commit;
394 372ccdbb 2018-06-10 stsp struct got_object_id *id;
396 b43fbaa0 2018-06-11 stsp err = got_commit_graph_iter_next(&id, graph);
398 9ba79e04 2018-06-11 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
399 9ba79e04 2018-06-11 stsp err = NULL;
402 372ccdbb 2018-06-10 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
404 31cedeaf 2018-09-15 stsp err = got_commit_graph_fetch_commits(graph, 1, repo);
410 b43fbaa0 2018-06-11 stsp if (id == NULL)
413 f8e900f3 2018-06-11 stsp err = got_object_open_as_commit(&commit, repo, id);
416 c0cc5c62 2018-10-18 stsp err = print_commit(commit, id, repo, show_patch, diff_context);
417 b43fbaa0 2018-06-11 stsp got_object_commit_close(commit);
418 372ccdbb 2018-06-10 stsp if (err || (limit && --limit == 0))
422 372ccdbb 2018-06-10 stsp got_commit_graph_close(graph);
423 f42b1b34 2018-03-12 stsp return err;
426 4ed7e80c 2018-05-20 stsp __dead static void
427 6f3d1eb0 2018-03-12 stsp usage_log(void)
429 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
430 04ca23f4 2018-07-16 stsp "[-r repository-path] [path]\n", getprogname());
434 4ed7e80c 2018-05-20 stsp static const struct got_error *
435 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
437 f42b1b34 2018-03-12 stsp const struct got_error *error;
438 04ca23f4 2018-07-16 stsp struct got_repository *repo = NULL;
439 3235492e 2018-04-01 stsp struct got_object_id *id = NULL;
440 d1f2edc9 2018-06-13 stsp struct got_object *obj = NULL;
441 04ca23f4 2018-07-16 stsp char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
442 d142fc45 2018-04-01 stsp char *start_commit = NULL;
443 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
444 1fd6d7ea 2018-06-13 stsp int show_patch = 0, limit = 0, first_parent_traversal = 0;
445 64a96a6d 2018-04-01 stsp const char *errstr;
447 6715a751 2018-03-16 stsp #ifndef PROFILE
448 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
450 f42b1b34 2018-03-12 stsp err(1, "pledge");
453 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
454 79109fed 2018-03-27 stsp switch (ch) {
456 79109fed 2018-03-27 stsp show_patch = 1;
459 d142fc45 2018-04-01 stsp start_commit = optarg;
462 4a8520aa 2018-10-18 stsp diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
464 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
465 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
468 64a96a6d 2018-04-01 stsp limit = strtonum(optarg, 1, INT_MAX, &errstr);
469 64a96a6d 2018-04-01 stsp if (errstr != NULL)
470 64a96a6d 2018-04-01 stsp err(1, "-l option %s", errstr);
473 0ed6ed4c 2018-06-13 stsp first_parent_traversal = 1;
476 04ca23f4 2018-07-16 stsp repo_path = realpath(optarg, NULL);
477 04ca23f4 2018-07-16 stsp if (repo_path == NULL)
478 04ca23f4 2018-07-16 stsp err(1, "-r option");
482 79109fed 2018-03-27 stsp /* NOTREACHED */
486 79109fed 2018-03-27 stsp argc -= optind;
487 79109fed 2018-03-27 stsp argv += optind;
489 04ca23f4 2018-07-16 stsp if (argc == 0)
490 04ca23f4 2018-07-16 stsp path = strdup("");
491 04ca23f4 2018-07-16 stsp else if (argc == 1)
492 04ca23f4 2018-07-16 stsp path = strdup(argv[0]);
494 6f3d1eb0 2018-03-12 stsp usage_log();
495 04ca23f4 2018-07-16 stsp if (path == NULL)
496 04ca23f4 2018-07-16 stsp return got_error_from_errno();
498 04ca23f4 2018-07-16 stsp cwd = getcwd(NULL, 0);
499 04ca23f4 2018-07-16 stsp if (cwd == NULL) {
500 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
503 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
504 04ca23f4 2018-07-16 stsp repo_path = strdup(cwd);
505 04ca23f4 2018-07-16 stsp if (repo_path == NULL) {
506 04ca23f4 2018-07-16 stsp error = got_error_from_errno();
511 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
512 d7d4f210 2018-03-12 stsp if (error != NULL)
515 d142fc45 2018-04-01 stsp if (start_commit == NULL) {
516 3235492e 2018-04-01 stsp struct got_reference *head_ref;
517 3235492e 2018-04-01 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
518 3235492e 2018-04-01 stsp if (error != NULL)
519 3235492e 2018-04-01 stsp return error;
520 3235492e 2018-04-01 stsp error = got_ref_resolve(&id, repo, head_ref);
521 3235492e 2018-04-01 stsp got_ref_close(head_ref);
522 3235492e 2018-04-01 stsp if (error != NULL)
523 3235492e 2018-04-01 stsp return error;
524 3235492e 2018-04-01 stsp error = got_object_open(&obj, repo, id);
526 d1f2edc9 2018-06-13 stsp struct got_reference *ref;
527 d1f2edc9 2018-06-13 stsp error = got_ref_open(&ref, repo, start_commit);
528 3235492e 2018-04-01 stsp if (error == NULL) {
529 d1f2edc9 2018-06-13 stsp error = got_ref_resolve(&id, repo, ref);
530 d1f2edc9 2018-06-13 stsp got_ref_close(ref);
531 d1f2edc9 2018-06-13 stsp if (error != NULL)
532 d1f2edc9 2018-06-13 stsp return error;
533 d1f2edc9 2018-06-13 stsp error = got_object_open(&obj, repo, id);
534 d1f2edc9 2018-06-13 stsp if (error != NULL)
535 d1f2edc9 2018-06-13 stsp return error;
537 d1f2edc9 2018-06-13 stsp if (obj == NULL) {
538 d1f2edc9 2018-06-13 stsp error = got_object_open_by_id_str(&obj, repo,
539 d1f2edc9 2018-06-13 stsp start_commit);
540 d1f2edc9 2018-06-13 stsp if (error != NULL)
541 d1f2edc9 2018-06-13 stsp return error;
542 6402fb3c 2018-09-15 stsp id = got_object_id_dup(got_object_get_id(obj));
543 3235492e 2018-04-01 stsp if (id == NULL)
544 3235492e 2018-04-01 stsp error = got_error_from_errno();
547 d7d4f210 2018-03-12 stsp if (error != NULL)
549 04ca23f4 2018-07-16 stsp if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
550 8bf5b3c9 2018-03-17 stsp error = got_error(GOT_ERR_OBJ_TYPE);
554 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
555 04ca23f4 2018-07-16 stsp if (error != NULL)
557 04ca23f4 2018-07-16 stsp if (in_repo_path) {
558 04ca23f4 2018-07-16 stsp free(path);
559 04ca23f4 2018-07-16 stsp path = in_repo_path;
562 04ca23f4 2018-07-16 stsp error = print_commits(obj, id, repo, path, show_patch,
563 c0cc5c62 2018-10-18 stsp diff_context, limit, first_parent_traversal);
565 04ca23f4 2018-07-16 stsp free(path);
566 04ca23f4 2018-07-16 stsp free(repo_path);
569 04ca23f4 2018-07-16 stsp got_object_close(obj);
571 ad242220 2018-09-08 stsp if (repo) {
572 ad242220 2018-09-08 stsp const struct got_error *repo_error;
573 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
574 ad242220 2018-09-08 stsp if (error == NULL)
575 ad242220 2018-09-08 stsp error = repo_error;
577 8bf5b3c9 2018-03-17 stsp return error;
580 4ed7e80c 2018-05-20 stsp __dead static void
581 3f8b7d6a 2018-04-01 stsp usage_diff(void)
583 c0cc5c62 2018-10-18 stsp fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
584 c0cc5c62 2018-10-18 stsp "object1 object2\n", getprogname());
588 4ed7e80c 2018-05-20 stsp static const struct got_error *
589 b00d56cd 2018-04-01 stsp cmd_diff(int argc, char *argv[])
591 b00d56cd 2018-04-01 stsp const struct got_error *error;
592 b00d56cd 2018-04-01 stsp struct got_repository *repo = NULL;
593 b00d56cd 2018-04-01 stsp struct got_object *obj1 = NULL, *obj2 = NULL;
594 b00d56cd 2018-04-01 stsp char *repo_path = NULL;
595 b00d56cd 2018-04-01 stsp char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
596 c0cc5c62 2018-10-18 stsp int diff_context = 3, ch;
597 c0cc5c62 2018-10-18 stsp const char *errstr;
599 b00d56cd 2018-04-01 stsp #ifndef PROFILE
600 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
602 b00d56cd 2018-04-01 stsp err(1, "pledge");
605 c0cc5c62 2018-10-18 stsp while ((ch = getopt(argc, argv, "C:")) != -1) {
606 b00d56cd 2018-04-01 stsp switch (ch) {
608 c0cc5c62 2018-10-18 stsp diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
609 c0cc5c62 2018-10-18 stsp if (errstr != NULL)
610 c0cc5c62 2018-10-18 stsp err(1, "-C option %s", errstr);
614 b00d56cd 2018-04-01 stsp /* NOTREACHED */
618 b00d56cd 2018-04-01 stsp argc -= optind;
619 b00d56cd 2018-04-01 stsp argv += optind;
621 b00d56cd 2018-04-01 stsp if (argc == 0) {
622 b00d56cd 2018-04-01 stsp usage_diff(); /* TODO show local worktree changes */
623 3f8b7d6a 2018-04-01 stsp } else if (argc == 2) {
624 3f8b7d6a 2018-04-01 stsp repo_path = getcwd(NULL, 0);
625 3f8b7d6a 2018-04-01 stsp if (repo_path == NULL)
626 e1e3f570 2018-04-01 stsp return got_error_from_errno();
627 3f8b7d6a 2018-04-01 stsp obj_id_str1 = argv[0];
628 3f8b7d6a 2018-04-01 stsp obj_id_str2 = argv[1];
629 b00d56cd 2018-04-01 stsp } else if (argc == 3) {
630 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
631 76089277 2018-04-01 stsp if (repo_path == NULL)
632 76089277 2018-04-01 stsp return got_error_from_errno();
633 b00d56cd 2018-04-01 stsp obj_id_str1 = argv[1];
634 b00d56cd 2018-04-01 stsp obj_id_str2 = argv[2];
636 b00d56cd 2018-04-01 stsp usage_diff();
638 b00d56cd 2018-04-01 stsp error = got_repo_open(&repo, repo_path);
639 76089277 2018-04-01 stsp free(repo_path);
640 b00d56cd 2018-04-01 stsp if (error != NULL)
643 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
647 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
651 b00d56cd 2018-04-01 stsp if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
652 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
656 b00d56cd 2018-04-01 stsp switch (got_object_get_type(obj1)) {
657 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_BLOB:
658 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_blobs(obj1, obj2, NULL, NULL,
659 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
661 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_TREE:
662 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_trees(obj1, obj2, "", "",
663 c0cc5c62 2018-10-18 stsp diff_context, repo, stdout);
665 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_COMMIT:
666 c0cc5c62 2018-10-18 stsp error = got_diff_objects_as_commits(obj1, obj2, diff_context,
667 c0cc5c62 2018-10-18 stsp repo, stdout);
670 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
675 b00d56cd 2018-04-01 stsp got_object_close(obj1);
677 b00d56cd 2018-04-01 stsp got_object_close(obj2);
678 ad242220 2018-09-08 stsp if (repo) {
679 ad242220 2018-09-08 stsp const struct got_error *repo_error;
680 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
681 ad242220 2018-09-08 stsp if (error == NULL)
682 ad242220 2018-09-08 stsp error = repo_error;
684 b00d56cd 2018-04-01 stsp return error;
687 404c43c4 2018-06-21 stsp __dead static void
688 404c43c4 2018-06-21 stsp usage_blame(void)
690 66bea077 2018-08-02 stsp fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
691 404c43c4 2018-06-21 stsp getprogname());
695 404c43c4 2018-06-21 stsp static const struct got_error *
696 404c43c4 2018-06-21 stsp cmd_blame(int argc, char *argv[])
698 404c43c4 2018-06-21 stsp const struct got_error *error;
699 404c43c4 2018-06-21 stsp struct got_repository *repo = NULL;
700 66bea077 2018-08-02 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
701 404c43c4 2018-06-21 stsp struct got_object_id *commit_id = NULL;
702 404c43c4 2018-06-21 stsp char *commit_id_str = NULL;
705 404c43c4 2018-06-21 stsp #ifndef PROFILE
706 ad242220 2018-09-08 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
708 404c43c4 2018-06-21 stsp err(1, "pledge");
711 66bea077 2018-08-02 stsp while ((ch = getopt(argc, argv, "c:r:")) != -1) {
712 404c43c4 2018-06-21 stsp switch (ch) {
714 404c43c4 2018-06-21 stsp commit_id_str = optarg;
717 66bea077 2018-08-02 stsp repo_path = realpath(optarg, NULL);
718 66bea077 2018-08-02 stsp if (repo_path == NULL)
719 66bea077 2018-08-02 stsp err(1, "-r option");
723 404c43c4 2018-06-21 stsp /* NOTREACHED */
727 404c43c4 2018-06-21 stsp argc -= optind;
728 404c43c4 2018-06-21 stsp argv += optind;
730 a39318fd 2018-08-02 stsp if (argc == 1)
731 404c43c4 2018-06-21 stsp path = argv[0];
733 404c43c4 2018-06-21 stsp usage_blame();
735 66bea077 2018-08-02 stsp cwd = getcwd(NULL, 0);
736 66bea077 2018-08-02 stsp if (cwd == NULL) {
737 66bea077 2018-08-02 stsp error = got_error_from_errno();
740 66bea077 2018-08-02 stsp if (repo_path == NULL) {
741 66bea077 2018-08-02 stsp repo_path = strdup(cwd);
742 66bea077 2018-08-02 stsp if (repo_path == NULL) {
743 66bea077 2018-08-02 stsp error = got_error_from_errno();
748 404c43c4 2018-06-21 stsp error = got_repo_open(&repo, repo_path);
749 404c43c4 2018-06-21 stsp if (error != NULL)
752 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
753 66bea077 2018-08-02 stsp if (error != NULL)
756 404c43c4 2018-06-21 stsp if (commit_id_str == NULL) {
757 404c43c4 2018-06-21 stsp struct got_reference *head_ref;
758 404c43c4 2018-06-21 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
759 404c43c4 2018-06-21 stsp if (error != NULL)
761 404c43c4 2018-06-21 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
762 404c43c4 2018-06-21 stsp got_ref_close(head_ref);
763 404c43c4 2018-06-21 stsp if (error != NULL)
766 404c43c4 2018-06-21 stsp struct got_object *obj;
767 404c43c4 2018-06-21 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
768 404c43c4 2018-06-21 stsp if (error != NULL)
770 6402fb3c 2018-09-15 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
771 404c43c4 2018-06-21 stsp if (commit_id == NULL)
772 404c43c4 2018-06-21 stsp error = got_error_from_errno();
773 404c43c4 2018-06-21 stsp got_object_close(obj);
776 66bea077 2018-08-02 stsp error = got_blame(in_repo_path, commit_id, repo, stdout);
778 66bea077 2018-08-02 stsp free(in_repo_path);
779 66bea077 2018-08-02 stsp free(repo_path);
781 404c43c4 2018-06-21 stsp free(commit_id);
782 ad242220 2018-09-08 stsp if (repo) {
783 ad242220 2018-09-08 stsp const struct got_error *repo_error;
784 ad242220 2018-09-08 stsp repo_error = got_repo_close(repo);
785 ad242220 2018-09-08 stsp if (error == NULL)
786 ad242220 2018-09-08 stsp error = repo_error;
788 404c43c4 2018-06-21 stsp return error;
791 5de5890b 2018-10-18 stsp __dead static void
792 5de5890b 2018-10-18 stsp usage_tree(void)
794 5de5890b 2018-10-18 stsp fprintf(stderr, "usage: %s tree [-c commit] [-r repository-path] [-i] path\n",
795 5de5890b 2018-10-18 stsp getprogname());
800 5de5890b 2018-10-18 stsp static const struct got_error *
801 5de5890b 2018-10-18 stsp print_tree(const char *path, struct got_object_id *commit_id,
802 5de5890b 2018-10-18 stsp int show_ids, struct got_repository *repo)
804 5de5890b 2018-10-18 stsp const struct got_error *err = NULL;
805 5de5890b 2018-10-18 stsp struct got_object_id *tree_id = NULL;
806 5de5890b 2018-10-18 stsp struct got_tree_object *tree = NULL;
807 5de5890b 2018-10-18 stsp const struct got_tree_entries *entries;
808 5de5890b 2018-10-18 stsp struct got_tree_entry *te;
810 5de5890b 2018-10-18 stsp err = got_object_id_by_path(&tree_id, repo, commit_id, path);
814 5de5890b 2018-10-18 stsp err = got_object_open_as_tree(&tree, repo, tree_id);
817 5de5890b 2018-10-18 stsp entries = got_object_tree_get_entries(tree);
818 5de5890b 2018-10-18 stsp te = SIMPLEQ_FIRST(&entries->head);
819 5de5890b 2018-10-18 stsp while (te) {
820 5de5890b 2018-10-18 stsp char *id = NULL;
821 5de5890b 2018-10-18 stsp if (show_ids) {
822 5de5890b 2018-10-18 stsp char *id_str;
823 5de5890b 2018-10-18 stsp err = got_object_id_str(&id_str, te->id);
826 5de5890b 2018-10-18 stsp if (asprintf(&id, "%s ", id_str) == -1) {
827 5de5890b 2018-10-18 stsp err = got_error_from_errno();
828 5de5890b 2018-10-18 stsp free(id_str);
831 5de5890b 2018-10-18 stsp free(id_str);
833 5de5890b 2018-10-18 stsp printf("%s%s%s\n", id ? id : "",
834 5de5890b 2018-10-18 stsp te->name, S_ISDIR(te->mode) ? "/" : "");
835 5de5890b 2018-10-18 stsp te = SIMPLEQ_NEXT(te, entry);
840 5de5890b 2018-10-18 stsp got_object_tree_close(tree);
841 5de5890b 2018-10-18 stsp free(tree_id);
842 5de5890b 2018-10-18 stsp return err;
845 5de5890b 2018-10-18 stsp static const struct got_error *
846 5de5890b 2018-10-18 stsp cmd_tree(int argc, char *argv[])
848 5de5890b 2018-10-18 stsp const struct got_error *error;
849 5de5890b 2018-10-18 stsp struct got_repository *repo = NULL;
850 5de5890b 2018-10-18 stsp char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
851 5de5890b 2018-10-18 stsp struct got_object_id *commit_id = NULL;
852 5de5890b 2018-10-18 stsp char *commit_id_str = NULL;
853 5de5890b 2018-10-18 stsp int show_ids = 0;
856 5de5890b 2018-10-18 stsp #ifndef PROFILE
857 5de5890b 2018-10-18 stsp if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
859 5de5890b 2018-10-18 stsp err(1, "pledge");
862 5de5890b 2018-10-18 stsp while ((ch = getopt(argc, argv, "c:r:i")) != -1) {
863 5de5890b 2018-10-18 stsp switch (ch) {
865 5de5890b 2018-10-18 stsp commit_id_str = optarg;
868 5de5890b 2018-10-18 stsp repo_path = realpath(optarg, NULL);
869 5de5890b 2018-10-18 stsp if (repo_path == NULL)
870 5de5890b 2018-10-18 stsp err(1, "-r option");
873 5de5890b 2018-10-18 stsp show_ids = 1;
877 5de5890b 2018-10-18 stsp /* NOTREACHED */
881 5de5890b 2018-10-18 stsp argc -= optind;
882 5de5890b 2018-10-18 stsp argv += optind;
884 5de5890b 2018-10-18 stsp if (argc == 1)
885 5de5890b 2018-10-18 stsp path = argv[0];
886 5de5890b 2018-10-18 stsp else if (argc > 1)
887 5de5890b 2018-10-18 stsp usage_tree();
889 5de5890b 2018-10-18 stsp path = "/";
891 5de5890b 2018-10-18 stsp cwd = getcwd(NULL, 0);
892 5de5890b 2018-10-18 stsp if (cwd == NULL) {
893 5de5890b 2018-10-18 stsp error = got_error_from_errno();
896 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
897 5de5890b 2018-10-18 stsp repo_path = strdup(cwd);
898 5de5890b 2018-10-18 stsp if (repo_path == NULL) {
899 5de5890b 2018-10-18 stsp error = got_error_from_errno();
904 5de5890b 2018-10-18 stsp error = got_repo_open(&repo, repo_path);
905 5de5890b 2018-10-18 stsp if (error != NULL)
908 23721109 2018-10-22 stsp error = got_repo_map_path(&in_repo_path, repo, path, 1);
909 5de5890b 2018-10-18 stsp if (error != NULL)
912 5de5890b 2018-10-18 stsp if (commit_id_str == NULL) {
913 5de5890b 2018-10-18 stsp struct got_reference *head_ref;
914 5de5890b 2018-10-18 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
915 5de5890b 2018-10-18 stsp if (error != NULL)
917 5de5890b 2018-10-18 stsp error = got_ref_resolve(&commit_id, repo, head_ref);
918 5de5890b 2018-10-18 stsp got_ref_close(head_ref);
919 5de5890b 2018-10-18 stsp if (error != NULL)
922 5de5890b 2018-10-18 stsp struct got_object *obj;
923 5de5890b 2018-10-18 stsp error = got_object_open_by_id_str(&obj, repo, commit_id_str);
924 5de5890b 2018-10-18 stsp if (error != NULL)
926 5de5890b 2018-10-18 stsp commit_id = got_object_id_dup(got_object_get_id(obj));
927 5de5890b 2018-10-18 stsp if (commit_id == NULL)
928 5de5890b 2018-10-18 stsp error = got_error_from_errno();
929 5de5890b 2018-10-18 stsp got_object_close(obj);
932 5de5890b 2018-10-18 stsp error = print_tree(in_repo_path, commit_id, show_ids, repo);
934 5de5890b 2018-10-18 stsp free(in_repo_path);
935 5de5890b 2018-10-18 stsp free(repo_path);
937 5de5890b 2018-10-18 stsp free(commit_id);
938 5de5890b 2018-10-18 stsp if (repo) {
939 5de5890b 2018-10-18 stsp const struct got_error *repo_error;
940 5de5890b 2018-10-18 stsp repo_error = got_repo_close(repo);
941 5de5890b 2018-10-18 stsp if (error == NULL)
942 5de5890b 2018-10-18 stsp error = repo_error;
944 5de5890b 2018-10-18 stsp return error;
947 f42b1b34 2018-03-12 stsp #ifdef notyet
948 4ed7e80c 2018-05-20 stsp static const struct got_error *
949 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
951 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
952 5c860e29 2018-03-12 stsp git_status_list *status;
953 5c860e29 2018-03-12 stsp git_status_options statusopts;
956 5c860e29 2018-03-12 stsp git_libgit2_init();
958 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
959 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
961 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
962 5c860e29 2018-03-12 stsp errx(1, "bar repository");
964 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
965 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
967 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
968 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
969 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
970 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
972 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
973 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
975 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
976 5c860e29 2018-03-12 stsp const git_status_entry *se;
978 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
979 5c860e29 2018-03-12 stsp switch (se->status) {
980 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
981 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
983 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
984 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
986 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
987 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
989 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
990 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
991 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
992 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
994 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
995 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
997 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
998 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
1000 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
1001 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
1003 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
1004 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
1006 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
1007 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
1008 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
1009 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
1011 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
1012 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
1014 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
1020 5c860e29 2018-03-12 stsp git_status_list_free(status);
1021 5c860e29 2018-03-12 stsp git_repository_free(repo);
1022 5c860e29 2018-03-12 stsp git_libgit2_shutdown();