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 int diff_context, 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, "", "", diff_context, 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, int diff_context)
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, diff_context, repo);
365 if (err == 0)
366 printf("\n");
369 fflush(stdout);
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 diff_context,
376 int limit, int first_parent_traversal)
378 const struct got_error *err;
379 struct got_commit_graph *graph;
381 err = got_commit_graph_open(&graph, root_id, path,
382 first_parent_traversal, repo);
383 if (err)
384 return err;
385 err = got_commit_graph_iter_start(graph, root_id, repo);
386 if (err)
387 goto done;
388 while (1) {
389 struct got_commit_object *commit;
390 struct got_object_id *id;
392 err = got_commit_graph_iter_next(&id, graph);
393 if (err) {
394 if (err->code == GOT_ERR_ITER_COMPLETED) {
395 err = NULL;
396 break;
398 if (err->code != GOT_ERR_ITER_NEED_MORE)
399 break;
400 err = got_commit_graph_fetch_commits(graph, 1, repo);
401 if (err)
402 break;
403 else
404 continue;
406 if (id == NULL)
407 break;
409 err = got_object_open_as_commit(&commit, repo, id);
410 if (err)
411 break;
412 err = print_commit(commit, id, repo, show_patch, diff_context);
413 got_object_commit_close(commit);
414 if (err || (limit && --limit == 0))
415 break;
417 done:
418 got_commit_graph_close(graph);
419 return err;
422 __dead static void
423 usage_log(void)
425 fprintf(stderr, "usage: %s log [-c commit] [-C number] [-f] [ -l N ] [-p] "
426 "[-r repository-path] [path]\n", getprogname());
427 exit(1);
430 static const struct got_error *
431 cmd_log(int argc, char *argv[])
433 const struct got_error *error;
434 struct got_repository *repo = NULL;
435 struct got_object_id *id = NULL;
436 struct got_object *obj = NULL;
437 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
438 char *start_commit = NULL;
439 int diff_context = 3, ch;
440 int show_patch = 0, limit = 0, first_parent_traversal = 0;
441 const char *errstr;
443 #ifndef PROFILE
444 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
445 == -1)
446 err(1, "pledge");
447 #endif
449 while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
450 switch (ch) {
451 case 'p':
452 show_patch = 1;
453 break;
454 case 'c':
455 start_commit = optarg;
456 break;
457 case 'C':
458 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
459 if (errstr != NULL)
460 err(1, "-C option %s", errstr);
461 break;
462 case 'l':
463 limit = strtonum(optarg, 1, INT_MAX, &errstr);
464 if (errstr != NULL)
465 err(1, "-l option %s", errstr);
466 break;
467 case 'f':
468 first_parent_traversal = 1;
469 break;
470 case 'r':
471 repo_path = realpath(optarg, NULL);
472 if (repo_path == NULL)
473 err(1, "-r option");
474 break;
475 default:
476 usage();
477 /* NOTREACHED */
481 argc -= optind;
482 argv += optind;
484 if (argc == 0)
485 path = strdup("");
486 else if (argc == 1)
487 path = strdup(argv[0]);
488 else
489 usage_log();
490 if (path == NULL)
491 return got_error_from_errno();
493 cwd = getcwd(NULL, 0);
494 if (cwd == NULL) {
495 error = got_error_from_errno();
496 goto done;
498 if (repo_path == NULL) {
499 repo_path = strdup(cwd);
500 if (repo_path == NULL) {
501 error = got_error_from_errno();
502 goto done;
506 error = got_repo_open(&repo, repo_path);
507 if (error != NULL)
508 goto done;
510 if (start_commit == NULL) {
511 struct got_reference *head_ref;
512 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
513 if (error != NULL)
514 return error;
515 error = got_ref_resolve(&id, repo, head_ref);
516 got_ref_close(head_ref);
517 if (error != NULL)
518 return error;
519 error = got_object_open(&obj, repo, id);
520 } else {
521 struct got_reference *ref;
522 error = got_ref_open(&ref, repo, start_commit);
523 if (error == NULL) {
524 error = got_ref_resolve(&id, repo, ref);
525 got_ref_close(ref);
526 if (error != NULL)
527 return error;
528 error = got_object_open(&obj, repo, id);
529 if (error != NULL)
530 return error;
532 if (obj == NULL) {
533 error = got_object_open_by_id_str(&obj, repo,
534 start_commit);
535 if (error != NULL)
536 return error;
537 id = got_object_id_dup(got_object_get_id(obj));
538 if (id == NULL)
539 error = got_error_from_errno();
542 if (error != NULL)
543 goto done;
544 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
545 error = got_error(GOT_ERR_OBJ_TYPE);
546 goto done;
549 error = got_repo_map_path(&in_repo_path, repo, path);
550 if (error != NULL)
551 goto done;
552 if (in_repo_path) {
553 free(path);
554 path = in_repo_path;
557 error = print_commits(obj, id, repo, path, show_patch,
558 diff_context, limit, first_parent_traversal);
559 done:
560 free(path);
561 free(repo_path);
562 free(cwd);
563 if (obj)
564 got_object_close(obj);
565 free(id);
566 if (repo) {
567 const struct got_error *repo_error;
568 repo_error = got_repo_close(repo);
569 if (error == NULL)
570 error = repo_error;
572 return error;
575 __dead static void
576 usage_diff(void)
578 fprintf(stderr, "usage: %s diff [-C number] [repository-path] "
579 "object1 object2\n", getprogname());
580 exit(1);
583 static const struct got_error *
584 cmd_diff(int argc, char *argv[])
586 const struct got_error *error;
587 struct got_repository *repo = NULL;
588 struct got_object *obj1 = NULL, *obj2 = NULL;
589 char *repo_path = NULL;
590 char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
591 int diff_context = 3, ch;
592 const char *errstr;
594 #ifndef PROFILE
595 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
596 == -1)
597 err(1, "pledge");
598 #endif
600 while ((ch = getopt(argc, argv, "C:")) != -1) {
601 switch (ch) {
602 case 'C':
603 diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
604 if (errstr != NULL)
605 err(1, "-C option %s", errstr);
606 break;
607 default:
608 usage();
609 /* NOTREACHED */
613 argc -= optind;
614 argv += optind;
616 if (argc == 0) {
617 usage_diff(); /* TODO show local worktree changes */
618 } else if (argc == 2) {
619 repo_path = getcwd(NULL, 0);
620 if (repo_path == NULL)
621 return got_error_from_errno();
622 obj_id_str1 = argv[0];
623 obj_id_str2 = argv[1];
624 } else if (argc == 3) {
625 repo_path = realpath(argv[0], NULL);
626 if (repo_path == NULL)
627 return got_error_from_errno();
628 obj_id_str1 = argv[1];
629 obj_id_str2 = argv[2];
630 } else
631 usage_diff();
633 error = got_repo_open(&repo, repo_path);
634 free(repo_path);
635 if (error != NULL)
636 goto done;
638 error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
639 if (error)
640 goto done;
642 error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
643 if (error)
644 goto done;
646 if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
647 error = got_error(GOT_ERR_OBJ_TYPE);
648 goto done;
651 switch (got_object_get_type(obj1)) {
652 case GOT_OBJ_TYPE_BLOB:
653 error = got_diff_objects_as_blobs(obj1, obj2, NULL, NULL,
654 diff_context, repo, stdout);
655 break;
656 case GOT_OBJ_TYPE_TREE:
657 error = got_diff_objects_as_trees(obj1, obj2, "", "",
658 diff_context, repo, stdout);
659 break;
660 case GOT_OBJ_TYPE_COMMIT:
661 error = got_diff_objects_as_commits(obj1, obj2, diff_context,
662 repo, stdout);
663 break;
664 default:
665 error = got_error(GOT_ERR_OBJ_TYPE);
668 done:
669 if (obj1)
670 got_object_close(obj1);
671 if (obj2)
672 got_object_close(obj2);
673 if (repo) {
674 const struct got_error *repo_error;
675 repo_error = got_repo_close(repo);
676 if (error == NULL)
677 error = repo_error;
679 return error;
682 __dead static void
683 usage_blame(void)
685 fprintf(stderr, "usage: %s blame [-c commit] [-r repository-path] path\n",
686 getprogname());
687 exit(1);
690 static const struct got_error *
691 cmd_blame(int argc, char *argv[])
693 const struct got_error *error;
694 struct got_repository *repo = NULL;
695 char *path, *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
696 struct got_object_id *commit_id = NULL;
697 char *commit_id_str = NULL;
698 int ch;
700 #ifndef PROFILE
701 if (pledge("stdio rpath wpath cpath flock proc exec sendfd", NULL)
702 == -1)
703 err(1, "pledge");
704 #endif
706 while ((ch = getopt(argc, argv, "c:r:")) != -1) {
707 switch (ch) {
708 case 'c':
709 commit_id_str = optarg;
710 break;
711 case 'r':
712 repo_path = realpath(optarg, NULL);
713 if (repo_path == NULL)
714 err(1, "-r option");
715 break;
716 default:
717 usage();
718 /* NOTREACHED */
722 argc -= optind;
723 argv += optind;
725 if (argc == 1)
726 path = argv[0];
727 else
728 usage_blame();
730 cwd = getcwd(NULL, 0);
731 if (cwd == NULL) {
732 error = got_error_from_errno();
733 goto done;
735 if (repo_path == NULL) {
736 repo_path = strdup(cwd);
737 if (repo_path == NULL) {
738 error = got_error_from_errno();
739 goto done;
743 error = got_repo_open(&repo, repo_path);
744 if (error != NULL)
745 goto done;
747 error = got_repo_map_path(&in_repo_path, repo, path);
748 if (error != NULL)
749 goto done;
751 if (commit_id_str == NULL) {
752 struct got_reference *head_ref;
753 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
754 if (error != NULL)
755 goto done;
756 error = got_ref_resolve(&commit_id, repo, head_ref);
757 got_ref_close(head_ref);
758 if (error != NULL)
759 goto done;
760 } else {
761 struct got_object *obj;
762 error = got_object_open_by_id_str(&obj, repo, commit_id_str);
763 if (error != NULL)
764 goto done;
765 commit_id = got_object_id_dup(got_object_get_id(obj));
766 if (commit_id == NULL)
767 error = got_error_from_errno();
768 got_object_close(obj);
771 error = got_blame(in_repo_path, commit_id, repo, stdout);
772 done:
773 free(in_repo_path);
774 free(repo_path);
775 free(cwd);
776 free(commit_id);
777 if (repo) {
778 const struct got_error *repo_error;
779 repo_error = got_repo_close(repo);
780 if (error == NULL)
781 error = repo_error;
783 return error;
786 #ifdef notyet
787 static const struct got_error *
788 cmd_status(int argc __unused, char *argv[] __unused)
790 git_repository *repo = NULL;
791 git_status_list *status;
792 git_status_options statusopts;
793 size_t i;
795 git_libgit2_init();
797 if (git_repository_open_ext(&repo, ".", 0, NULL))
798 errx(1, "git_repository_open: %s", giterr_last()->message);
800 if (git_repository_is_bare(repo))
801 errx(1, "bar repository");
803 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
804 errx(1, "git_status_init_options: %s", giterr_last()->message);
806 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
807 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
808 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
809 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
811 if (git_status_list_new(&status, repo, &statusopts))
812 errx(1, "git_status_list_new: %s", giterr_last()->message);
814 for (i = 0; i < git_status_list_entrycount(status); i++) {
815 const git_status_entry *se;
817 se = git_status_byindex(status, i);
818 switch (se->status) {
819 case GIT_STATUS_WT_NEW:
820 printf("? %s\n", se->index_to_workdir->new_file.path);
821 break;
822 case GIT_STATUS_WT_MODIFIED:
823 printf("M %s\n", se->index_to_workdir->new_file.path);
824 break;
825 case GIT_STATUS_WT_DELETED:
826 printf("R %s\n", se->index_to_workdir->new_file.path);
827 break;
828 case GIT_STATUS_WT_RENAMED:
829 printf("m %s -> %s\n",
830 se->index_to_workdir->old_file.path,
831 se->index_to_workdir->new_file.path);
832 break;
833 case GIT_STATUS_WT_TYPECHANGE:
834 printf("t %s\n", se->index_to_workdir->new_file.path);
835 break;
836 case GIT_STATUS_INDEX_NEW:
837 printf("A %s\n", se->head_to_index->new_file.path);
838 break;
839 case GIT_STATUS_INDEX_MODIFIED:
840 printf("M %s\n", se->head_to_index->old_file.path);
841 break;
842 case GIT_STATUS_INDEX_DELETED:
843 printf("R %s\n", se->head_to_index->old_file.path);
844 break;
845 case GIT_STATUS_INDEX_RENAMED:
846 printf("m %s -> %s\n",
847 se->head_to_index->old_file.path,
848 se->head_to_index->new_file.path);
849 break;
850 case GIT_STATUS_INDEX_TYPECHANGE:
851 printf("t %s\n", se->head_to_index->old_file.path);
852 break;
853 case GIT_STATUS_CURRENT:
854 default:
855 break;
859 git_status_list_free(status);
860 git_repository_free(repo);
861 git_libgit2_shutdown();
863 return 0;
865 #endif