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;
396 err = got_commit_graph_open(&graph, root_id, first_parent_traversal,
397 repo);
398 if (err)
399 return err;
400 err = got_commit_graph_iter_start(graph, root_id);
401 if (err)
402 return err;
403 do {
404 struct got_commit_object *commit;
405 struct got_object_id *id;
407 err = got_commit_graph_iter_next(&id, graph);
408 if (err) {
409 if (err->code == GOT_ERR_ITER_COMPLETED) {
410 err = NULL;
411 break;
413 if (err->code != GOT_ERR_ITER_NEED_MORE)
414 break;
415 err = got_commit_graph_fetch_commits(&ncommits,
416 graph, 1, repo);
417 if (err)
418 break;
419 else
420 continue;
422 if (id == NULL)
423 break;
425 err = got_object_open_as_commit(&commit, repo, id);
426 if (err)
427 return err;
428 if (path) {
429 struct got_object *obj;
430 struct got_object_qid *pid;
431 int changed = 1;
433 err = got_object_open_by_path(&obj, repo, id, path);
434 if (err) {
435 if (err->code == GOT_ERR_NO_OBJ && found_obj) {
436 /*
437 * Object was added in previous commit.
438 * History stops here.
439 */
440 err = NULL;
442 break;
444 found_obj = 1;
446 pid = SIMPLEQ_FIRST(&commit->parent_ids);
447 if (pid != NULL) {
448 struct got_object *pobj;
449 err = got_object_open_by_path(&pobj, repo,
450 pid->id, path);
451 if (err) {
452 if (err->code != GOT_ERR_NO_OBJ) {
453 got_object_close(obj);
454 break;
456 err = NULL;
457 changed = 1;
458 } else {
459 changed = got_object_id_cmp(
460 got_object_get_id(obj),
461 got_object_get_id(pobj));
462 got_object_close(pobj);
465 if (!changed) {
466 got_object_commit_close(commit);
467 continue;
470 err = print_commit(commit, id, repo, show_patch);
471 got_object_commit_close(commit);
472 if (err || (limit && --limit == 0))
473 break;
474 } while (ncommits > 0);
476 got_commit_graph_close(graph);
477 return err;
480 __dead static void
481 usage_log(void)
483 fprintf(stderr, "usage: %s log [-c commit] [-f] [ -l N ] [-p] "
484 "[-r repository-path] [path]\n", getprogname());
485 exit(1);
488 static const struct got_error *
489 cmd_log(int argc, char *argv[])
491 const struct got_error *error;
492 struct got_repository *repo = NULL;
493 struct got_object_id *id = NULL;
494 struct got_object *obj = NULL;
495 char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
496 char *start_commit = NULL;
497 int ch;
498 int show_patch = 0, limit = 0, first_parent_traversal = 0;
499 const char *errstr;
501 #ifndef PROFILE
502 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
503 err(1, "pledge");
504 #endif
506 while ((ch = getopt(argc, argv, "pc:l:fr:")) != -1) {
507 switch (ch) {
508 case 'p':
509 show_patch = 1;
510 break;
511 case 'c':
512 start_commit = optarg;
513 break;
514 case 'l':
515 limit = strtonum(optarg, 1, INT_MAX, &errstr);
516 if (errstr != NULL)
517 err(1, "-l option %s", errstr);
518 break;
519 case 'f':
520 first_parent_traversal = 1;
521 break;
522 case 'r':
523 repo_path = realpath(optarg, NULL);
524 if (repo_path == NULL)
525 err(1, "-r option");
526 break;
527 default:
528 usage();
529 /* NOTREACHED */
533 argc -= optind;
534 argv += optind;
536 if (argc == 0)
537 path = strdup("");
538 else if (argc == 1)
539 path = strdup(argv[0]);
540 else
541 usage_log();
542 if (path == NULL)
543 return got_error_from_errno();
545 cwd = getcwd(NULL, 0);
546 if (cwd == NULL) {
547 error = got_error_from_errno();
548 goto done;
550 if (repo_path == NULL) {
551 repo_path = strdup(cwd);
552 if (repo_path == NULL) {
553 error = got_error_from_errno();
554 goto done;
558 error = got_repo_open(&repo, repo_path);
559 if (error != NULL)
560 goto done;
562 if (start_commit == NULL) {
563 struct got_reference *head_ref;
564 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
565 if (error != NULL)
566 return error;
567 error = got_ref_resolve(&id, repo, head_ref);
568 got_ref_close(head_ref);
569 if (error != NULL)
570 return error;
571 error = got_object_open(&obj, repo, id);
572 } else {
573 struct got_reference *ref;
574 error = got_ref_open(&ref, repo, start_commit);
575 if (error == NULL) {
576 error = got_ref_resolve(&id, repo, ref);
577 got_ref_close(ref);
578 if (error != NULL)
579 return error;
580 error = got_object_open(&obj, repo, id);
581 if (error != NULL)
582 return error;
584 if (obj == NULL) {
585 error = got_object_open_by_id_str(&obj, repo,
586 start_commit);
587 if (error != NULL)
588 return error;
589 id = got_object_get_id(obj);
590 if (id == NULL)
591 error = got_error_from_errno();
594 if (error != NULL)
595 goto done;
596 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
597 error = got_error(GOT_ERR_OBJ_TYPE);
598 goto done;
601 error = got_repo_map_path(&in_repo_path, repo, path);
602 if (error != NULL)
603 goto done;
604 if (in_repo_path) {
605 free(path);
606 path = in_repo_path;
609 error = print_commits(obj, id, repo, path, show_patch,
610 limit, first_parent_traversal);
611 done:
612 free(path);
613 free(repo_path);
614 free(cwd);
615 if (obj)
616 got_object_close(obj);
617 free(id);
618 if (repo)
619 got_repo_close(repo);
620 return error;
623 __dead static void
624 usage_diff(void)
626 fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
627 getprogname());
628 exit(1);
631 static const struct got_error *
632 cmd_diff(int argc, char *argv[])
634 const struct got_error *error;
635 struct got_repository *repo = NULL;
636 struct got_object_id *id1 = NULL, *id2 = NULL;
637 struct got_object *obj1 = NULL, *obj2 = NULL;
638 char *repo_path = NULL;
639 char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
640 int ch;
642 #ifndef PROFILE
643 if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
644 err(1, "pledge");
645 #endif
647 while ((ch = getopt(argc, argv, "")) != -1) {
648 switch (ch) {
649 default:
650 usage();
651 /* NOTREACHED */
655 argc -= optind;
656 argv += optind;
658 if (argc == 0) {
659 usage_diff(); /* TODO show local worktree changes */
660 } else if (argc == 2) {
661 repo_path = getcwd(NULL, 0);
662 if (repo_path == NULL)
663 return got_error_from_errno();
664 obj_id_str1 = argv[0];
665 obj_id_str2 = argv[1];
666 } else if (argc == 3) {
667 repo_path = realpath(argv[0], NULL);
668 if (repo_path == NULL)
669 return got_error_from_errno();
670 obj_id_str1 = argv[1];
671 obj_id_str2 = argv[2];
672 } else
673 usage_diff();
675 error = got_repo_open(&repo, repo_path);
676 free(repo_path);
677 if (error != NULL)
678 goto done;
680 error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
681 if (error == NULL) {
682 id1 = got_object_get_id(obj1);
683 if (id1 == NULL)
684 error = got_error_from_errno();
686 if (error != NULL)
687 goto done;
689 error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
690 if (error == NULL) {
691 id2 = got_object_get_id(obj2);
692 if (id2 == NULL)
693 error = got_error_from_errno();
695 if (error != NULL)
696 goto done;
698 if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
699 error = got_error(GOT_ERR_OBJ_TYPE);
700 goto done;
703 switch (got_object_get_type(obj1)) {
704 case GOT_OBJ_TYPE_BLOB:
705 error = got_diff_objects_as_blobs(obj1, obj2, repo, stdout);
706 break;
707 case GOT_OBJ_TYPE_TREE:
708 error = got_diff_objects_as_trees(obj1, obj2, repo, stdout);
709 break;
710 case GOT_OBJ_TYPE_COMMIT:
711 error = got_diff_objects_as_commits(obj1, obj2, repo, stdout);
712 break;
713 default:
714 error = got_error(GOT_ERR_OBJ_TYPE);
717 done:
718 if (obj1)
719 got_object_close(obj1);
720 if (obj2)
721 got_object_close(obj2);
722 if (id1)
723 free(id1);
724 if (id2)
725 free(id2);
726 if (repo)
727 got_repo_close(repo);
728 return error;
731 __dead static void
732 usage_blame(void)
734 fprintf(stderr, "usage: %s blame [-c commit] [repository-path] path\n",
735 getprogname());
736 exit(1);
739 static const struct got_error *
740 cmd_blame(int argc, char *argv[])
742 const struct got_error *error;
743 struct got_repository *repo = NULL;
744 char *repo_path = NULL;
745 char *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", NULL) == -1)
752 err(1, "pledge");
753 #endif
755 while ((ch = getopt(argc, argv, "c:")) != -1) {
756 switch (ch) {
757 case 'c':
758 commit_id_str = optarg;
759 break;
760 default:
761 usage();
762 /* NOTREACHED */
766 argc -= optind;
767 argv += optind;
769 if (argc == 0) {
770 usage_blame();
771 } else if (argc == 1) {
772 repo_path = getcwd(NULL, 0);
773 if (repo_path == NULL)
774 return got_error_from_errno();
775 path = argv[0];
776 } else if (argc == 2) {
777 repo_path = realpath(argv[0], NULL);
778 if (repo_path == NULL)
779 return got_error_from_errno();
780 path = argv[1];
781 } else
782 usage_blame();
784 error = got_repo_open(&repo, repo_path);
785 free(repo_path);
786 if (error != NULL)
787 goto done;
789 if (commit_id_str == NULL) {
790 struct got_reference *head_ref;
791 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
792 if (error != NULL)
793 return error;
794 error = got_ref_resolve(&commit_id, repo, head_ref);
795 got_ref_close(head_ref);
796 if (error != NULL)
797 return error;
798 } else {
799 struct got_object *obj;
800 error = got_object_open_by_id_str(&obj, repo, commit_id_str);
801 if (error != NULL)
802 return error;
803 commit_id = got_object_get_id(obj);
804 if (commit_id == NULL)
805 error = got_error_from_errno();
806 got_object_close(obj);
809 error = got_blame(path, commit_id, repo, stdout);
810 done:
811 free(commit_id);
812 if (repo)
813 got_repo_close(repo);
814 return error;
817 #ifdef notyet
818 static const struct got_error *
819 cmd_status(int argc __unused, char *argv[] __unused)
821 git_repository *repo = NULL;
822 git_status_list *status;
823 git_status_options statusopts;
824 size_t i;
826 git_libgit2_init();
828 if (git_repository_open_ext(&repo, ".", 0, NULL))
829 errx(1, "git_repository_open: %s", giterr_last()->message);
831 if (git_repository_is_bare(repo))
832 errx(1, "bar repository");
834 if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
835 errx(1, "git_status_init_options: %s", giterr_last()->message);
837 statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
838 statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
839 GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
840 GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
842 if (git_status_list_new(&status, repo, &statusopts))
843 errx(1, "git_status_list_new: %s", giterr_last()->message);
845 for (i = 0; i < git_status_list_entrycount(status); i++) {
846 const git_status_entry *se;
848 se = git_status_byindex(status, i);
849 switch (se->status) {
850 case GIT_STATUS_WT_NEW:
851 printf("? %s\n", se->index_to_workdir->new_file.path);
852 break;
853 case GIT_STATUS_WT_MODIFIED:
854 printf("M %s\n", se->index_to_workdir->new_file.path);
855 break;
856 case GIT_STATUS_WT_DELETED:
857 printf("R %s\n", se->index_to_workdir->new_file.path);
858 break;
859 case GIT_STATUS_WT_RENAMED:
860 printf("m %s -> %s\n",
861 se->index_to_workdir->old_file.path,
862 se->index_to_workdir->new_file.path);
863 break;
864 case GIT_STATUS_WT_TYPECHANGE:
865 printf("t %s\n", se->index_to_workdir->new_file.path);
866 break;
867 case GIT_STATUS_INDEX_NEW:
868 printf("A %s\n", se->head_to_index->new_file.path);
869 break;
870 case GIT_STATUS_INDEX_MODIFIED:
871 printf("M %s\n", se->head_to_index->old_file.path);
872 break;
873 case GIT_STATUS_INDEX_DELETED:
874 printf("R %s\n", se->head_to_index->old_file.path);
875 break;
876 case GIT_STATUS_INDEX_RENAMED:
877 printf("m %s -> %s\n",
878 se->head_to_index->old_file.path,
879 se->head_to_index->new_file.path);
880 break;
881 case GIT_STATUS_INDEX_TYPECHANGE:
882 printf("t %s\n", se->head_to_index->old_file.path);
883 break;
884 case GIT_STATUS_CURRENT:
885 default:
886 break;
890 git_status_list_free(status);
891 git_repository_free(repo);
892 git_libgit2_shutdown();
894 return 0;
896 #endif