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 *obj;
273 struct got_object_qid *qid;
275 err = got_object_open(&obj, repo, commit->tree_id);
276 if (err)
277 return err;
279 err = got_object_tree_open(&tree2, repo, obj);
280 got_object_close(obj);
281 if (err)
282 return err;
284 qid = SIMPLEQ_FIRST(&commit->parent_ids);
285 if (qid != NULL) {
286 struct got_commit_object *pcommit;
288 err = got_object_open(&obj, repo, qid->id);
289 if (err)
290 return err;
292 err = got_object_commit_open(&pcommit, repo, obj);
293 got_object_close(obj);
294 if (err)
295 return err;
297 err = got_object_open(&obj, repo, pcommit->tree_id);
298 got_object_commit_close(pcommit);
299 if (err)
300 return err;
301 err = got_object_tree_open(&tree1, repo, obj);
302 got_object_close(obj);
303 if (err)
304 return err;
307 err = got_diff_tree(tree1, tree2, repo, stdout);
308 if (tree1)
309 got_object_tree_close(tree1);
310 got_object_tree_close(tree2);
311 return err;
314 static char *
315 get_datestr(time_t *time, char *datebuf)
317 char *p, *s = ctime_r(time, datebuf);
318 p = strchr(s, '\n');
319 if (p)
320 *p = '\0';
321 return s;
324 static const struct got_error *
325 print_commit(struct got_commit_object *commit, struct got_object_id *id,
326 struct got_repository *repo, int show_patch)
328 const struct got_error *err = NULL;
329 char *id_str, *datestr, *logmsg, *line;
330 char datebuf[26];
331 time_t author_time, committer_time;
333 err = got_object_id_str(&id_str, id);
334 if (err)
335 return err;
337 author_time = mktime(&commit->tm_author);
338 committer_time = mktime(&commit->tm_committer);
339 #if 0
340 /* This would express the date in committer's timezone. */
341 author_time += commit->tm_author.tm_gmtoff;
342 committer_time += commit->tm_committer.tm_gmtoff;
343 #endif
345 printf("-----------------------------------------------\n");
346 printf("commit %s\n", id_str);
347 free(id_str);
348 datestr = get_datestr(&author_time, datebuf);
349 printf("author: %s %s UTC\n", commit->author, datestr);
350 if (strcmp(commit->author, commit->committer) != 0 ||
351 author_time != committer_time) {
352 datestr = get_datestr(&committer_time, datebuf);
353 printf("committer: %s %s UTC\n", commit->committer, datestr);
355 if (commit->nparents > 1) {
356 struct got_object_qid *qid;
357 int n = 1;
358 SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
359 err = got_object_id_str(&id_str, qid->id);
360 if (err)
361 return err;
362 printf("parent %d: %s\n", n++, id_str);
363 free(id_str);
367 logmsg = strdup(commit->logmsg);
368 if (logmsg == NULL)
369 return got_error_from_errno();
371 do {
372 line = strsep(&logmsg, "\n");
373 if (line)
374 printf(" %s\n", line);
375 } while (line);
376 free(logmsg);
378 if (show_patch) {
379 err = print_patch(commit, id, repo);
380 if (err == 0)
381 printf("\n");
384 return err;
387 static const struct got_error *
388 print_commits(struct got_object *root_obj, struct got_object_id *root_id,
389 struct got_repository *repo, char *path, int show_patch, int limit,
390 int first_parent_traversal)
392 const struct got_error *err;
393 struct got_commit_graph *graph;
394 int ncommits, found_obj = 0;
395 int is_root_path = (strcmp(path, "/") == 0);
397 err = got_commit_graph_open(&graph, root_id, first_parent_traversal,
398 repo);
399 if (err)
400 return err;
401 err = got_commit_graph_iter_start(graph, root_id);
402 if (err)
403 goto done;
404 do {
405 struct got_commit_object *commit;
406 struct got_object_id *id;
408 err = got_commit_graph_iter_next(&id, graph);
409 if (err) {
410 if (err->code == GOT_ERR_ITER_COMPLETED) {
411 err = NULL;
412 break;
414 if (err->code != GOT_ERR_ITER_NEED_MORE)
415 break;
416 err = got_commit_graph_fetch_commits(&ncommits,
417 graph, 1, repo);
418 if (err)
419 break;
420 else
421 continue;
423 if (id == NULL)
424 break;
426 err = got_object_open_as_commit(&commit, repo, id);
427 if (err)
428 break;
429 if (!is_root_path) {
430 struct got_object *obj;
431 struct got_object_qid *pid;
432 int changed = 0;
434 err = got_object_open_by_path(&obj, repo, id, path);
435 if (err) {
436 got_object_commit_close(commit);
437 if (err->code == GOT_ERR_NO_OBJ && found_obj) {
438 /*
439 * History of the path stops here
440 * on the current commit's branch.
441 * Keep logging on other branches.
442 */
443 err = NULL;
444 continue;
446 break;
448 found_obj = 1;
450 pid = SIMPLEQ_FIRST(&commit->parent_ids);
451 if (pid != NULL) {
452 struct got_object *pobj;
453 err = got_object_open_by_path(&pobj, repo,
454 pid->id, path);
455 if (err) {
456 if (err->code != GOT_ERR_NO_OBJ) {
457 got_object_close(obj);
458 got_object_commit_close(commit);
459 break;
461 err = NULL;
462 changed = 1;
463 } else {
464 changed = (got_object_id_cmp(
465 got_object_get_id(obj),
466 got_object_get_id(pobj)) != 0);
467 got_object_close(pobj);
470 got_object_close(obj);
471 if (!changed) {
472 got_object_commit_close(commit);
473 continue;
476 err = print_commit(commit, id, repo, show_patch);
477 got_object_commit_close(commit);
478 if (err || (limit && --limit == 0))
479 break;
480 } while (ncommits > 0);
481 done:
482 got_commit_graph_close(graph);
483 return err;
486 __dead static void
487 usage_log(void)
489 fprintf(stderr, "usage: %s log [-c commit] [-f] [ -l N ] [-p] "
490 "[-r repository-path] [path]\n", getprogname());
491 exit(1);
494 static const struct got_error *
495 cmd_log(int argc, char *argv[])
497 const struct got_error *error;
498 struct got_repository *repo = NULL;
499 struct got_object_id *id = NULL;
500 struct got_object *obj = NULL;
501 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
502 char *start_commit = NULL;
503 int ch;
504 int show_patch = 0, limit = 0, first_parent_traversal = 0;
505 const char *errstr;
507 #ifndef PROFILE
508 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
509 err(1, "pledge");
510 #endif
512 while ((ch = getopt(argc, argv, "pc:l:fr:")) != -1) {
513 switch (ch) {
514 case 'p':
515 show_patch = 1;
516 break;
517 case 'c':
518 start_commit = optarg;
519 break;
520 case 'l':
521 limit = strtonum(optarg, 1, INT_MAX, &errstr);
522 if (errstr != NULL)
523 err(1, "-l option %s", errstr);
524 break;
525 case 'f':
526 first_parent_traversal = 1;
527 break;
528 case 'r':
529 repo_path = realpath(optarg, NULL);
530 if (repo_path == NULL)
531 err(1, "-r option");
532 break;
533 default:
534 usage();
535 /* NOTREACHED */
539 argc -= optind;
540 argv += optind;
542 if (argc == 0)
543 path = strdup("");
544 else if (argc == 1)
545 path = strdup(argv[0]);
546 else
547 usage_log();
548 if (path == NULL)
549 return got_error_from_errno();
551 cwd = getcwd(NULL, 0);
552 if (cwd == NULL) {
553 error = got_error_from_errno();
554 goto done;
556 if (repo_path == NULL) {
557 repo_path = strdup(cwd);
558 if (repo_path == NULL) {
559 error = got_error_from_errno();
560 goto done;
564 error = got_repo_open(&repo, repo_path);
565 if (error != NULL)
566 goto done;
568 if (start_commit == NULL) {
569 struct got_reference *head_ref;
570 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
571 if (error != NULL)
572 return error;
573 error = got_ref_resolve(&id, repo, head_ref);
574 got_ref_close(head_ref);
575 if (error != NULL)
576 return error;
577 error = got_object_open(&obj, repo, id);
578 } else {
579 struct got_reference *ref;
580 error = got_ref_open(&ref, repo, start_commit);
581 if (error == NULL) {
582 error = got_ref_resolve(&id, repo, ref);
583 got_ref_close(ref);
584 if (error != NULL)
585 return error;
586 error = got_object_open(&obj, repo, id);
587 if (error != NULL)
588 return error;
590 if (obj == NULL) {
591 error = got_object_open_by_id_str(&obj, repo,
592 start_commit);
593 if (error != NULL)
594 return error;
595 id = got_object_get_id(obj);
596 if (id == NULL)
597 error = got_error_from_errno();
600 if (error != NULL)
601 goto done;
602 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
603 error = got_error(GOT_ERR_OBJ_TYPE);
604 goto done;
607 error = got_repo_map_path(&in_repo_path, repo, path);
608 if (error != NULL)
609 goto done;
610 if (in_repo_path) {
611 free(path);
612 path = in_repo_path;
615 error = print_commits(obj, id, repo, path, show_patch,
616 limit, first_parent_traversal);
617 done:
618 free(path);
619 free(repo_path);
620 free(cwd);
621 if (obj)
622 got_object_close(obj);
623 free(id);
624 if (repo)
625 got_repo_close(repo);
626 return error;
629 __dead static void
630 usage_diff(void)
632 fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
633 getprogname());
634 exit(1);
637 static const struct got_error *
638 cmd_diff(int argc, char *argv[])
640 const struct got_error *error;
641 struct got_repository *repo = NULL;
642 struct got_object_id *id1 = NULL, *id2 = NULL;
643 struct got_object *obj1 = NULL, *obj2 = NULL;
644 char *repo_path = NULL;
645 char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
646 int ch;
648 #ifndef PROFILE
649 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
650 err(1, "pledge");
651 #endif
653 while ((ch = getopt(argc, argv, "")) != -1) {
654 switch (ch) {
655 default:
656 usage();
657 /* NOTREACHED */
661 argc -= optind;
662 argv += optind;
664 if (argc == 0) {
665 usage_diff(); /* TODO show local worktree changes */
666 } else if (argc == 2) {
667 repo_path = getcwd(NULL, 0);
668 if (repo_path == NULL)
669 return got_error_from_errno();
670 obj_id_str1 = argv[0];
671 obj_id_str2 = argv[1];
672 } else if (argc == 3) {
673 repo_path = realpath(argv[0], NULL);
674 if (repo_path == NULL)
675 return got_error_from_errno();
676 obj_id_str1 = argv[1];
677 obj_id_str2 = argv[2];
678 } else
679 usage_diff();
681 error = got_repo_open(&repo, repo_path);
682 free(repo_path);
683 if (error != NULL)
684 goto done;
686 error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
687 if (error == NULL) {
688 id1 = got_object_get_id(obj1);
689 if (id1 == NULL)
690 error = got_error_from_errno();
692 if (error != NULL)
693 goto done;
695 error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
696 if (error == NULL) {
697 id2 = got_object_get_id(obj2);
698 if (id2 == NULL)
699 error = got_error_from_errno();
701 if (error != NULL)
702 goto done;
704 if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
705 error = got_error(GOT_ERR_OBJ_TYPE);
706 goto done;
709 switch (got_object_get_type(obj1)) {
710 case GOT_OBJ_TYPE_BLOB:
711 error = got_diff_objects_as_blobs(obj1, obj2, repo, stdout);
712 break;
713 case GOT_OBJ_TYPE_TREE:
714 error = got_diff_objects_as_trees(obj1, obj2, repo, stdout);
715 break;
716 case GOT_OBJ_TYPE_COMMIT:
717 error = got_diff_objects_as_commits(obj1, obj2, repo, stdout);
718 break;
719 default:
720 error = got_error(GOT_ERR_OBJ_TYPE);
723 done:
724 if (obj1)
725 got_object_close(obj1);
726 if (obj2)
727 got_object_close(obj2);
728 if (id1)
729 free(id1);
730 if (id2)
731 free(id2);
732 if (repo)
733 got_repo_close(repo);
734 return error;
737 __dead static void
738 usage_blame(void)
740 fprintf(stderr, "usage: %s blame [-c commit] [repository-path] path\n",
741 getprogname());
742 exit(1);
745 static const struct got_error *
746 cmd_blame(int argc, char *argv[])
748 const struct got_error *error;
749 struct got_repository *repo = NULL;
750 char *repo_path = NULL;
751 char *path = NULL;
752 struct got_object_id *commit_id = NULL;
753 char *commit_id_str = NULL;
754 int ch;
756 #ifndef PROFILE
757 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
758 err(1, "pledge");
759 #endif
761 while ((ch = getopt(argc, argv, "c:")) != -1) {
762 switch (ch) {
763 case 'c':
764 commit_id_str = optarg;
765 break;
766 default:
767 usage();
768 /* NOTREACHED */
772 argc -= optind;
773 argv += optind;
775 if (argc == 0) {
776 usage_blame();
777 } else if (argc == 1) {
778 repo_path = getcwd(NULL, 0);
779 if (repo_path == NULL)
780 return got_error_from_errno();
781 path = argv[0];
782 } else if (argc == 2) {
783 repo_path = realpath(argv[0], NULL);
784 if (repo_path == NULL)
785 return got_error_from_errno();
786 path = argv[1];
787 } else
788 usage_blame();
790 error = got_repo_open(&repo, repo_path);
791 free(repo_path);
792 if (error != NULL)
793 goto done;
795 if (commit_id_str == NULL) {
796 struct got_reference *head_ref;
797 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
798 if (error != NULL)
799 return error;
800 error = got_ref_resolve(&commit_id, repo, head_ref);
801 got_ref_close(head_ref);
802 if (error != NULL)
803 return error;
804 } else {
805 struct got_object *obj;
806 error = got_object_open_by_id_str(&obj, repo, commit_id_str);
807 if (error != NULL)
808 return error;
809 commit_id = got_object_get_id(obj);
810 if (commit_id == NULL)
811 error = got_error_from_errno();
812 got_object_close(obj);
815 error = got_blame(path, commit_id, repo, stdout);
816 done:
817 free(commit_id);
818 if (repo)
819 got_repo_close(repo);
820 return error;
823 #ifdef notyet
824 static const struct got_error *
825 cmd_status(int argc __unused, char *argv[] __unused)
827 git_repository *repo = NULL;
828 git_status_list *status;
829 git_status_options statusopts;
830 size_t i;
832 git_libgit2_init();
834 if (git_repository_open_ext(&repo, ".", 0, NULL))
835 errx(1, "git_repository_open: %s", giterr_last()->message);
837 if (git_repository_is_bare(repo))
838 errx(1, "bar repository");
840 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
841 errx(1, "git_status_init_options: %s", giterr_last()->message);
843 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
844 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
845 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
846 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
848 if (git_status_list_new(&status, repo, &statusopts))
849 errx(1, "git_status_list_new: %s", giterr_last()->message);
851 for (i = 0; i < git_status_list_entrycount(status); i++) {
852 const git_status_entry *se;
854 se = git_status_byindex(status, i);
855 switch (se->status) {
856 case GIT_STATUS_WT_NEW:
857 printf("? %s\n", se->index_to_workdir->new_file.path);
858 break;
859 case GIT_STATUS_WT_MODIFIED:
860 printf("M %s\n", se->index_to_workdir->new_file.path);
861 break;
862 case GIT_STATUS_WT_DELETED:
863 printf("R %s\n", se->index_to_workdir->new_file.path);
864 break;
865 case GIT_STATUS_WT_RENAMED:
866 printf("m %s -> %s\n",
867 se->index_to_workdir->old_file.path,
868 se->index_to_workdir->new_file.path);
869 break;
870 case GIT_STATUS_WT_TYPECHANGE:
871 printf("t %s\n", se->index_to_workdir->new_file.path);
872 break;
873 case GIT_STATUS_INDEX_NEW:
874 printf("A %s\n", se->head_to_index->new_file.path);
875 break;
876 case GIT_STATUS_INDEX_MODIFIED:
877 printf("M %s\n", se->head_to_index->old_file.path);
878 break;
879 case GIT_STATUS_INDEX_DELETED:
880 printf("R %s\n", se->head_to_index->old_file.path);
881 break;
882 case GIT_STATUS_INDEX_RENAMED:
883 printf("m %s -> %s\n",
884 se->head_to_index->old_file.path,
885 se->head_to_index->new_file.path);
886 break;
887 case GIT_STATUS_INDEX_TYPECHANGE:
888 printf("t %s\n", se->head_to_index->old_file.path);
889 break;
890 case GIT_STATUS_CURRENT:
891 default:
892 break;
896 git_status_list_free(status);
897 git_repository_free(repo);
898 git_libgit2_shutdown();
900 return 0;
902 #endif