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", NULL) == -1)
194 err(1, "pledge");
195 #endif
196 if (argc == 1) {
197 char *cwd, *base, *dotgit;
198 repo_path = realpath(argv[0], NULL);
199 if (repo_path == NULL)
200 return got_error_from_errno();
201 cwd = getcwd(NULL, 0);
202 if (cwd == NULL) {
203 error = got_error_from_errno();
204 goto done;
206 if (path_prefix[0])
207 base = basename(path_prefix);
208 else
209 base = basename(repo_path);
210 if (base == NULL) {
211 error = got_error_from_errno();
212 goto done;
214 dotgit = strstr(base, ".git");
215 if (dotgit)
216 *dotgit = '\0';
217 if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
218 error = got_error_from_errno();
219 free(cwd);
220 goto done;
222 free(cwd);
223 } else if (argc == 2) {
224 repo_path = realpath(argv[0], NULL);
225 if (repo_path == NULL) {
226 error = got_error_from_errno();
227 goto done;
229 worktree_path = realpath(argv[1], NULL);
230 if (worktree_path == NULL) {
231 error = got_error_from_errno();
232 goto done;
234 } else
235 usage_checkout();
237 error = got_repo_open(&repo, repo_path);
238 if (error != NULL)
239 goto done;
240 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
241 if (error != NULL)
242 goto done;
244 error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
245 if (error != NULL)
246 goto done;
248 error = got_worktree_open(&worktree, worktree_path);
249 if (error != NULL)
250 goto done;
252 error = got_worktree_checkout_files(worktree, head_ref, repo,
253 checkout_progress, worktree_path);
254 if (error != NULL)
255 goto done;
257 printf("Checked out %s\n", worktree_path);
258 printf("Now shut up and hack\n");
260 done:
261 free(repo_path);
262 free(worktree_path);
263 return error;
266 static const struct got_error *
267 print_patch(struct got_commit_object *commit, struct got_object_id *id,
268 struct got_repository *repo)
270 const struct got_error *err = NULL;
271 struct got_tree_object *tree1 = NULL, *tree2;
272 struct got_object_qid *qid;
274 err = got_object_open_as_tree(&tree2, repo, commit->tree_id);
275 if (err)
276 return err;
278 qid = SIMPLEQ_FIRST(&commit->parent_ids);
279 if (qid != NULL) {
280 struct got_commit_object *pcommit;
282 err = got_object_open_as_commit(&pcommit, repo, qid->id);
283 if (err)
284 return err;
286 err = got_object_open_as_tree(&tree1, repo, pcommit->tree_id);
287 got_object_commit_close(pcommit);
288 if (err)
289 return err;
292 err = got_diff_tree(tree1, tree2, repo, stdout);
293 if (tree1)
294 got_object_tree_close(tree1);
295 got_object_tree_close(tree2);
296 return err;
299 static char *
300 get_datestr(time_t *time, char *datebuf)
302 char *p, *s = ctime_r(time, datebuf);
303 p = strchr(s, '\n');
304 if (p)
305 *p = '\0';
306 return s;
309 static const struct got_error *
310 print_commit(struct got_commit_object *commit, struct got_object_id *id,
311 struct got_repository *repo, int show_patch)
313 const struct got_error *err = NULL;
314 char *id_str, *datestr, *logmsg0, *logmsg, *line;
315 char datebuf[26];
316 time_t author_time, committer_time;
318 err = got_object_id_str(&id_str, id);
319 if (err)
320 return err;
322 author_time = mktime(&commit->tm_author);
323 committer_time = mktime(&commit->tm_committer);
324 #if 0
325 /* This would express the date in committer's timezone. */
326 author_time += commit->tm_author.tm_gmtoff;
327 committer_time += commit->tm_committer.tm_gmtoff;
328 #endif
330 printf("-----------------------------------------------\n");
331 printf("commit %s\n", id_str);
332 free(id_str);
333 datestr = get_datestr(&author_time, datebuf);
334 printf("author: %s %s UTC\n", commit->author, datestr);
335 if (strcmp(commit->author, commit->committer) != 0 ||
336 author_time != committer_time) {
337 datestr = get_datestr(&committer_time, datebuf);
338 printf("committer: %s %s UTC\n", commit->committer, datestr);
340 if (commit->nparents > 1) {
341 struct got_object_qid *qid;
342 int n = 1;
343 SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
344 err = got_object_id_str(&id_str, qid->id);
345 if (err)
346 return err;
347 printf("parent %d: %s\n", n++, id_str);
348 free(id_str);
352 logmsg0 = strdup(commit->logmsg);
353 if (logmsg0 == NULL)
354 return got_error_from_errno();
356 logmsg = logmsg0;
357 do {
358 line = strsep(&logmsg, "\n");
359 if (line)
360 printf(" %s\n", line);
361 } while (line);
362 free(logmsg0);
364 if (show_patch) {
365 err = print_patch(commit, id, repo);
366 if (err == 0)
367 printf("\n");
370 return err;
373 static const struct got_error *
374 print_commits(struct got_object *root_obj, struct got_object_id *root_id,
375 struct got_repository *repo, char *path, int show_patch, int limit,
376 int first_parent_traversal)
378 const struct got_error *err;
379 struct got_commit_graph *graph;
380 int ncommits, found_obj = 0;
381 int is_root_path = (strcmp(path, "/") == 0);
383 err = got_commit_graph_open(&graph, root_id, first_parent_traversal,
384 repo);
385 if (err)
386 return err;
387 err = got_commit_graph_iter_start(graph, root_id);
388 if (err)
389 goto done;
390 do {
391 struct got_commit_object *commit;
392 struct got_object_id *id;
394 err = got_commit_graph_iter_next(&id, graph);
395 if (err) {
396 if (err->code == GOT_ERR_ITER_COMPLETED) {
397 err = NULL;
398 break;
400 if (err->code != GOT_ERR_ITER_NEED_MORE)
401 break;
402 err = got_commit_graph_fetch_commits(&ncommits,
403 graph, 1, repo);
404 if (err)
405 break;
406 else
407 continue;
409 if (id == NULL)
410 break;
412 err = got_object_open_as_commit(&commit, repo, id);
413 if (err)
414 break;
415 if (!is_root_path) {
416 struct got_object *obj;
417 struct got_object_qid *pid;
418 int changed = 0;
420 err = got_object_open_by_path(&obj, repo, id, path);
421 if (err) {
422 got_object_commit_close(commit);
423 if (err->code == GOT_ERR_NO_OBJ && found_obj) {
424 /*
425 * History of the path stops here
426 * on the current commit's branch.
427 * Keep logging on other branches.
428 */
429 err = NULL;
430 continue;
432 break;
434 found_obj = 1;
436 pid = SIMPLEQ_FIRST(&commit->parent_ids);
437 if (pid != NULL) {
438 struct got_object *pobj;
439 err = got_object_open_by_path(&pobj, repo,
440 pid->id, path);
441 if (err) {
442 if (err->code != GOT_ERR_NO_OBJ) {
443 got_object_close(obj);
444 got_object_commit_close(commit);
445 break;
447 err = NULL;
448 changed = 1;
449 } else {
450 changed = (got_object_id_cmp(
451 got_object_get_id(obj),
452 got_object_get_id(pobj)) != 0);
453 got_object_close(pobj);
456 got_object_close(obj);
457 if (!changed) {
458 got_object_commit_close(commit);
459 continue;
462 err = print_commit(commit, id, repo, show_patch);
463 got_object_commit_close(commit);
464 if (err || (limit && --limit == 0))
465 break;
466 } while (ncommits > 0);
467 done:
468 got_commit_graph_close(graph);
469 return err;
472 __dead static void
473 usage_log(void)
475 fprintf(stderr, "usage: %s log [-c commit] [-f] [ -l N ] [-p] "
476 "[-r repository-path] [path]\n", getprogname());
477 exit(1);
480 static const struct got_error *
481 cmd_log(int argc, char *argv[])
483 const struct got_error *error;
484 struct got_repository *repo = NULL;
485 struct got_object_id *id = NULL;
486 struct got_object *obj = NULL;
487 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
488 char *start_commit = NULL;
489 int ch;
490 int show_patch = 0, limit = 0, first_parent_traversal = 0;
491 const char *errstr;
493 #ifndef PROFILE
494 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
495 err(1, "pledge");
496 #endif
498 while ((ch = getopt(argc, argv, "pc:l:fr:")) != -1) {
499 switch (ch) {
500 case 'p':
501 show_patch = 1;
502 break;
503 case 'c':
504 start_commit = optarg;
505 break;
506 case 'l':
507 limit = strtonum(optarg, 1, INT_MAX, &errstr);
508 if (errstr != NULL)
509 err(1, "-l option %s", errstr);
510 break;
511 case 'f':
512 first_parent_traversal = 1;
513 break;
514 case 'r':
515 repo_path = realpath(optarg, NULL);
516 if (repo_path == NULL)
517 err(1, "-r option");
518 break;
519 default:
520 usage();
521 /* NOTREACHED */
525 argc -= optind;
526 argv += optind;
528 if (argc == 0)
529 path = strdup("");
530 else if (argc == 1)
531 path = strdup(argv[0]);
532 else
533 usage_log();
534 if (path == NULL)
535 return got_error_from_errno();
537 cwd = getcwd(NULL, 0);
538 if (cwd == NULL) {
539 error = got_error_from_errno();
540 goto done;
542 if (repo_path == NULL) {
543 repo_path = strdup(cwd);
544 if (repo_path == NULL) {
545 error = got_error_from_errno();
546 goto done;
550 error = got_repo_open(&repo, repo_path);
551 if (error != NULL)
552 goto done;
554 if (start_commit == NULL) {
555 struct got_reference *head_ref;
556 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
557 if (error != NULL)
558 return error;
559 error = got_ref_resolve(&id, repo, head_ref);
560 got_ref_close(head_ref);
561 if (error != NULL)
562 return error;
563 error = got_object_open(&obj, repo, id);
564 } else {
565 struct got_reference *ref;
566 error = got_ref_open(&ref, repo, start_commit);
567 if (error == NULL) {
568 error = got_ref_resolve(&id, repo, ref);
569 got_ref_close(ref);
570 if (error != NULL)
571 return error;
572 error = got_object_open(&obj, repo, id);
573 if (error != NULL)
574 return error;
576 if (obj == NULL) {
577 error = got_object_open_by_id_str(&obj, repo,
578 start_commit);
579 if (error != NULL)
580 return error;
581 id = got_object_get_id(obj);
582 if (id == NULL)
583 error = got_error_from_errno();
586 if (error != NULL)
587 goto done;
588 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
589 error = got_error(GOT_ERR_OBJ_TYPE);
590 goto done;
593 error = got_repo_map_path(&in_repo_path, repo, path);
594 if (error != NULL)
595 goto done;
596 if (in_repo_path) {
597 free(path);
598 path = in_repo_path;
601 error = print_commits(obj, id, repo, path, show_patch,
602 limit, first_parent_traversal);
603 done:
604 free(path);
605 free(repo_path);
606 free(cwd);
607 if (obj)
608 got_object_close(obj);
609 free(id);
610 if (repo)
611 got_repo_close(repo);
612 return error;
615 __dead static void
616 usage_diff(void)
618 fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
619 getprogname());
620 exit(1);
623 static const struct got_error *
624 cmd_diff(int argc, char *argv[])
626 const struct got_error *error;
627 struct got_repository *repo = NULL;
628 struct got_object_id *id1 = NULL, *id2 = NULL;
629 struct got_object *obj1 = NULL, *obj2 = NULL;
630 char *repo_path = NULL;
631 char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
632 int ch;
634 #ifndef PROFILE
635 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
636 err(1, "pledge");
637 #endif
639 while ((ch = getopt(argc, argv, "")) != -1) {
640 switch (ch) {
641 default:
642 usage();
643 /* NOTREACHED */
647 argc -= optind;
648 argv += optind;
650 if (argc == 0) {
651 usage_diff(); /* TODO show local worktree changes */
652 } else if (argc == 2) {
653 repo_path = getcwd(NULL, 0);
654 if (repo_path == NULL)
655 return got_error_from_errno();
656 obj_id_str1 = argv[0];
657 obj_id_str2 = argv[1];
658 } else if (argc == 3) {
659 repo_path = realpath(argv[0], NULL);
660 if (repo_path == NULL)
661 return got_error_from_errno();
662 obj_id_str1 = argv[1];
663 obj_id_str2 = argv[2];
664 } else
665 usage_diff();
667 error = got_repo_open(&repo, repo_path);
668 free(repo_path);
669 if (error != NULL)
670 goto done;
672 error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
673 if (error == NULL) {
674 id1 = got_object_get_id(obj1);
675 if (id1 == NULL)
676 error = got_error_from_errno();
678 if (error != NULL)
679 goto done;
681 error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
682 if (error == NULL) {
683 id2 = got_object_get_id(obj2);
684 if (id2 == NULL)
685 error = got_error_from_errno();
687 if (error != NULL)
688 goto done;
690 if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
691 error = got_error(GOT_ERR_OBJ_TYPE);
692 goto done;
695 switch (got_object_get_type(obj1)) {
696 case GOT_OBJ_TYPE_BLOB:
697 error = got_diff_objects_as_blobs(obj1, obj2, repo, stdout);
698 break;
699 case GOT_OBJ_TYPE_TREE:
700 error = got_diff_objects_as_trees(obj1, obj2, repo, stdout);
701 break;
702 case GOT_OBJ_TYPE_COMMIT:
703 error = got_diff_objects_as_commits(obj1, obj2, repo, stdout);
704 break;
705 default:
706 error = got_error(GOT_ERR_OBJ_TYPE);
709 done:
710 if (obj1)
711 got_object_close(obj1);
712 if (obj2)
713 got_object_close(obj2);
714 if (id1)
715 free(id1);
716 if (id2)
717 free(id2);
718 if (repo)
719 got_repo_close(repo);
720 return error;
723 __dead static void
724 usage_blame(void)
726 fprintf(stderr, "usage: %s blame [-c commit] [repository-path] path\n",
727 getprogname());
728 exit(1);
731 static const struct got_error *
732 cmd_blame(int argc, char *argv[])
734 const struct got_error *error;
735 struct got_repository *repo = NULL;
736 char *repo_path = NULL;
737 char *path = NULL;
738 struct got_object_id *commit_id = NULL;
739 char *commit_id_str = NULL;
740 int ch;
742 #ifndef PROFILE
743 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
744 err(1, "pledge");
745 #endif
747 while ((ch = getopt(argc, argv, "c:")) != -1) {
748 switch (ch) {
749 case 'c':
750 commit_id_str = optarg;
751 break;
752 default:
753 usage();
754 /* NOTREACHED */
758 argc -= optind;
759 argv += optind;
761 if (argc == 0) {
762 usage_blame();
763 } else if (argc == 1) {
764 repo_path = getcwd(NULL, 0);
765 if (repo_path == NULL)
766 return got_error_from_errno();
767 path = argv[0];
768 } else if (argc == 2) {
769 repo_path = realpath(argv[0], NULL);
770 if (repo_path == NULL)
771 return got_error_from_errno();
772 path = argv[1];
773 } else
774 usage_blame();
776 error = got_repo_open(&repo, repo_path);
777 free(repo_path);
778 if (error != NULL)
779 goto done;
781 if (commit_id_str == NULL) {
782 struct got_reference *head_ref;
783 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
784 if (error != NULL)
785 return error;
786 error = got_ref_resolve(&commit_id, repo, head_ref);
787 got_ref_close(head_ref);
788 if (error != NULL)
789 return error;
790 } else {
791 struct got_object *obj;
792 error = got_object_open_by_id_str(&obj, repo, commit_id_str);
793 if (error != NULL)
794 return error;
795 commit_id = got_object_get_id(obj);
796 if (commit_id == NULL)
797 error = got_error_from_errno();
798 got_object_close(obj);
801 error = got_blame(path, commit_id, repo, stdout);
802 done:
803 free(commit_id);
804 if (repo)
805 got_repo_close(repo);
806 return error;
809 #ifdef notyet
810 static const struct got_error *
811 cmd_status(int argc __unused, char *argv[] __unused)
813 git_repository *repo = NULL;
814 git_status_list *status;
815 git_status_options statusopts;
816 size_t i;
818 git_libgit2_init();
820 if (git_repository_open_ext(&repo, ".", 0, NULL))
821 errx(1, "git_repository_open: %s", giterr_last()->message);
823 if (git_repository_is_bare(repo))
824 errx(1, "bar repository");
826 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
827 errx(1, "git_status_init_options: %s", giterr_last()->message);
829 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
830 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
831 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
832 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
834 if (git_status_list_new(&status, repo, &statusopts))
835 errx(1, "git_status_list_new: %s", giterr_last()->message);
837 for (i = 0; i < git_status_list_entrycount(status); i++) {
838 const git_status_entry *se;
840 se = git_status_byindex(status, i);
841 switch (se->status) {
842 case GIT_STATUS_WT_NEW:
843 printf("? %s\n", se->index_to_workdir->new_file.path);
844 break;
845 case GIT_STATUS_WT_MODIFIED:
846 printf("M %s\n", se->index_to_workdir->new_file.path);
847 break;
848 case GIT_STATUS_WT_DELETED:
849 printf("R %s\n", se->index_to_workdir->new_file.path);
850 break;
851 case GIT_STATUS_WT_RENAMED:
852 printf("m %s -> %s\n",
853 se->index_to_workdir->old_file.path,
854 se->index_to_workdir->new_file.path);
855 break;
856 case GIT_STATUS_WT_TYPECHANGE:
857 printf("t %s\n", se->index_to_workdir->new_file.path);
858 break;
859 case GIT_STATUS_INDEX_NEW:
860 printf("A %s\n", se->head_to_index->new_file.path);
861 break;
862 case GIT_STATUS_INDEX_MODIFIED:
863 printf("M %s\n", se->head_to_index->old_file.path);
864 break;
865 case GIT_STATUS_INDEX_DELETED:
866 printf("R %s\n", se->head_to_index->old_file.path);
867 break;
868 case GIT_STATUS_INDEX_RENAMED:
869 printf("m %s -> %s\n",
870 se->head_to_index->old_file.path,
871 se->head_to_index->new_file.path);
872 break;
873 case GIT_STATUS_INDEX_TYPECHANGE:
874 printf("t %s\n", se->head_to_index->old_file.path);
875 break;
876 case GIT_STATUS_CURRENT:
877 default:
878 break;
882 git_status_list_free(status);
883 git_repository_free(repo);
884 git_libgit2_shutdown();
886 return 0;
888 #endif