Blame


1 5c860e29 2018-03-12 stsp /*
2 f42b1b34 2018-03-12 stsp * Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
3 f42b1b34 2018-03-12 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 5c860e29 2018-03-12 stsp *
5 5c860e29 2018-03-12 stsp * Permission to use, copy, modify, and distribute this software for any
6 5c860e29 2018-03-12 stsp * purpose with or without fee is hereby granted, provided that the above
7 5c860e29 2018-03-12 stsp * copyright notice and this permission notice appear in all copies.
8 5c860e29 2018-03-12 stsp *
9 5c860e29 2018-03-12 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 5c860e29 2018-03-12 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 5c860e29 2018-03-12 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 5c860e29 2018-03-12 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 5c860e29 2018-03-12 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 5c860e29 2018-03-12 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 5c860e29 2018-03-12 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 5c860e29 2018-03-12 stsp */
17 5c860e29 2018-03-12 stsp
18 f42b1b34 2018-03-12 stsp #include <sys/queue.h>
19 f42b1b34 2018-03-12 stsp
20 5c860e29 2018-03-12 stsp #include <err.h>
21 5c860e29 2018-03-12 stsp #include <errno.h>
22 5c860e29 2018-03-12 stsp #include <locale.h>
23 5c860e29 2018-03-12 stsp #include <stdio.h>
24 5c860e29 2018-03-12 stsp #include <stdlib.h>
25 5c860e29 2018-03-12 stsp #include <string.h>
26 5c860e29 2018-03-12 stsp #include <unistd.h>
27 c09a553d 2018-03-12 stsp #include <libgen.h>
28 5c860e29 2018-03-12 stsp
29 f42b1b34 2018-03-12 stsp #include "got_error.h"
30 f42b1b34 2018-03-12 stsp #include "got_object.h"
31 f42b1b34 2018-03-12 stsp #include "got_refs.h"
32 f42b1b34 2018-03-12 stsp #include "got_repository.h"
33 c09a553d 2018-03-12 stsp #include "got_worktree.h"
34 5c860e29 2018-03-12 stsp
35 5c860e29 2018-03-12 stsp #ifndef nitems
36 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
37 5c860e29 2018-03-12 stsp #endif
38 5c860e29 2018-03-12 stsp
39 5c860e29 2018-03-12 stsp struct cmd {
40 5c860e29 2018-03-12 stsp const char *cmd_name;
41 d7d4f210 2018-03-12 stsp const struct got_error *(*cmd_main)(int, char *[]);
42 1b6b95a8 2018-03-12 stsp void (*cmd_usage)(void);
43 46a0db7d 2018-03-12 stsp const char *cmd_descr;
44 5c860e29 2018-03-12 stsp };
45 5c860e29 2018-03-12 stsp
46 5c860e29 2018-03-12 stsp __dead void usage(void);
47 c09a553d 2018-03-12 stsp __dead void usage_checkout(void);
48 6f3d1eb0 2018-03-12 stsp __dead void usage_log(void);
49 5c860e29 2018-03-12 stsp
50 c09a553d 2018-03-12 stsp const struct got_error* cmd_checkout(int, char *[]);
51 d7d4f210 2018-03-12 stsp const struct got_error* cmd_log(int, char *[]);
52 d7d4f210 2018-03-12 stsp const struct got_error* cmd_status(int, char *[]);
53 5c860e29 2018-03-12 stsp
54 5c860e29 2018-03-12 stsp struct cmd got_commands[] = {
55 c09a553d 2018-03-12 stsp { "checkout", cmd_checkout, usage_checkout,
56 c09a553d 2018-03-12 stsp "check out a work tree from a repository" },
57 1b6b95a8 2018-03-12 stsp { "log", cmd_log, usage_log,
58 1b6b95a8 2018-03-12 stsp "show repository history" },
59 f42b1b34 2018-03-12 stsp #ifdef notyet
60 1b6b95a8 2018-03-12 stsp { "status", cmd_status, usage_status,
61 1b6b95a8 2018-03-12 stsp "show modification status of files" },
62 f42b1b34 2018-03-12 stsp #endif
63 5c860e29 2018-03-12 stsp };
64 5c860e29 2018-03-12 stsp
65 5c860e29 2018-03-12 stsp int
66 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
67 5c860e29 2018-03-12 stsp {
68 5c860e29 2018-03-12 stsp struct cmd *cmd;
69 5c860e29 2018-03-12 stsp unsigned int i;
70 5c860e29 2018-03-12 stsp int ch;
71 1b6b95a8 2018-03-12 stsp int hflag = 0;
72 5c860e29 2018-03-12 stsp
73 5c860e29 2018-03-12 stsp setlocale(LC_ALL, "");
74 5c860e29 2018-03-12 stsp
75 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
76 5c860e29 2018-03-12 stsp switch (ch) {
77 1b6b95a8 2018-03-12 stsp case 'h':
78 1b6b95a8 2018-03-12 stsp hflag = 1;
79 1b6b95a8 2018-03-12 stsp break;
80 5c860e29 2018-03-12 stsp default:
81 5c860e29 2018-03-12 stsp usage();
82 5c860e29 2018-03-12 stsp /* NOTREACHED */
83 5c860e29 2018-03-12 stsp }
84 5c860e29 2018-03-12 stsp }
85 5c860e29 2018-03-12 stsp
86 5c860e29 2018-03-12 stsp argc -= optind;
87 5c860e29 2018-03-12 stsp argv += optind;
88 5c860e29 2018-03-12 stsp
89 5c860e29 2018-03-12 stsp if (argc <= 0)
90 5c860e29 2018-03-12 stsp usage();
91 5c860e29 2018-03-12 stsp
92 5c860e29 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
93 d7d4f210 2018-03-12 stsp const struct got_error *error;
94 d7d4f210 2018-03-12 stsp
95 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
96 5c860e29 2018-03-12 stsp
97 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
98 5c860e29 2018-03-12 stsp continue;
99 5c860e29 2018-03-12 stsp
100 1b6b95a8 2018-03-12 stsp if (hflag)
101 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
102 1b6b95a8 2018-03-12 stsp
103 d7d4f210 2018-03-12 stsp error = got_commands[i].cmd_main(argc, argv);
104 d7d4f210 2018-03-12 stsp if (error) {
105 d7d4f210 2018-03-12 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
106 d7d4f210 2018-03-12 stsp return 1;
107 d7d4f210 2018-03-12 stsp }
108 d7d4f210 2018-03-12 stsp
109 d7d4f210 2018-03-12 stsp return 0;
110 5c860e29 2018-03-12 stsp }
111 5c860e29 2018-03-12 stsp
112 5c860e29 2018-03-12 stsp fprintf(stderr, "%s: unknown command -- %s\n", getprogname(), argv[0]);
113 5c860e29 2018-03-12 stsp return 1;
114 5c860e29 2018-03-12 stsp }
115 5c860e29 2018-03-12 stsp
116 5c860e29 2018-03-12 stsp __dead void
117 5c860e29 2018-03-12 stsp usage(void)
118 5c860e29 2018-03-12 stsp {
119 46a0db7d 2018-03-12 stsp int i;
120 46a0db7d 2018-03-12 stsp
121 987e94ba 2018-03-12 stsp fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
122 987e94ba 2018-03-12 stsp "Available commands:\n", getprogname());
123 46a0db7d 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
124 46a0db7d 2018-03-12 stsp struct cmd *cmd = &got_commands[i];
125 46a0db7d 2018-03-12 stsp fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
126 46a0db7d 2018-03-12 stsp }
127 5c860e29 2018-03-12 stsp exit(1);
128 5c860e29 2018-03-12 stsp }
129 5c860e29 2018-03-12 stsp
130 c09a553d 2018-03-12 stsp __dead void
131 c09a553d 2018-03-12 stsp usage_checkout(void)
132 c09a553d 2018-03-12 stsp {
133 c09a553d 2018-03-12 stsp fprintf(stderr, "usage: %s checkout REPO_PATH [WORKTREE_PATH]\n",
134 c09a553d 2018-03-12 stsp getprogname());
135 c09a553d 2018-03-12 stsp exit(1);
136 c09a553d 2018-03-12 stsp }
137 c09a553d 2018-03-12 stsp
138 c09a553d 2018-03-12 stsp const struct got_error *
139 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
140 c09a553d 2018-03-12 stsp {
141 c09a553d 2018-03-12 stsp const struct got_error *error = NULL;
142 c09a553d 2018-03-12 stsp struct got_repository *repo = NULL;
143 c09a553d 2018-03-12 stsp struct got_reference *head_ref = NULL;
144 c09a553d 2018-03-12 stsp struct got_worktree *worktree = NULL;
145 c09a553d 2018-03-12 stsp char *repo_path = NULL;
146 c09a553d 2018-03-12 stsp char *worktree_path = NULL;
147 c09a553d 2018-03-12 stsp
148 c09a553d 2018-03-12 stsp if (pledge("stdio rpath wpath cpath flock", NULL) == -1)
149 c09a553d 2018-03-12 stsp err(1, "pledge");
150 c09a553d 2018-03-12 stsp
151 c09a553d 2018-03-12 stsp if (argc == 2) {
152 c09a553d 2018-03-12 stsp char *cwd, *base, *dotgit;
153 c09a553d 2018-03-12 stsp repo_path = argv[1];
154 c09a553d 2018-03-12 stsp cwd = getcwd(NULL, 0);
155 c09a553d 2018-03-12 stsp if (cwd == NULL)
156 c09a553d 2018-03-12 stsp err(1, "getcwd");
157 c09a553d 2018-03-12 stsp base = basename(repo_path);
158 c09a553d 2018-03-12 stsp if (base == NULL)
159 c09a553d 2018-03-12 stsp err(1, "basename");
160 c09a553d 2018-03-12 stsp dotgit = strstr(base, ".git");
161 c09a553d 2018-03-12 stsp if (dotgit)
162 c09a553d 2018-03-12 stsp *dotgit = '\0';
163 c09a553d 2018-03-12 stsp if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
164 c09a553d 2018-03-12 stsp free(cwd);
165 c09a553d 2018-03-12 stsp return got_error(GOT_ERR_NO_MEM);
166 c09a553d 2018-03-12 stsp }
167 c09a553d 2018-03-12 stsp free(cwd);
168 c09a553d 2018-03-12 stsp } else if (argc == 3) {
169 c09a553d 2018-03-12 stsp repo_path = argv[1];
170 c09a553d 2018-03-12 stsp worktree_path = strdup(argv[2]);
171 c09a553d 2018-03-12 stsp if (worktree_path == NULL)
172 c09a553d 2018-03-12 stsp return got_error(GOT_ERR_NO_MEM);
173 c09a553d 2018-03-12 stsp } else
174 c09a553d 2018-03-12 stsp usage_checkout();
175 c09a553d 2018-03-12 stsp
176 c09a553d 2018-03-12 stsp printf("%s %s %s %s\n", getprogname(), argv[0], repo_path, worktree_path);
177 c09a553d 2018-03-12 stsp
178 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
179 c09a553d 2018-03-12 stsp if (error != NULL)
180 c09a553d 2018-03-12 stsp goto done;
181 c09a553d 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
182 c09a553d 2018-03-12 stsp if (error != NULL)
183 c09a553d 2018-03-12 stsp goto done;
184 c09a553d 2018-03-12 stsp
185 c09a553d 2018-03-12 stsp error = got_worktree_init(worktree_path, head_ref, "/", repo);
186 c09a553d 2018-03-12 stsp if (error != NULL)
187 c09a553d 2018-03-12 stsp goto done;
188 c09a553d 2018-03-12 stsp
189 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
190 c09a553d 2018-03-12 stsp if (error != NULL)
191 c09a553d 2018-03-12 stsp goto done;
192 c09a553d 2018-03-12 stsp
193 c09a553d 2018-03-12 stsp error = got_worktree_checkout_files(worktree, head_ref, repo);
194 c09a553d 2018-03-12 stsp if (error != NULL)
195 c09a553d 2018-03-12 stsp goto done;
196 c09a553d 2018-03-12 stsp
197 c09a553d 2018-03-12 stsp printf("checked out %s\n", worktree_path);
198 c09a553d 2018-03-12 stsp
199 c09a553d 2018-03-12 stsp done:
200 c09a553d 2018-03-12 stsp free(worktree_path);
201 c09a553d 2018-03-12 stsp return error;
202 c09a553d 2018-03-12 stsp }
203 c09a553d 2018-03-12 stsp
204 f42b1b34 2018-03-12 stsp static const struct got_error *
205 f42b1b34 2018-03-12 stsp print_commit_object(struct got_object *, struct got_object_id *,
206 f42b1b34 2018-03-12 stsp struct got_repository *);
207 f42b1b34 2018-03-12 stsp
208 f42b1b34 2018-03-12 stsp static const struct got_error *
209 f42b1b34 2018-03-12 stsp print_parent_commits(struct got_commit_object *commit,
210 f42b1b34 2018-03-12 stsp struct got_repository *repo)
211 5c860e29 2018-03-12 stsp {
212 f42b1b34 2018-03-12 stsp struct got_parent_id *pid;
213 f42b1b34 2018-03-12 stsp const struct got_error *err = NULL;
214 f42b1b34 2018-03-12 stsp struct got_object *obj;
215 5c860e29 2018-03-12 stsp
216 f42b1b34 2018-03-12 stsp SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
217 f42b1b34 2018-03-12 stsp err = got_object_open(&obj, repo, pid->id);
218 f42b1b34 2018-03-12 stsp if (err != NULL)
219 f42b1b34 2018-03-12 stsp return err;
220 f42b1b34 2018-03-12 stsp if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT)
221 f42b1b34 2018-03-12 stsp return got_error(GOT_ERR_OBJ_TYPE);
222 f42b1b34 2018-03-12 stsp err = print_commit_object(obj, pid->id, repo);
223 f42b1b34 2018-03-12 stsp got_object_close(obj);
224 f42b1b34 2018-03-12 stsp }
225 5c860e29 2018-03-12 stsp
226 f42b1b34 2018-03-12 stsp return err;
227 f42b1b34 2018-03-12 stsp }
228 5c860e29 2018-03-12 stsp
229 f42b1b34 2018-03-12 stsp static const struct got_error *
230 f42b1b34 2018-03-12 stsp print_commit_object(struct got_object *obj, struct got_object_id *id,
231 f42b1b34 2018-03-12 stsp struct got_repository *repo)
232 f42b1b34 2018-03-12 stsp {
233 f42b1b34 2018-03-12 stsp struct got_commit_object *commit;
234 f42b1b34 2018-03-12 stsp char *buf;
235 f42b1b34 2018-03-12 stsp const struct got_error *err;
236 5c860e29 2018-03-12 stsp
237 f42b1b34 2018-03-12 stsp err = got_object_commit_open(&commit, repo, obj);
238 f42b1b34 2018-03-12 stsp if (err)
239 f42b1b34 2018-03-12 stsp return err;
240 5c860e29 2018-03-12 stsp
241 f42b1b34 2018-03-12 stsp err = got_object_id_str(&buf, id);
242 f42b1b34 2018-03-12 stsp if (err)
243 f42b1b34 2018-03-12 stsp return err;
244 5c860e29 2018-03-12 stsp
245 f42b1b34 2018-03-12 stsp printf("-----------------------------------------------\n");
246 f42b1b34 2018-03-12 stsp printf("commit: %s\n", buf);
247 f42b1b34 2018-03-12 stsp printf("Author: %s\n", commit->author);
248 f42b1b34 2018-03-12 stsp printf("\n%s\n", commit->logmsg);
249 5c860e29 2018-03-12 stsp
250 f42b1b34 2018-03-12 stsp free(buf);
251 5c860e29 2018-03-12 stsp
252 f42b1b34 2018-03-12 stsp err = print_parent_commits(commit, repo);
253 f42b1b34 2018-03-12 stsp got_object_commit_close(commit);
254 f42b1b34 2018-03-12 stsp return err;
255 f42b1b34 2018-03-12 stsp }
256 5c860e29 2018-03-12 stsp
257 6f3d1eb0 2018-03-12 stsp __dead void
258 6f3d1eb0 2018-03-12 stsp usage_log(void)
259 6f3d1eb0 2018-03-12 stsp {
260 6f3d1eb0 2018-03-12 stsp fprintf(stderr, "usage: %s log [REPO_PATH]\n", getprogname());
261 6f3d1eb0 2018-03-12 stsp exit(1);
262 6f3d1eb0 2018-03-12 stsp }
263 6f3d1eb0 2018-03-12 stsp
264 d7d4f210 2018-03-12 stsp const struct got_error *
265 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
266 f42b1b34 2018-03-12 stsp {
267 f42b1b34 2018-03-12 stsp const struct got_error *error;
268 f42b1b34 2018-03-12 stsp struct got_repository *repo;
269 f42b1b34 2018-03-12 stsp struct got_reference *head_ref;
270 f42b1b34 2018-03-12 stsp struct got_object_id *id;
271 f42b1b34 2018-03-12 stsp struct got_object *obj;
272 6f3d1eb0 2018-03-12 stsp char *repo_path = NULL;
273 5c860e29 2018-03-12 stsp
274 f42b1b34 2018-03-12 stsp if (pledge("stdio rpath wpath cpath", NULL) == -1)
275 f42b1b34 2018-03-12 stsp err(1, "pledge");
276 f42b1b34 2018-03-12 stsp
277 6f3d1eb0 2018-03-12 stsp if (argc == 1) {
278 6f3d1eb0 2018-03-12 stsp repo_path = getcwd(NULL, 0);
279 6f3d1eb0 2018-03-12 stsp if (repo_path == NULL)
280 6f3d1eb0 2018-03-12 stsp err(1, "getcwd");
281 6f3d1eb0 2018-03-12 stsp } else if (argc == 2)
282 6f3d1eb0 2018-03-12 stsp repo_path = argv[1];
283 6f3d1eb0 2018-03-12 stsp else
284 6f3d1eb0 2018-03-12 stsp usage_log();
285 f42b1b34 2018-03-12 stsp
286 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
287 d7d4f210 2018-03-12 stsp if (error != NULL)
288 d7d4f210 2018-03-12 stsp return error;
289 d7d4f210 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
290 d7d4f210 2018-03-12 stsp if (error != NULL)
291 d7d4f210 2018-03-12 stsp return error;
292 f42b1b34 2018-03-12 stsp error = got_ref_resolve(&id, repo, head_ref);
293 d7d4f210 2018-03-12 stsp if (error != NULL)
294 d7d4f210 2018-03-12 stsp return error;
295 f42b1b34 2018-03-12 stsp
296 f42b1b34 2018-03-12 stsp error = got_object_open(&obj, repo, id);
297 d7d4f210 2018-03-12 stsp if (error != NULL)
298 d7d4f210 2018-03-12 stsp return error;
299 f42b1b34 2018-03-12 stsp if (got_object_get_type(obj) == GOT_OBJ_TYPE_COMMIT) {
300 f42b1b34 2018-03-12 stsp error = print_commit_object(obj, id, repo);
301 f42b1b34 2018-03-12 stsp if (error)
302 d7d4f210 2018-03-12 stsp return error;
303 f42b1b34 2018-03-12 stsp } else
304 d7d4f210 2018-03-12 stsp return got_error(GOT_ERR_OBJ_TYPE);
305 f42b1b34 2018-03-12 stsp got_object_close(obj);
306 f42b1b34 2018-03-12 stsp free(id);
307 f42b1b34 2018-03-12 stsp got_ref_close(head_ref);
308 f42b1b34 2018-03-12 stsp got_repo_close(repo);
309 d7d4f210 2018-03-12 stsp return NULL;
310 5c860e29 2018-03-12 stsp }
311 5c860e29 2018-03-12 stsp
312 f42b1b34 2018-03-12 stsp #ifdef notyet
313 d7d4f210 2018-03-12 stsp const struct got_error *
314 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
315 5c860e29 2018-03-12 stsp {
316 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
317 5c860e29 2018-03-12 stsp git_status_list *status;
318 5c860e29 2018-03-12 stsp git_status_options statusopts;
319 5c860e29 2018-03-12 stsp size_t i;
320 5c860e29 2018-03-12 stsp
321 5c860e29 2018-03-12 stsp git_libgit2_init();
322 5c860e29 2018-03-12 stsp
323 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
324 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
325 5c860e29 2018-03-12 stsp
326 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
327 5c860e29 2018-03-12 stsp errx(1, "bar repository");
328 5c860e29 2018-03-12 stsp
329 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
330 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
331 5c860e29 2018-03-12 stsp
332 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
333 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
334 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
335 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
336 5c860e29 2018-03-12 stsp
337 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
338 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
339 5c860e29 2018-03-12 stsp
340 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
341 5c860e29 2018-03-12 stsp const git_status_entry *se;
342 5c860e29 2018-03-12 stsp
343 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
344 5c860e29 2018-03-12 stsp switch (se->status) {
345 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
346 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
347 5c860e29 2018-03-12 stsp break;
348 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
349 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
350 5c860e29 2018-03-12 stsp break;
351 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
352 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
353 5c860e29 2018-03-12 stsp break;
354 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
355 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
356 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
357 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
358 5c860e29 2018-03-12 stsp break;
359 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
360 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
361 5c860e29 2018-03-12 stsp break;
362 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
363 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
364 5c860e29 2018-03-12 stsp break;
365 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
366 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
367 5c860e29 2018-03-12 stsp break;
368 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
369 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
370 5c860e29 2018-03-12 stsp break;
371 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
372 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
373 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
374 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
375 5c860e29 2018-03-12 stsp break;
376 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
377 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
378 5c860e29 2018-03-12 stsp break;
379 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
380 5c860e29 2018-03-12 stsp default:
381 5c860e29 2018-03-12 stsp break;
382 5c860e29 2018-03-12 stsp }
383 5c860e29 2018-03-12 stsp }
384 5c860e29 2018-03-12 stsp
385 5c860e29 2018-03-12 stsp git_status_list_free(status);
386 5c860e29 2018-03-12 stsp git_repository_free(repo);
387 5c860e29 2018-03-12 stsp git_libgit2_shutdown();
388 5c860e29 2018-03-12 stsp
389 5c860e29 2018-03-12 stsp return 0;
390 5c860e29 2018-03-12 stsp }
391 f42b1b34 2018-03-12 stsp #endif