2 * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
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.
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.
18 #include <sys/queue.h>
19 #include <sys/limits.h>
20 #include <sys/types.h>
34 #include "got_error.h"
35 #include "got_object.h"
36 #include "got_reference.h"
37 #include "got_repository.h"
38 #include "got_worktree.h"
40 #include "got_commit_graph.h"
41 #include "got_blame.h"
42 #include "got_privsep.h"
45 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
48 static volatile sig_atomic_t sigint_received;
49 static volatile sig_atomic_t sigpipe_received;
52 catch_sigint(int signo)
58 catch_sigpipe(int signo)
66 const struct got_error *(*cmd_main)(int, char *[]);
67 void (*cmd_usage)(void);
68 const char *cmd_descr;
71 __dead static void usage(void);
72 __dead static void usage_checkout(void);
73 __dead static void usage_update(void);
74 __dead static void usage_log(void);
75 __dead static void usage_diff(void);
76 __dead static void usage_blame(void);
77 __dead static void usage_tree(void);
79 static const struct got_error* cmd_checkout(int, char *[]);
80 static const struct got_error* cmd_update(int, char *[]);
81 static const struct got_error* cmd_log(int, char *[]);
82 static const struct got_error* cmd_diff(int, char *[]);
83 static const struct got_error* cmd_blame(int, char *[]);
84 static const struct got_error* cmd_tree(int, char *[]);
86 static const struct got_error* cmd_status(int, char *[]);
89 static struct cmd got_commands[] = {
90 { "checkout", cmd_checkout, usage_checkout,
91 "check out a new work tree from a repository" },
92 { "update", cmd_update, usage_update,
93 "update a work tree to a different commit" },
94 { "log", cmd_log, usage_log,
95 "show repository history" },
96 { "diff", cmd_diff, usage_diff,
97 "compare files and directories" },
98 { "blame", cmd_blame, usage_blame,
99 " show when lines in a file were changed" },
100 { "tree", cmd_tree, usage_tree,
101 " list files and directories in repository" },
103 { "status", cmd_status, usage_status,
104 "show modification status of files" },
109 main(int argc, char *argv[])
116 setlocale(LC_ALL, "");
118 while ((ch = getopt(argc, argv, "h")) != -1) {
136 signal(SIGINT, catch_sigint);
137 signal(SIGPIPE, catch_sigpipe);
139 for (i = 0; i < nitems(got_commands); i++) {
140 const struct got_error *error;
142 cmd = &got_commands[i];
144 if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
148 got_commands[i].cmd_usage();
150 error = got_commands[i].cmd_main(argc, argv);
151 if (error && !(sigint_received || sigpipe_received)) {
152 fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
159 fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
168 fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
169 "Available commands:\n", getprogname());
170 for (i = 0; i < nitems(got_commands); i++) {
171 struct cmd *cmd = &got_commands[i];
172 fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
180 fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
181 "[worktree-path]\n", getprogname());
186 checkout_progress(void *arg, unsigned char status, const char *path)
188 char *worktree_path = arg;
190 while (path[0] == '/')
193 printf("%c %s/%s\n", status, worktree_path, path);
196 static const struct got_error *
197 checkout_cancel(void *arg)
199 if (sigint_received || sigpipe_received)
200 return got_error(GOT_ERR_CANCELLED);
204 static const struct got_error *
205 cmd_checkout(int argc, char *argv[])
207 const struct got_error *error = NULL;
208 struct got_repository *repo = NULL;
209 struct got_reference *head_ref = NULL;
210 struct got_worktree *worktree = NULL;
211 char *repo_path = NULL;
212 char *worktree_path = NULL;
213 const char *path_prefix = "";
214 int ch, same_path_prefix;
216 while ((ch = getopt(argc, argv, "p:")) != -1) {
219 path_prefix = optarg;
231 if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
236 char *cwd, *base, *dotgit;
237 repo_path = realpath(argv[0], NULL);
238 if (repo_path == NULL)
239 return got_error_from_errno();
240 cwd = getcwd(NULL, 0);
242 error = got_error_from_errno();
246 base = basename(path_prefix);
248 base = basename(repo_path);
250 error = got_error_from_errno();
253 dotgit = strstr(base, ".git");
256 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
257 error = got_error_from_errno();
262 } else if (argc == 2) {
263 repo_path = realpath(argv[0], NULL);
264 if (repo_path == NULL) {
265 error = got_error_from_errno();
268 worktree_path = realpath(argv[1], NULL);
269 if (worktree_path == NULL) {
270 error = got_error_from_errno();
276 if (unveil(repo_path, "r") != 0 ||
277 unveil(worktree_path, "rwc") != 0 ||
278 unveil("/tmp", "rwc") != 0) {
279 error = got_error_from_errno();
282 error = got_privsep_unveil_exec_helpers();
286 if (unveil(NULL, NULL) != 0) {
287 error = got_error_from_errno();
291 error = got_repo_open(&repo, repo_path);
294 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
298 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
299 if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST))
302 error = got_worktree_open(&worktree, worktree_path);
306 error = got_worktree_match_path_prefix(&same_path_prefix, worktree,
310 if (!same_path_prefix) {
311 error = got_error(GOT_ERR_PATH_PREFIX);
315 error = got_worktree_checkout_files(worktree, repo,
316 checkout_progress, worktree_path, checkout_cancel, NULL);
320 printf("Now shut up and hack\n");
331 fprintf(stderr, "usage: %s update [-c commit] [worktree-path]\n",
337 update_progress(void *arg, unsigned char status, const char *path)
339 if (status == GOT_STATUS_EXISTS)
342 while (path[0] == '/')
344 printf("%c %s\n", status, path);
347 static const struct got_error *
348 check_ancestry(struct got_worktree *worktree, struct got_object_id *commit_id,
349 struct got_repository *repo)
351 const struct got_error *err;
352 struct got_reference *head_ref = NULL;
353 struct got_object_id *head_commit_id = NULL;
354 struct got_commit_graph *graph = NULL;
356 head_ref = got_worktree_get_head_ref(worktree);
357 if (head_ref == NULL)
358 return got_error_from_errno();
360 /* TODO: Check the reflog. The head ref may have been rebased. */
361 err = got_ref_resolve(&head_commit_id, repo, head_ref);
365 err = got_commit_graph_open(&graph, head_commit_id, "/", 1, repo);
369 err = got_commit_graph_iter_start(graph, head_commit_id, repo);
373 struct got_object_id *id;
375 if (sigint_received || sigpipe_received)
378 err = got_commit_graph_iter_next(&id, graph);
380 if (err->code == GOT_ERR_ITER_COMPLETED) {
381 err = got_error(GOT_ERR_ANCESTRY);
384 if (err->code != GOT_ERR_ITER_NEED_MORE)
386 err = got_commit_graph_fetch_commits(graph, 1, repo);
394 if (got_object_id_cmp(id, commit_id) == 0)
399 got_ref_close(head_ref);
401 got_commit_graph_close(graph);
405 static const struct got_error *
406 cmd_update(int argc, char *argv[])
408 const struct got_error *error = NULL;
409 struct got_repository *repo = NULL;
410 struct got_worktree *worktree = NULL;
411 char *worktree_path = NULL;
412 struct got_object_id *commit_id = NULL;
413 char *commit_id_str = NULL;
416 while ((ch = getopt(argc, argv, "c:")) != -1) {
419 commit_id_str = strdup(optarg);
420 if (commit_id_str == NULL)
421 return got_error_from_errno();
433 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
438 worktree_path = getcwd(NULL, 0);
439 if (worktree_path == NULL) {
440 error = got_error_from_errno();
443 } else if (argc == 1) {
444 worktree_path = realpath(argv[0], NULL);
445 if (worktree_path == NULL) {
446 error = got_error_from_errno();
452 error = got_worktree_open(&worktree, worktree_path);
456 error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
460 if (commit_id_str == NULL) {
461 struct got_reference *head_ref;
462 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
465 error = got_ref_resolve(&commit_id, repo, head_ref);
468 error = got_object_id_str(&commit_id_str, commit_id);
472 error = got_object_resolve_id_str(&commit_id, repo,
478 error = check_ancestry(worktree, commit_id, repo);
482 if (got_object_id_cmp(got_worktree_get_base_commit_id(worktree),
484 error = got_worktree_set_base_commit_id(worktree, repo,
490 error = got_worktree_checkout_files(worktree, repo,
491 update_progress, NULL, checkout_cancel, NULL);
495 printf("Updated to commit %s\n", commit_id_str);
503 static const struct got_error *
504 print_patch(struct got_commit_object *commit, struct got_object_id *id,
505 int diff_context, struct got_repository *repo)
507 const struct got_error *err = NULL;
508 struct got_tree_object *tree1 = NULL, *tree2;
509 struct got_object_qid *qid;
510 char *id_str1 = NULL, *id_str2;
512 err = got_object_open_as_tree(&tree2, repo,
513 got_object_commit_get_tree_id(commit));
517 qid = SIMPLEQ_FIRST(got_object_commit_get_parent_ids(commit));
519 struct got_commit_object *pcommit;
521 err = got_object_open_as_commit(&pcommit, repo, qid->id);
525 err = got_object_open_as_tree(&tree1, repo,
526 got_object_commit_get_tree_id(pcommit));
527 got_object_commit_close(pcommit);
531 err = got_object_id_str(&id_str1, qid->id);
536 err = got_object_id_str(&id_str2, id);
540 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
541 err = got_diff_tree(tree1, tree2, "", "", diff_context, repo, stdout);
544 got_object_tree_close(tree1);
545 got_object_tree_close(tree2);
552 get_datestr(time_t *time, char *datebuf)
554 char *p, *s = ctime_r(time, datebuf);
561 static const struct got_error *
562 print_commit(struct got_commit_object *commit, struct got_object_id *id,
563 struct got_repository *repo, int show_patch, int diff_context)
565 const struct got_error *err = NULL;
566 char *id_str, *datestr, *logmsg0, *logmsg, *line;
568 time_t committer_time;
569 const char *author, *committer;
571 err = got_object_id_str(&id_str, id);
575 printf("-----------------------------------------------\n");
576 printf("commit %s\n", id_str);
578 printf("from: %s\n", got_object_commit_get_author(commit));
579 committer_time = got_object_commit_get_committer_time(commit);
580 datestr = get_datestr(&committer_time, datebuf);
581 printf("date: %s UTC\n", datestr);
582 author = got_object_commit_get_author(commit);
583 committer = got_object_commit_get_committer(commit);
584 if (strcmp(author, committer) != 0)
585 printf("via: %s\n", committer);
586 if (got_object_commit_get_nparents(commit) > 1) {
587 const struct got_object_id_queue *parent_ids;
588 struct got_object_qid *qid;
590 parent_ids = got_object_commit_get_parent_ids(commit);
591 SIMPLEQ_FOREACH(qid, parent_ids, entry) {
592 err = got_object_id_str(&id_str, qid->id);
595 printf("parent %d: %s\n", n++, id_str);
600 logmsg0 = strdup(got_object_commit_get_logmsg(commit));
602 return got_error_from_errno();
606 line = strsep(&logmsg, "\n");
608 printf(" %s\n", line);
613 err = print_patch(commit, id, diff_context, repo);
622 static const struct got_error *
623 print_commits(struct got_object_id *root_id, struct got_repository *repo,
624 char *path, int show_patch, int diff_context, int limit,
625 int first_parent_traversal)
627 const struct got_error *err;
628 struct got_commit_graph *graph;
630 err = got_commit_graph_open(&graph, root_id, path,
631 first_parent_traversal, repo);
634 err = got_commit_graph_iter_start(graph, root_id, repo);
638 struct got_commit_object *commit;
639 struct got_object_id *id;
641 if (sigint_received || sigpipe_received)
644 err = got_commit_graph_iter_next(&id, graph);
646 if (err->code == GOT_ERR_ITER_COMPLETED) {
650 if (err->code != GOT_ERR_ITER_NEED_MORE)
652 err = got_commit_graph_fetch_commits(graph, 1, repo);
661 err = got_object_open_as_commit(&commit, repo, id);
664 err = print_commit(commit, id, repo, show_patch, diff_context);
665 got_object_commit_close(commit);
666 if (err || (limit && --limit == 0))
670 got_commit_graph_close(graph);
677 fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
678 "[-r repository-path] [path]\n", getprogname());
682 static const struct got_error *
683 cmd_log(int argc, char *argv[])
685 const struct got_error *error;
686 struct got_repository *repo = NULL;
687 struct got_commit_object *commit = NULL;
688 struct got_object_id *id = NULL;
689 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
690 char *start_commit = NULL;
691 int diff_context = 3, ch;
692 int show_patch = 0, limit = 0, first_parent_traversal = 0;
696 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
701 while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
707 start_commit = optarg;
710 diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
713 err(1, "-C option %s", errstr);
716 limit = strtonum(optarg, 1, INT_MAX, &errstr);
718 err(1, "-l option %s", errstr);
721 first_parent_traversal = 1;
724 repo_path = realpath(optarg, NULL);
725 if (repo_path == NULL)
740 path = strdup(argv[0]);
744 return got_error_from_errno();
746 cwd = getcwd(NULL, 0);
748 error = got_error_from_errno();
751 if (repo_path == NULL) {
752 repo_path = strdup(cwd);
753 if (repo_path == NULL) {
754 error = got_error_from_errno();
759 error = got_repo_open(&repo, repo_path);
763 if (start_commit == NULL) {
764 struct got_reference *head_ref;
765 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
768 error = got_ref_resolve(&id, repo, head_ref);
769 got_ref_close(head_ref);
772 error = got_object_open_as_commit(&commit, repo, id);
774 struct got_reference *ref;
775 error = got_ref_open(&ref, repo, start_commit);
777 error = got_ref_resolve(&id, repo, ref);
781 error = got_object_open_as_commit(&commit, repo, id);
785 if (commit == NULL) {
786 error = got_object_resolve_id_str(&id, repo,
795 error = got_repo_map_path(&in_repo_path, repo, path, 1);
803 error = print_commits(id, repo, path, show_patch,
804 diff_context, limit, first_parent_traversal);
811 const struct got_error *repo_error;
812 repo_error = got_repo_close(repo);
822 fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
823 "object1 object2\n", getprogname());
827 static const struct got_error *
828 cmd_diff(int argc, char *argv[])
830 const struct got_error *error;
831 struct got_repository *repo = NULL;
832 char *repo_path = NULL;
833 struct got_object_id *id1 = NULL, *id2 = NULL;
834 char *id_str1 = NULL, *id_str2 = NULL;
836 int diff_context = 3, ch;
840 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
845 while ((ch = getopt(argc, argv, "C:")) != -1) {
848 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
850 err(1, "-C option %s", errstr);
862 usage_diff(); /* TODO show local worktree changes */
863 } else if (argc == 2) {
864 repo_path = getcwd(NULL, 0);
865 if (repo_path == NULL)
866 return got_error_from_errno();
869 } else if (argc == 3) {
870 repo_path = realpath(argv[0], NULL);
871 if (repo_path == NULL)
872 return got_error_from_errno();
878 error = got_repo_open(&repo, repo_path);
883 error = got_object_resolve_id_str(&id1, repo, id_str1);
887 error = got_object_resolve_id_str(&id2, repo, id_str2);
891 error = got_object_get_type(&type1, repo, id1);
895 error = got_object_get_type(&type2, repo, id2);
899 if (type1 != type2) {
900 error = got_error(GOT_ERR_OBJ_TYPE);
905 case GOT_OBJ_TYPE_BLOB:
906 error = got_diff_objects_as_blobs(id1, id2, NULL, NULL,
907 diff_context, repo, stdout);
909 case GOT_OBJ_TYPE_TREE:
910 error = got_diff_objects_as_trees(id1, id2, "", "",
911 diff_context, repo, stdout);
913 case GOT_OBJ_TYPE_COMMIT:
914 printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null",
916 error = got_diff_objects_as_commits(id1, id2, diff_context,
920 error = got_error(GOT_ERR_OBJ_TYPE);
927 const struct got_error *repo_error;
928 repo_error = got_repo_close(repo);
938 fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
943 static const struct got_error *
944 cmd_blame(int argc, char *argv[])
946 const struct got_error *error;
947 struct got_repository *repo = NULL;
948 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
949 struct got_object_id *commit_id = NULL;
950 char *commit_id_str = NULL;
954 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
959 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
962 commit_id_str = optarg;
965 repo_path = realpath(optarg, NULL);
966 if (repo_path == NULL)
983 cwd = getcwd(NULL, 0);
985 error = got_error_from_errno();
988 if (repo_path == NULL) {
989 repo_path = strdup(cwd);
990 if (repo_path == NULL) {
991 error = got_error_from_errno();
996 error = got_repo_open(&repo, repo_path);
1000 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1004 if (commit_id_str == NULL) {
1005 struct got_reference *head_ref;
1006 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
1009 error = got_ref_resolve(&commit_id, repo, head_ref);
1010 got_ref_close(head_ref);
1014 error = got_object_resolve_id_str(&commit_id, repo,
1020 error = got_blame(in_repo_path, commit_id, repo, stdout);
1027 const struct got_error *repo_error;
1028 repo_error = got_repo_close(repo);
1038 fprintf(stderr, "usage: %s tree [-c commit] [-r repository-path] [-i] path\n",
1044 static const struct got_error *
1045 print_tree(const char *path, struct got_object_id *commit_id,
1046 int show_ids, struct got_repository *repo)
1048 const struct got_error *err = NULL;
1049 struct got_object_id *tree_id = NULL;
1050 struct got_tree_object *tree = NULL;
1051 const struct got_tree_entries *entries;
1052 struct got_tree_entry *te;
1054 err = got_object_id_by_path(&tree_id, repo, commit_id, path);
1058 err = got_object_open_as_tree(&tree, repo, tree_id);
1061 entries = got_object_tree_get_entries(tree);
1062 te = SIMPLEQ_FIRST(&entries->head);
1066 if (sigint_received || sigpipe_received)
1071 err = got_object_id_str(&id_str, te->id);
1074 if (asprintf(&id, "%s ", id_str) == -1) {
1075 err = got_error_from_errno();
1081 printf("%s%s%s\n", id ? id : "",
1082 te->name, S_ISDIR(te->mode) ? "/" : "");
1083 te = SIMPLEQ_NEXT(te, entry);
1088 got_object_tree_close(tree);
1093 static const struct got_error *
1094 cmd_tree(int argc, char *argv[])
1096 const struct got_error *error;
1097 struct got_repository *repo = NULL;
1098 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
1099 struct got_object_id *commit_id = NULL;
1100 char *commit_id_str = NULL;
1105 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
1110 while ((ch = getopt(argc, argv, "c:r:i")) != -1) {
1113 commit_id_str = optarg;
1116 repo_path = realpath(optarg, NULL);
1117 if (repo_path == NULL)
1118 err(1, "-r option");
1139 cwd = getcwd(NULL, 0);
1141 error = got_error_from_errno();
1144 if (repo_path == NULL) {
1145 repo_path = strdup(cwd);
1146 if (repo_path == NULL) {
1147 error = got_error_from_errno();
1152 error = got_repo_open(&repo, repo_path);
1156 error = got_repo_map_path(&in_repo_path, repo, path, 1);
1160 if (commit_id_str == NULL) {
1161 struct got_reference *head_ref;
1162 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
1165 error = got_ref_resolve(&commit_id, repo, head_ref);
1166 got_ref_close(head_ref);
1170 error = got_object_resolve_id_str(&commit_id, repo,
1176 error = print_tree(in_repo_path, commit_id, show_ids, repo);
1183 const struct got_error *repo_error;
1184 repo_error = got_repo_close(repo);
1192 static const struct got_error *
1193 cmd_status(int argc __unused, char *argv[] __unused)
1195 git_repository *repo = NULL;
1196 git_status_list *status;
1197 git_status_options statusopts;
1202 if (git_repository_open_ext(&repo, ".", 0, NULL))
1203 errx(1, "git_repository_open: %s", giterr_last()->message);
1205 if (git_repository_is_bare(repo))
1206 errx(1, "bar repository");
1208 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
1209 errx(1, "git_status_init_options: %s", giterr_last()->message);
1211 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1212 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
1213 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
1214 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
1216 if (git_status_list_new(&status, repo, &statusopts))
1217 errx(1, "git_status_list_new: %s", giterr_last()->message);
1219 for (i = 0; i < git_status_list_entrycount(status); i++) {
1220 const git_status_entry *se;
1222 se = git_status_byindex(status, i);
1223 switch (se->status) {
1224 case GIT_STATUS_WT_NEW:
1225 printf("? %s\n", se->index_to_workdir->new_file.path);
1227 case GIT_STATUS_WT_MODIFIED:
1228 printf("M %s\n", se->index_to_workdir->new_file.path);
1230 case GIT_STATUS_WT_DELETED:
1231 printf("R %s\n", se->index_to_workdir->new_file.path);
1233 case GIT_STATUS_WT_RENAMED:
1234 printf("m %s -> %s\n",
1235 se->index_to_workdir->old_file.path,
1236 se->index_to_workdir->new_file.path);
1238 case GIT_STATUS_WT_TYPECHANGE:
1239 printf("t %s\n", se->index_to_workdir->new_file.path);
1241 case GIT_STATUS_INDEX_NEW:
1242 printf("A %s\n", se->head_to_index->new_file.path);
1244 case GIT_STATUS_INDEX_MODIFIED:
1245 printf("M %s\n", se->head_to_index->old_file.path);
1247 case GIT_STATUS_INDEX_DELETED:
1248 printf("R %s\n", se->head_to_index->old_file.path);
1250 case GIT_STATUS_INDEX_RENAMED:
1251 printf("m %s -> %s\n",
1252 se->head_to_index->old_file.path,
1253 se->head_to_index->new_file.path);
1255 case GIT_STATUS_INDEX_TYPECHANGE:
1256 printf("t %s\n", se->head_to_index->old_file.path);
1258 case GIT_STATUS_CURRENT:
1264 git_status_list_free(status);
1265 git_repository_free(repo);
1266 git_libgit2_shutdown();