Blob


1 /*
2 * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/queue.h>
19 #include <sys/limits.h>
20 #include <sys/types.h>
22 #include <err.h>
23 #include <errno.h>
24 #include <locale.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <libgen.h>
30 #include <time.h>
32 #include "got_error.h"
33 #include "got_object.h"
34 #include "got_reference.h"
35 #include "got_repository.h"
36 #include "got_worktree.h"
37 #include "got_diff.h"
38 #include "got_commit_graph.h"
39 #include "got_blame.h"
41 #ifndef nitems
42 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
43 #endif
45 struct cmd {
46 const char *cmd_name;
47 const struct got_error *(*cmd_main)(int, char *[]);
48 void (*cmd_usage)(void);
49 const char *cmd_descr;
50 };
52 __dead static void usage(void);
53 __dead static void usage_checkout(void);
54 __dead static void usage_log(void);
55 __dead static void usage_diff(void);
56 __dead static void usage_blame(void);
58 static const struct got_error* cmd_checkout(int, char *[]);
59 static const struct got_error* cmd_log(int, char *[]);
60 static const struct got_error* cmd_diff(int, char *[]);
61 static const struct got_error* cmd_blame(int, char *[]);
62 #ifdef notyet
63 static const struct got_error* cmd_status(int, char *[]);
64 #endif
66 static struct cmd got_commands[] = {
67 { "checkout", cmd_checkout, usage_checkout,
68 "check out a new work tree from a repository" },
69 { "log", cmd_log, usage_log,
70 "show repository history" },
71 { "diff", cmd_diff, usage_diff,
72 "compare files and directories" },
73 { "blame", cmd_blame, usage_blame,
74 " show when lines in a file were changed" },
75 #ifdef notyet
76 { "status", cmd_status, usage_status,
77 "show modification status of files" },
78 #endif
79 };
81 int
82 main(int argc, char *argv[])
83 {
84 struct cmd *cmd;
85 unsigned int i;
86 int ch;
87 int hflag = 0;
89 setlocale(LC_ALL, "");
91 while ((ch = getopt(argc, argv, "h")) != -1) {
92 switch (ch) {
93 case 'h':
94 hflag = 1;
95 break;
96 default:
97 usage();
98 /* NOTREACHED */
99 }
102 argc -= optind;
103 argv += optind;
104 optind = 0;
106 if (argc <= 0)
107 usage();
109 for (i = 0; i < nitems(got_commands); i++) {
110 const struct got_error *error;
112 cmd = &got_commands[i];
114 if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
115 continue;
117 if (hflag)
118 got_commands[i].cmd_usage();
120 error = got_commands[i].cmd_main(argc, argv);
121 if (error) {
122 fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
123 return 1;
126 return 0;
129 fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
130 return 1;
133 __dead static void
134 usage(void)
136 int i;
138 fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
139 "Available commands:\n", getprogname());
140 for (i = 0; i < nitems(got_commands); i++) {
141 struct cmd *cmd = &got_commands[i];
142 fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
144 exit(1);
147 __dead static void
148 usage_checkout(void)
150 fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
151 "[worktree-path]\n", getprogname());
152 exit(1);
155 static void
156 checkout_progress(void *arg, const char *path)
158 char *worktree_path = arg;
160 while (path[0] == '/')
161 path++;
163 printf("A %s/%s\n", worktree_path, path);
166 static const struct got_error *
167 cmd_checkout(int argc, char *argv[])
169 const struct got_error *error = NULL;
170 struct got_repository *repo = NULL;
171 struct got_reference *head_ref = NULL;
172 struct got_worktree *worktree = NULL;
173 char *repo_path = NULL;
174 char *worktree_path = NULL;
175 const char *path_prefix = "";
176 int ch;
178 while ((ch = getopt(argc, argv, "p:")) != -1) {
179 switch (ch) {
180 case 'p':
181 path_prefix = optarg;
182 break;
183 default:
184 usage();
185 /* NOTREACHED */
189 argc -= optind;
190 argv += optind;
192 #ifndef PROFILE
193 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
194 == -1)
195 err(1, "pledge");
196 #endif
197 if (argc == 1) {
198 char *cwd, *base, *dotgit;
199 repo_path = realpath(argv[0], NULL);
200 if (repo_path == NULL)
201 return got_error_from_errno();
202 cwd = getcwd(NULL, 0);
203 if (cwd == NULL) {
204 error = got_error_from_errno();
205 goto done;
207 if (path_prefix[0])
208 base = basename(path_prefix);
209 else
210 base = basename(repo_path);
211 if (base == NULL) {
212 error = got_error_from_errno();
213 goto done;
215 dotgit = strstr(base, ".git");
216 if (dotgit)
217 *dotgit = '\0';
218 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
219 error = got_error_from_errno();
220 free(cwd);
221 goto done;
223 free(cwd);
224 } else if (argc == 2) {
225 repo_path = realpath(argv[0], NULL);
226 if (repo_path == NULL) {
227 error = got_error_from_errno();
228 goto done;
230 worktree_path = realpath(argv[1], NULL);
231 if (worktree_path == NULL) {
232 error = got_error_from_errno();
233 goto done;
235 } else
236 usage_checkout();
238 error = got_repo_open(&repo, repo_path);
239 if (error != NULL)
240 goto done;
241 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
242 if (error != NULL)
243 goto done;
245 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
246 if (error != NULL)
247 goto done;
249 error = got_worktree_open(&worktree, worktree_path);
250 if (error != NULL)
251 goto done;
253 error = got_worktree_checkout_files(worktree, head_ref, repo,
254 checkout_progress, worktree_path);
255 if (error != NULL)
256 goto done;
258 printf("Checked out %s\n", worktree_path);
259 printf("Now shut up and hack\n");
261 done:
262 free(repo_path);
263 free(worktree_path);
264 return error;
267 static const struct got_error *
268 print_patch(struct got_commit_object *commit, struct got_object_id *id,
269 struct got_repository *repo)
271 const struct got_error *err = NULL;
272 struct got_tree_object *tree1 = NULL, *tree2;
273 struct got_object_qid *qid;
275 err = got_object_open_as_tree(&tree2, repo, commit->tree_id);
276 if (err)
277 return err;
279 qid = SIMPLEQ_FIRST(&commit->parent_ids);
280 if (qid != NULL) {
281 struct got_commit_object *pcommit;
283 err = got_object_open_as_commit(&pcommit, repo, qid->id);
284 if (err)
285 return err;
287 err = got_object_open_as_tree(&tree1, repo, pcommit->tree_id);
288 got_object_commit_close(pcommit);
289 if (err)
290 return err;
293 err = got_diff_tree(tree1, tree2, "", "", repo, stdout);
294 if (tree1)
295 got_object_tree_close(tree1);
296 got_object_tree_close(tree2);
297 return err;
300 static char *
301 get_datestr(time_t *time, char *datebuf)
303 char *p, *s = ctime_r(time, datebuf);
304 p = strchr(s, '\n');
305 if (p)
306 *p = '\0';
307 return s;
310 static const struct got_error *
311 print_commit(struct got_commit_object *commit, struct got_object_id *id,
312 struct got_repository *repo, int show_patch)
314 const struct got_error *err = NULL;
315 char *id_str, *datestr, *logmsg0, *logmsg, *line;
316 char datebuf[26];
317 time_t author_time, committer_time;
319 err = got_object_id_str(&id_str, id);
320 if (err)
321 return err;
323 author_time = mktime(&commit->tm_author);
324 committer_time = mktime(&commit->tm_committer);
325 #if 0
326 /* This would express the date in committer's timezone. */
327 author_time += commit->tm_author.tm_gmtoff;
328 committer_time += commit->tm_committer.tm_gmtoff;
329 #endif
331 printf("-----------------------------------------------\n");
332 printf("commit %s\n", id_str);
333 free(id_str);
334 printf("from: %s\n", commit->author);
335 datestr = get_datestr(&committer_time, datebuf);
336 printf("date: %s UTC\n", datestr);
337 if (strcmp(commit->author, commit->committer) != 0)
338 printf("via: %s\n", commit->committer);
339 if (commit->nparents > 1) {
340 struct got_object_qid *qid;
341 int n = 1;
342 SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
343 err = got_object_id_str(&id_str, qid->id);
344 if (err)
345 return err;
346 printf("parent %d: %s\n", n++, id_str);
347 free(id_str);
351 logmsg0 = strdup(commit->logmsg);
352 if (logmsg0 == NULL)
353 return got_error_from_errno();
355 logmsg = logmsg0;
356 do {
357 line = strsep(&logmsg, "\n");
358 if (line)
359 printf(" %s\n", line);
360 } while (line);
361 free(logmsg0);
363 if (show_patch) {
364 err = print_patch(commit, id, repo);
365 if (err == 0)
366 printf("\n");
369 return err;
372 static const struct got_error *
373 detect_change(int *changed, struct got_object_id *commit_id,
374 struct got_object *obj, const char *path, struct got_repository *repo)
376 const struct got_error *err = NULL;
377 struct got_object_id *id, *pid;
378 struct got_object *pobj;
380 err = got_object_open_by_path(&pobj, repo, commit_id, path);
381 if (err) {
382 if (err->code != GOT_ERR_NO_OBJ)
383 return err;
384 *changed = 1;
385 return NULL;
388 id = got_object_get_id(obj);
389 pid = got_object_get_id(pobj);
390 *changed = (got_object_id_cmp(id, pid) != 0);
391 got_object_close(pobj);
392 return NULL;
395 static const struct got_error *
396 print_commits(struct got_object *root_obj, struct got_object_id *root_id,
397 struct got_repository *repo, char *path, int show_patch, int limit,
398 int first_parent_traversal)
400 const struct got_error *err;
401 struct got_commit_graph *graph;
402 int ncommits, found_obj = 0;
403 int is_root_path = (strcmp(path, "/") == 0);
405 err = got_commit_graph_open(&graph, root_id, first_parent_traversal,
406 repo);
407 if (err)
408 return err;
409 err = got_commit_graph_iter_start(graph, root_id);
410 if (err)
411 goto done;
412 do {
413 struct got_commit_object *commit;
414 struct got_object_id *id;
416 err = got_commit_graph_iter_next(&id, graph);
417 if (err) {
418 if (err->code == GOT_ERR_ITER_COMPLETED) {
419 err = NULL;
420 break;
422 if (err->code != GOT_ERR_ITER_NEED_MORE)
423 break;
424 err = got_commit_graph_fetch_commits(&ncommits,
425 graph, 1, repo);
426 if (err)
427 break;
428 else
429 continue;
431 if (id == NULL)
432 break;
434 err = got_object_open_as_commit(&commit, repo, id);
435 if (err)
436 break;
437 if (!is_root_path) {
438 struct got_object *obj;
439 struct got_object_qid *pid;
440 int changed = 0;
442 err = got_object_open_by_path(&obj, repo, id, path);
443 if (err) {
444 got_object_commit_close(commit);
445 if (err->code == GOT_ERR_NO_OBJ && found_obj) {
446 /*
447 * History of the path stops here
448 * on the current commit's branch.
449 * Keep logging on other branches.
450 */
451 err = NULL;
452 continue;
454 break;
456 found_obj = 1;
458 pid = SIMPLEQ_FIRST(&commit->parent_ids);
459 if (pid) {
460 err = detect_change(&changed, pid->id, obj,
461 path, repo);
462 if (err) {
463 got_object_close(obj);
464 got_object_commit_close(commit);
465 break;
468 got_object_close(obj);
469 if (!changed) {
470 got_object_commit_close(commit);
471 continue;
474 err = print_commit(commit, id, repo, show_patch);
475 got_object_commit_close(commit);
476 if (err || (limit && --limit == 0))
477 break;
478 } while (ncommits > 0);
479 done:
480 got_commit_graph_close(graph);
481 return err;
484 __dead static void
485 usage_log(void)
487 fprintf(stderr, "usage: %s log [-c commit] [-f] [ -l N ] [-p] "
488 "[-r repository-path] [path]\n", getprogname());
489 exit(1);
492 static const struct got_error *
493 cmd_log(int argc, char *argv[])
495 const struct got_error *error;
496 struct got_repository *repo = NULL;
497 struct got_object_id *id = NULL;
498 struct got_object *obj = NULL;
499 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
500 char *start_commit = NULL;
501 int ch;
502 int show_patch = 0, limit = 0, first_parent_traversal = 0;
503 const char *errstr;
505 #ifndef PROFILE
506 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
507 == -1)
508 err(1, "pledge");
509 #endif
511 while ((ch = getopt(argc, argv, "pc:l:fr:")) != -1) {
512 switch (ch) {
513 case 'p':
514 show_patch = 1;
515 break;
516 case 'c':
517 start_commit = optarg;
518 break;
519 case 'l':
520 limit = strtonum(optarg, 1, INT_MAX, &errstr);
521 if (errstr != NULL)
522 err(1, "-l option %s", errstr);
523 break;
524 case 'f':
525 first_parent_traversal = 1;
526 break;
527 case 'r':
528 repo_path = realpath(optarg, NULL);
529 if (repo_path == NULL)
530 err(1, "-r option");
531 break;
532 default:
533 usage();
534 /* NOTREACHED */
538 argc -= optind;
539 argv += optind;
541 if (argc == 0)
542 path = strdup("");
543 else if (argc == 1)
544 path = strdup(argv[0]);
545 else
546 usage_log();
547 if (path == NULL)
548 return got_error_from_errno();
550 cwd = getcwd(NULL, 0);
551 if (cwd == NULL) {
552 error = got_error_from_errno();
553 goto done;
555 if (repo_path == NULL) {
556 repo_path = strdup(cwd);
557 if (repo_path == NULL) {
558 error = got_error_from_errno();
559 goto done;
563 error = got_repo_open(&repo, repo_path);
564 if (error != NULL)
565 goto done;
567 if (start_commit == NULL) {
568 struct got_reference *head_ref;
569 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
570 if (error != NULL)
571 return error;
572 error = got_ref_resolve(&id, repo, head_ref);
573 got_ref_close(head_ref);
574 if (error != NULL)
575 return error;
576 error = got_object_open(&obj, repo, id);
577 } else {
578 struct got_reference *ref;
579 error = got_ref_open(&ref, repo, start_commit);
580 if (error == NULL) {
581 error = got_ref_resolve(&id, repo, ref);
582 got_ref_close(ref);
583 if (error != NULL)
584 return error;
585 error = got_object_open(&obj, repo, id);
586 if (error != NULL)
587 return error;
589 if (obj == NULL) {
590 error = got_object_open_by_id_str(&obj, repo,
591 start_commit);
592 if (error != NULL)
593 return error;
594 id = got_object_id_dup(got_object_get_id(obj));
595 if (id == NULL)
596 error = got_error_from_errno();
599 if (error != NULL)
600 goto done;
601 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
602 error = got_error(GOT_ERR_OBJ_TYPE);
603 goto done;
606 error = got_repo_map_path(&in_repo_path, repo, path);
607 if (error != NULL)
608 goto done;
609 if (in_repo_path) {
610 free(path);
611 path = in_repo_path;
614 error = print_commits(obj, id, repo, path, show_patch,
615 limit, first_parent_traversal);
616 done:
617 free(path);
618 free(repo_path);
619 free(cwd);
620 if (obj)
621 got_object_close(obj);
622 free(id);
623 if (repo) {
624 const struct got_error *repo_error;
625 repo_error = got_repo_close(repo);
626 if (error == NULL)
627 error = repo_error;
629 return error;
632 __dead static void
633 usage_diff(void)
635 fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
636 getprogname());
637 exit(1);
640 static const struct got_error *
641 cmd_diff(int argc, char *argv[])
643 const struct got_error *error;
644 struct got_repository *repo = NULL;
645 struct got_object *obj1 = NULL, *obj2 = NULL;
646 char *repo_path = NULL;
647 char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
648 int ch;
650 #ifndef PROFILE
651 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
652 == -1)
653 err(1, "pledge");
654 #endif
656 while ((ch = getopt(argc, argv, "")) != -1) {
657 switch (ch) {
658 default:
659 usage();
660 /* NOTREACHED */
664 argc -= optind;
665 argv += optind;
667 if (argc == 0) {
668 usage_diff(); /* TODO show local worktree changes */
669 } else if (argc == 2) {
670 repo_path = getcwd(NULL, 0);
671 if (repo_path == NULL)
672 return got_error_from_errno();
673 obj_id_str1 = argv[0];
674 obj_id_str2 = argv[1];
675 } else if (argc == 3) {
676 repo_path = realpath(argv[0], NULL);
677 if (repo_path == NULL)
678 return got_error_from_errno();
679 obj_id_str1 = argv[1];
680 obj_id_str2 = argv[2];
681 } else
682 usage_diff();
684 error = got_repo_open(&repo, repo_path);
685 free(repo_path);
686 if (error != NULL)
687 goto done;
689 error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
690 if (error)
691 goto done;
693 error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
694 if (error)
695 goto done;
697 if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
698 error = got_error(GOT_ERR_OBJ_TYPE);
699 goto done;
702 switch (got_object_get_type(obj1)) {
703 case GOT_OBJ_TYPE_BLOB:
704 error = got_diff_objects_as_blobs(obj1, obj2, NULL, NULL,
705 repo, stdout);
706 break;
707 case GOT_OBJ_TYPE_TREE:
708 error = got_diff_objects_as_trees(obj1, obj2, "", "", repo,
709 stdout);
710 break;
711 case GOT_OBJ_TYPE_COMMIT:
712 error = got_diff_objects_as_commits(obj1, obj2, repo, stdout);
713 break;
714 default:
715 error = got_error(GOT_ERR_OBJ_TYPE);
718 done:
719 if (obj1)
720 got_object_close(obj1);
721 if (obj2)
722 got_object_close(obj2);
723 if (repo) {
724 const struct got_error *repo_error;
725 repo_error = got_repo_close(repo);
726 if (error == NULL)
727 error = repo_error;
729 return error;
732 __dead static void
733 usage_blame(void)
735 fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
736 getprogname());
737 exit(1);
740 static const struct got_error *
741 cmd_blame(int argc, char *argv[])
743 const struct got_error *error;
744 struct got_repository *repo = NULL;
745 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
746 struct got_object_id *commit_id = NULL;
747 char *commit_id_str = NULL;
748 int ch;
750 #ifndef PROFILE
751 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
752 == -1)
753 err(1, "pledge");
754 #endif
756 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
757 switch (ch) {
758 case 'c':
759 commit_id_str = optarg;
760 break;
761 case 'r':
762 repo_path = realpath(optarg, NULL);
763 if (repo_path == NULL)
764 err(1, "-r option");
765 break;
766 default:
767 usage();
768 /* NOTREACHED */
772 argc -= optind;
773 argv += optind;
775 if (argc == 1)
776 path = argv[0];
777 else
778 usage_blame();
780 cwd = getcwd(NULL, 0);
781 if (cwd == NULL) {
782 error = got_error_from_errno();
783 goto done;
785 if (repo_path == NULL) {
786 repo_path = strdup(cwd);
787 if (repo_path == NULL) {
788 error = got_error_from_errno();
789 goto done;
793 error = got_repo_open(&repo, repo_path);
794 if (error != NULL)
795 goto done;
797 error = got_repo_map_path(&in_repo_path, repo, path);
798 if (error != NULL)
799 goto done;
801 if (commit_id_str == NULL) {
802 struct got_reference *head_ref;
803 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
804 if (error != NULL)
805 goto done;
806 error = got_ref_resolve(&commit_id, repo, head_ref);
807 got_ref_close(head_ref);
808 if (error != NULL)
809 goto done;
810 } else {
811 struct got_object *obj;
812 error = got_object_open_by_id_str(&obj, repo, commit_id_str);
813 if (error != NULL)
814 goto done;
815 commit_id = got_object_id_dup(got_object_get_id(obj));
816 if (commit_id == NULL)
817 error = got_error_from_errno();
818 got_object_close(obj);
821 error = got_blame(in_repo_path, commit_id, repo, stdout);
822 done:
823 free(in_repo_path);
824 free(repo_path);
825 free(cwd);
826 free(commit_id);
827 if (repo) {
828 const struct got_error *repo_error;
829 repo_error = got_repo_close(repo);
830 if (error == NULL)
831 error = repo_error;
833 return error;
836 #ifdef notyet
837 static const struct got_error *
838 cmd_status(int argc __unused, char *argv[] __unused)
840 git_repository *repo = NULL;
841 git_status_list *status;
842 git_status_options statusopts;
843 size_t i;
845 git_libgit2_init();
847 if (git_repository_open_ext(&repo, ".", 0, NULL))
848 errx(1, "git_repository_open: %s", giterr_last()->message);
850 if (git_repository_is_bare(repo))
851 errx(1, "bar repository");
853 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
854 errx(1, "git_status_init_options: %s", giterr_last()->message);
856 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
857 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
858 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
859 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
861 if (git_status_list_new(&status, repo, &statusopts))
862 errx(1, "git_status_list_new: %s", giterr_last()->message);
864 for (i = 0; i < git_status_list_entrycount(status); i++) {
865 const git_status_entry *se;
867 se = git_status_byindex(status, i);
868 switch (se->status) {
869 case GIT_STATUS_WT_NEW:
870 printf("? %s\n", se->index_to_workdir->new_file.path);
871 break;
872 case GIT_STATUS_WT_MODIFIED:
873 printf("M %s\n", se->index_to_workdir->new_file.path);
874 break;
875 case GIT_STATUS_WT_DELETED:
876 printf("R %s\n", se->index_to_workdir->new_file.path);
877 break;
878 case GIT_STATUS_WT_RENAMED:
879 printf("m %s -> %s\n",
880 se->index_to_workdir->old_file.path,
881 se->index_to_workdir->new_file.path);
882 break;
883 case GIT_STATUS_WT_TYPECHANGE:
884 printf("t %s\n", se->index_to_workdir->new_file.path);
885 break;
886 case GIT_STATUS_INDEX_NEW:
887 printf("A %s\n", se->head_to_index->new_file.path);
888 break;
889 case GIT_STATUS_INDEX_MODIFIED:
890 printf("M %s\n", se->head_to_index->old_file.path);
891 break;
892 case GIT_STATUS_INDEX_DELETED:
893 printf("R %s\n", se->head_to_index->old_file.path);
894 break;
895 case GIT_STATUS_INDEX_RENAMED:
896 printf("m %s -> %s\n",
897 se->head_to_index->old_file.path,
898 se->head_to_index->new_file.path);
899 break;
900 case GIT_STATUS_INDEX_TYPECHANGE:
901 printf("t %s\n", se->head_to_index->old_file.path);
902 break;
903 case GIT_STATUS_CURRENT:
904 default:
905 break;
909 git_status_list_free(status);
910 git_repository_free(repo);
911 git_libgit2_shutdown();
913 return 0;
915 #endif