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 64a96a6d 2018-04-01 stsp #include <sys/limits.h>
20 c0768b0f 2018-06-10 stsp #include <sys/types.h>
21 f42b1b34 2018-03-12 stsp
22 5c860e29 2018-03-12 stsp #include <err.h>
23 5c860e29 2018-03-12 stsp #include <errno.h>
24 5c860e29 2018-03-12 stsp #include <locale.h>
25 5c860e29 2018-03-12 stsp #include <stdio.h>
26 5c860e29 2018-03-12 stsp #include <stdlib.h>
27 5c860e29 2018-03-12 stsp #include <string.h>
28 5c860e29 2018-03-12 stsp #include <unistd.h>
29 c09a553d 2018-03-12 stsp #include <libgen.h>
30 c0768b0f 2018-06-10 stsp #include <time.h>
31 5c860e29 2018-03-12 stsp
32 f42b1b34 2018-03-12 stsp #include "got_error.h"
33 f42b1b34 2018-03-12 stsp #include "got_object.h"
34 5261c201 2018-04-01 stsp #include "got_reference.h"
35 f42b1b34 2018-03-12 stsp #include "got_repository.h"
36 c09a553d 2018-03-12 stsp #include "got_worktree.h"
37 79109fed 2018-03-27 stsp #include "got_diff.h"
38 372ccdbb 2018-06-10 stsp #include "got_commit_graph.h"
39 5c860e29 2018-03-12 stsp
40 5c860e29 2018-03-12 stsp #ifndef nitems
41 5c860e29 2018-03-12 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
42 5c860e29 2018-03-12 stsp #endif
43 5c860e29 2018-03-12 stsp
44 5c860e29 2018-03-12 stsp struct cmd {
45 5c860e29 2018-03-12 stsp const char *cmd_name;
46 d7d4f210 2018-03-12 stsp const struct got_error *(*cmd_main)(int, char *[]);
47 1b6b95a8 2018-03-12 stsp void (*cmd_usage)(void);
48 46a0db7d 2018-03-12 stsp const char *cmd_descr;
49 5c860e29 2018-03-12 stsp };
50 5c860e29 2018-03-12 stsp
51 4ed7e80c 2018-05-20 stsp __dead static void usage(void);
52 4ed7e80c 2018-05-20 stsp __dead static void usage_checkout(void);
53 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
54 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
55 5c860e29 2018-03-12 stsp
56 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_checkout(int, char *[]);
57 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
58 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
59 4ed7e80c 2018-05-20 stsp #ifdef notyet
60 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_status(int, char *[]);
61 4ed7e80c 2018-05-20 stsp #endif
62 5c860e29 2018-03-12 stsp
63 4ed7e80c 2018-05-20 stsp static struct cmd got_commands[] = {
64 c09a553d 2018-03-12 stsp { "checkout", cmd_checkout, usage_checkout,
65 0bb8a95e 2018-03-12 stsp "check out a new work tree from a repository" },
66 1b6b95a8 2018-03-12 stsp { "log", cmd_log, usage_log,
67 1b6b95a8 2018-03-12 stsp "show repository history" },
68 b00d56cd 2018-04-01 stsp { "diff", cmd_diff, usage_diff,
69 b00d56cd 2018-04-01 stsp "compare files and directories" },
70 f42b1b34 2018-03-12 stsp #ifdef notyet
71 1b6b95a8 2018-03-12 stsp { "status", cmd_status, usage_status,
72 1b6b95a8 2018-03-12 stsp "show modification status of files" },
73 f42b1b34 2018-03-12 stsp #endif
74 5c860e29 2018-03-12 stsp };
75 5c860e29 2018-03-12 stsp
76 5c860e29 2018-03-12 stsp int
77 5c860e29 2018-03-12 stsp main(int argc, char *argv[])
78 5c860e29 2018-03-12 stsp {
79 5c860e29 2018-03-12 stsp struct cmd *cmd;
80 5c860e29 2018-03-12 stsp unsigned int i;
81 5c860e29 2018-03-12 stsp int ch;
82 1b6b95a8 2018-03-12 stsp int hflag = 0;
83 5c860e29 2018-03-12 stsp
84 5c860e29 2018-03-12 stsp setlocale(LC_ALL, "");
85 5c860e29 2018-03-12 stsp
86 1b6b95a8 2018-03-12 stsp while ((ch = getopt(argc, argv, "h")) != -1) {
87 5c860e29 2018-03-12 stsp switch (ch) {
88 1b6b95a8 2018-03-12 stsp case 'h':
89 1b6b95a8 2018-03-12 stsp hflag = 1;
90 1b6b95a8 2018-03-12 stsp break;
91 5c860e29 2018-03-12 stsp default:
92 5c860e29 2018-03-12 stsp usage();
93 5c860e29 2018-03-12 stsp /* NOTREACHED */
94 5c860e29 2018-03-12 stsp }
95 5c860e29 2018-03-12 stsp }
96 5c860e29 2018-03-12 stsp
97 5c860e29 2018-03-12 stsp argc -= optind;
98 5c860e29 2018-03-12 stsp argv += optind;
99 1e70621d 2018-03-27 stsp optind = 0;
100 5c860e29 2018-03-12 stsp
101 5c860e29 2018-03-12 stsp if (argc <= 0)
102 5c860e29 2018-03-12 stsp usage();
103 5c860e29 2018-03-12 stsp
104 5c860e29 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
105 d7d4f210 2018-03-12 stsp const struct got_error *error;
106 d7d4f210 2018-03-12 stsp
107 5c860e29 2018-03-12 stsp cmd = &got_commands[i];
108 5c860e29 2018-03-12 stsp
109 5c860e29 2018-03-12 stsp if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
110 5c860e29 2018-03-12 stsp continue;
111 5c860e29 2018-03-12 stsp
112 1b6b95a8 2018-03-12 stsp if (hflag)
113 1b6b95a8 2018-03-12 stsp got_commands[i].cmd_usage();
114 1b6b95a8 2018-03-12 stsp
115 d7d4f210 2018-03-12 stsp error = got_commands[i].cmd_main(argc, argv);
116 d7d4f210 2018-03-12 stsp if (error) {
117 d7d4f210 2018-03-12 stsp fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
118 d7d4f210 2018-03-12 stsp return 1;
119 d7d4f210 2018-03-12 stsp }
120 d7d4f210 2018-03-12 stsp
121 d7d4f210 2018-03-12 stsp return 0;
122 5c860e29 2018-03-12 stsp }
123 5c860e29 2018-03-12 stsp
124 20ecf764 2018-03-12 stsp fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
125 5c860e29 2018-03-12 stsp return 1;
126 5c860e29 2018-03-12 stsp }
127 5c860e29 2018-03-12 stsp
128 4ed7e80c 2018-05-20 stsp __dead static void
129 5c860e29 2018-03-12 stsp usage(void)
130 5c860e29 2018-03-12 stsp {
131 46a0db7d 2018-03-12 stsp int i;
132 46a0db7d 2018-03-12 stsp
133 987e94ba 2018-03-12 stsp fprintf(stderr, "usage: %s [-h] command [arg ...]\n\n"
134 987e94ba 2018-03-12 stsp "Available commands:\n", getprogname());
135 46a0db7d 2018-03-12 stsp for (i = 0; i < nitems(got_commands); i++) {
136 46a0db7d 2018-03-12 stsp struct cmd *cmd = &got_commands[i];
137 46a0db7d 2018-03-12 stsp fprintf(stderr, " %s: %s\n", cmd->cmd_name, cmd->cmd_descr);
138 46a0db7d 2018-03-12 stsp }
139 5c860e29 2018-03-12 stsp exit(1);
140 5c860e29 2018-03-12 stsp }
141 5c860e29 2018-03-12 stsp
142 4ed7e80c 2018-05-20 stsp __dead static void
143 c09a553d 2018-03-12 stsp usage_checkout(void)
144 c09a553d 2018-03-12 stsp {
145 0bb8a95e 2018-03-12 stsp fprintf(stderr, "usage: %s checkout [-p prefix] repository-path "
146 0bb8a95e 2018-03-12 stsp "[worktree-path]\n", getprogname());
147 c09a553d 2018-03-12 stsp exit(1);
148 92a684f4 2018-03-12 stsp }
149 92a684f4 2018-03-12 stsp
150 92a684f4 2018-03-12 stsp static void
151 92a684f4 2018-03-12 stsp checkout_progress(void *arg, const char *path)
152 92a684f4 2018-03-12 stsp {
153 92a684f4 2018-03-12 stsp char *worktree_path = arg;
154 92a684f4 2018-03-12 stsp
155 92a684f4 2018-03-12 stsp while (path[0] == '/')
156 92a684f4 2018-03-12 stsp path++;
157 92a684f4 2018-03-12 stsp
158 92a684f4 2018-03-12 stsp printf("A %s/%s\n", worktree_path, path);
159 c09a553d 2018-03-12 stsp }
160 c09a553d 2018-03-12 stsp
161 4ed7e80c 2018-05-20 stsp static const struct got_error *
162 c09a553d 2018-03-12 stsp cmd_checkout(int argc, char *argv[])
163 c09a553d 2018-03-12 stsp {
164 c09a553d 2018-03-12 stsp const struct got_error *error = NULL;
165 c09a553d 2018-03-12 stsp struct got_repository *repo = NULL;
166 c09a553d 2018-03-12 stsp struct got_reference *head_ref = NULL;
167 c09a553d 2018-03-12 stsp struct got_worktree *worktree = NULL;
168 c09a553d 2018-03-12 stsp char *repo_path = NULL;
169 c09a553d 2018-03-12 stsp char *worktree_path = NULL;
170 0bb8a95e 2018-03-12 stsp const char *path_prefix = "";
171 0bb8a95e 2018-03-12 stsp int ch;
172 c09a553d 2018-03-12 stsp
173 0bb8a95e 2018-03-12 stsp while ((ch = getopt(argc, argv, "p:")) != -1) {
174 0bb8a95e 2018-03-12 stsp switch (ch) {
175 0bb8a95e 2018-03-12 stsp case 'p':
176 0bb8a95e 2018-03-12 stsp path_prefix = optarg;
177 0bb8a95e 2018-03-12 stsp break;
178 0bb8a95e 2018-03-12 stsp default:
179 0bb8a95e 2018-03-12 stsp usage();
180 0bb8a95e 2018-03-12 stsp /* NOTREACHED */
181 0bb8a95e 2018-03-12 stsp }
182 0bb8a95e 2018-03-12 stsp }
183 0bb8a95e 2018-03-12 stsp
184 0bb8a95e 2018-03-12 stsp argc -= optind;
185 0bb8a95e 2018-03-12 stsp argv += optind;
186 0bb8a95e 2018-03-12 stsp
187 6715a751 2018-03-16 stsp #ifndef PROFILE
188 2178c42e 2018-04-22 stsp if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
189 c09a553d 2018-03-12 stsp err(1, "pledge");
190 6715a751 2018-03-16 stsp #endif
191 0bb8a95e 2018-03-12 stsp if (argc == 1) {
192 c09a553d 2018-03-12 stsp char *cwd, *base, *dotgit;
193 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
194 76089277 2018-04-01 stsp if (repo_path == NULL)
195 76089277 2018-04-01 stsp return got_error_from_errno();
196 c09a553d 2018-03-12 stsp cwd = getcwd(NULL, 0);
197 76089277 2018-04-01 stsp if (cwd == NULL) {
198 76089277 2018-04-01 stsp error = got_error_from_errno();
199 76089277 2018-04-01 stsp goto done;
200 76089277 2018-04-01 stsp }
201 5d7c1dab 2018-04-01 stsp if (path_prefix[0])
202 5d7c1dab 2018-04-01 stsp base = basename(path_prefix);
203 5d7c1dab 2018-04-01 stsp else
204 5d7c1dab 2018-04-01 stsp base = basename(repo_path);
205 76089277 2018-04-01 stsp if (base == NULL) {
206 76089277 2018-04-01 stsp error = got_error_from_errno();
207 76089277 2018-04-01 stsp goto done;
208 76089277 2018-04-01 stsp }
209 c09a553d 2018-03-12 stsp dotgit = strstr(base, ".git");
210 c09a553d 2018-03-12 stsp if (dotgit)
211 c09a553d 2018-03-12 stsp *dotgit = '\0';
212 c09a553d 2018-03-12 stsp if (asprintf(&worktree_path, "%s/%s", cwd, base) == -1) {
213 0a585a0d 2018-03-17 stsp error = got_error_from_errno();
214 c09a553d 2018-03-12 stsp free(cwd);
215 76089277 2018-04-01 stsp goto done;
216 c09a553d 2018-03-12 stsp }
217 c09a553d 2018-03-12 stsp free(cwd);
218 0bb8a95e 2018-03-12 stsp } else if (argc == 2) {
219 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
220 76089277 2018-04-01 stsp if (repo_path == NULL) {
221 76089277 2018-04-01 stsp error = got_error_from_errno();
222 76089277 2018-04-01 stsp goto done;
223 76089277 2018-04-01 stsp }
224 f7b38925 2018-04-01 stsp worktree_path = realpath(argv[1], NULL);
225 76089277 2018-04-01 stsp if (worktree_path == NULL) {
226 76089277 2018-04-01 stsp error = got_error_from_errno();
227 76089277 2018-04-01 stsp goto done;
228 76089277 2018-04-01 stsp }
229 c09a553d 2018-03-12 stsp } else
230 c09a553d 2018-03-12 stsp usage_checkout();
231 c09a553d 2018-03-12 stsp
232 c09a553d 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
233 c09a553d 2018-03-12 stsp if (error != NULL)
234 c09a553d 2018-03-12 stsp goto done;
235 c09a553d 2018-03-12 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
236 c09a553d 2018-03-12 stsp if (error != NULL)
237 c09a553d 2018-03-12 stsp goto done;
238 c09a553d 2018-03-12 stsp
239 0bb8a95e 2018-03-12 stsp error = got_worktree_init(worktree_path, head_ref, path_prefix, repo);
240 c09a553d 2018-03-12 stsp if (error != NULL)
241 c09a553d 2018-03-12 stsp goto done;
242 c09a553d 2018-03-12 stsp
243 c09a553d 2018-03-12 stsp error = got_worktree_open(&worktree, worktree_path);
244 c09a553d 2018-03-12 stsp if (error != NULL)
245 c09a553d 2018-03-12 stsp goto done;
246 c09a553d 2018-03-12 stsp
247 92a684f4 2018-03-12 stsp error = got_worktree_checkout_files(worktree, head_ref, repo,
248 92a684f4 2018-03-12 stsp checkout_progress, worktree_path);
249 c09a553d 2018-03-12 stsp if (error != NULL)
250 c09a553d 2018-03-12 stsp goto done;
251 c09a553d 2018-03-12 stsp
252 b65ae19a 2018-04-24 stsp printf("Checked out %s\n", worktree_path);
253 b65ae19a 2018-04-24 stsp printf("Now shut up and hack\n");
254 c09a553d 2018-03-12 stsp
255 c09a553d 2018-03-12 stsp done:
256 76089277 2018-04-01 stsp free(repo_path);
257 c09a553d 2018-03-12 stsp free(worktree_path);
258 c09a553d 2018-03-12 stsp return error;
259 c09a553d 2018-03-12 stsp }
260 c09a553d 2018-03-12 stsp
261 f42b1b34 2018-03-12 stsp static const struct got_error *
262 79109fed 2018-03-27 stsp print_patch(struct got_commit_object *commit, struct got_object_id *id,
263 f42b1b34 2018-03-12 stsp struct got_repository *repo)
264 5c860e29 2018-03-12 stsp {
265 f42b1b34 2018-03-12 stsp const struct got_error *err = NULL;
266 79109fed 2018-03-27 stsp struct got_tree_object *tree1 = NULL, *tree2;
267 79109fed 2018-03-27 stsp struct got_object *obj;
268 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
269 79109fed 2018-03-27 stsp
270 79109fed 2018-03-27 stsp err = got_object_open(&obj, repo, commit->tree_id);
271 79109fed 2018-03-27 stsp if (err)
272 79109fed 2018-03-27 stsp return err;
273 79109fed 2018-03-27 stsp
274 79109fed 2018-03-27 stsp err = got_object_tree_open(&tree2, repo, obj);
275 79109fed 2018-03-27 stsp got_object_close(obj);
276 79109fed 2018-03-27 stsp if (err)
277 79109fed 2018-03-27 stsp return err;
278 79109fed 2018-03-27 stsp
279 79f35eb3 2018-06-11 stsp qid = SIMPLEQ_FIRST(&commit->parent_ids);
280 79f35eb3 2018-06-11 stsp if (qid != NULL) {
281 79109fed 2018-03-27 stsp struct got_commit_object *pcommit;
282 79109fed 2018-03-27 stsp
283 79f35eb3 2018-06-11 stsp err = got_object_open(&obj, repo, qid->id);
284 79109fed 2018-03-27 stsp if (err)
285 79109fed 2018-03-27 stsp return err;
286 79109fed 2018-03-27 stsp
287 79109fed 2018-03-27 stsp err = got_object_commit_open(&pcommit, repo, obj);
288 79109fed 2018-03-27 stsp got_object_close(obj);
289 79109fed 2018-03-27 stsp if (err)
290 79109fed 2018-03-27 stsp return err;
291 79109fed 2018-03-27 stsp
292 79109fed 2018-03-27 stsp err = got_object_open(&obj, repo, pcommit->tree_id);
293 79109fed 2018-03-27 stsp got_object_commit_close(pcommit);
294 79109fed 2018-03-27 stsp if (err)
295 79109fed 2018-03-27 stsp return err;
296 79109fed 2018-03-27 stsp err = got_object_tree_open(&tree1, repo, obj);
297 79109fed 2018-03-27 stsp got_object_close(obj);
298 79109fed 2018-03-27 stsp if (err)
299 79109fed 2018-03-27 stsp return err;
300 79109fed 2018-03-27 stsp }
301 79109fed 2018-03-27 stsp
302 79109fed 2018-03-27 stsp err = got_diff_tree(tree1, tree2, repo, stdout);
303 79109fed 2018-03-27 stsp if (tree1)
304 79109fed 2018-03-27 stsp got_object_tree_close(tree1);
305 79109fed 2018-03-27 stsp got_object_tree_close(tree2);
306 79109fed 2018-03-27 stsp return err;
307 79109fed 2018-03-27 stsp }
308 79109fed 2018-03-27 stsp
309 6c281f94 2018-06-11 stsp char *
310 6c281f94 2018-06-11 stsp get_datestr(time_t *time, char *datebuf)
311 6c281f94 2018-06-11 stsp {
312 6c281f94 2018-06-11 stsp char *p, *s = ctime_r(time, datebuf);
313 6c281f94 2018-06-11 stsp p = strchr(s, '\n');
314 6c281f94 2018-06-11 stsp if (p)
315 6c281f94 2018-06-11 stsp *p = '\0';
316 6c281f94 2018-06-11 stsp return s;
317 6c281f94 2018-06-11 stsp }
318 6c281f94 2018-06-11 stsp
319 79109fed 2018-03-27 stsp static const struct got_error *
320 79109fed 2018-03-27 stsp print_commit(struct got_commit_object *commit, struct got_object_id *id,
321 1fd6d7ea 2018-06-13 stsp struct got_repository *repo, int show_patch)
322 79109fed 2018-03-27 stsp {
323 79109fed 2018-03-27 stsp const struct got_error *err = NULL;
324 6c281f94 2018-06-11 stsp char *id_str, *datestr, *logmsg, *line;
325 6c281f94 2018-06-11 stsp char datebuf[26];
326 788c352e 2018-06-16 stsp time_t author_time, committer_time;
327 5c860e29 2018-03-12 stsp
328 832c249c 2018-06-10 stsp err = got_object_id_str(&id_str, id);
329 8bf5b3c9 2018-03-17 stsp if (err)
330 8bf5b3c9 2018-03-17 stsp return err;
331 788c352e 2018-06-16 stsp
332 788c352e 2018-06-16 stsp author_time = mktime(&commit->tm_author);
333 788c352e 2018-06-16 stsp committer_time = mktime(&commit->tm_committer);
334 788c352e 2018-06-16 stsp #if 0
335 788c352e 2018-06-16 stsp /* This would express the date in committer's timezone. */
336 788c352e 2018-06-16 stsp author_time += commit->tm_author.tm_gmtoff;
337 788c352e 2018-06-16 stsp committer_time += commit->tm_committer.tm_gmtoff;
338 788c352e 2018-06-16 stsp #endif
339 5c860e29 2018-03-12 stsp
340 8bf5b3c9 2018-03-17 stsp printf("-----------------------------------------------\n");
341 832c249c 2018-06-10 stsp printf("commit %s\n", id_str);
342 832c249c 2018-06-10 stsp free(id_str);
343 788c352e 2018-06-16 stsp datestr = get_datestr(&author_time, datebuf);
344 788c352e 2018-06-16 stsp printf("author: %s %s UTC\n", commit->author, datestr);
345 6ede4e7a 2018-06-11 stsp if (strcmp(commit->author, commit->committer) != 0 ||
346 788c352e 2018-06-16 stsp author_time != committer_time) {
347 788c352e 2018-06-16 stsp datestr = get_datestr(&committer_time, datebuf);
348 788c352e 2018-06-16 stsp printf("committer: %s %s UTC\n", commit->committer, datestr);
349 6c281f94 2018-06-11 stsp }
350 3fe1abad 2018-06-10 stsp if (commit->nparents > 1) {
351 79f35eb3 2018-06-11 stsp struct got_object_qid *qid;
352 3fe1abad 2018-06-10 stsp int n = 1;
353 79f35eb3 2018-06-11 stsp SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
354 79f35eb3 2018-06-11 stsp err = got_object_id_str(&id_str, qid->id);
355 a0603db2 2018-06-10 stsp if (err)
356 a0603db2 2018-06-10 stsp return err;
357 3fe1abad 2018-06-10 stsp printf("parent %d: %s\n", n++, id_str);
358 a0603db2 2018-06-10 stsp free(id_str);
359 a0603db2 2018-06-10 stsp }
360 a0603db2 2018-06-10 stsp }
361 832c249c 2018-06-10 stsp
362 832c249c 2018-06-10 stsp logmsg = strdup(commit->logmsg);
363 832c249c 2018-06-10 stsp if (logmsg == NULL)
364 832c249c 2018-06-10 stsp return got_error_from_errno();
365 8bf5b3c9 2018-03-17 stsp
366 832c249c 2018-06-10 stsp do {
367 832c249c 2018-06-10 stsp line = strsep(&logmsg, "\n");
368 832c249c 2018-06-10 stsp if (line)
369 832c249c 2018-06-10 stsp printf(" %s\n", line);
370 832c249c 2018-06-10 stsp } while (line);
371 832c249c 2018-06-10 stsp free(logmsg);
372 832c249c 2018-06-10 stsp
373 971751ac 2018-03-27 stsp if (show_patch) {
374 79109fed 2018-03-27 stsp err = print_patch(commit, id, repo);
375 971751ac 2018-03-27 stsp if (err == 0)
376 971751ac 2018-03-27 stsp printf("\n");
377 971751ac 2018-03-27 stsp }
378 79109fed 2018-03-27 stsp
379 79109fed 2018-03-27 stsp return err;
380 f42b1b34 2018-03-12 stsp }
381 5c860e29 2018-03-12 stsp
382 f42b1b34 2018-03-12 stsp static const struct got_error *
383 8bf5b3c9 2018-03-17 stsp print_commits(struct got_object *root_obj, struct got_object_id *root_id,
384 1fd6d7ea 2018-06-13 stsp struct got_repository *repo, int show_patch, int limit,
385 0ed6ed4c 2018-06-13 stsp int first_parent_traversal)
386 f42b1b34 2018-03-12 stsp {
387 f42b1b34 2018-03-12 stsp const struct got_error *err;
388 372ccdbb 2018-06-10 stsp struct got_commit_graph *graph;
389 372ccdbb 2018-06-10 stsp int ncommits;
390 372ccdbb 2018-06-10 stsp
391 0ed6ed4c 2018-06-13 stsp err = got_commit_graph_open(&graph, root_id, first_parent_traversal,
392 0ed6ed4c 2018-06-13 stsp repo);
393 f42b1b34 2018-03-12 stsp if (err)
394 f42b1b34 2018-03-12 stsp return err;
395 372ccdbb 2018-06-10 stsp err = got_commit_graph_iter_start(graph, root_id);
396 372ccdbb 2018-06-10 stsp if (err)
397 0a585a0d 2018-03-17 stsp return err;
398 372ccdbb 2018-06-10 stsp do {
399 372ccdbb 2018-06-10 stsp struct got_commit_object *commit;
400 372ccdbb 2018-06-10 stsp struct got_object_id *id;
401 8bf5b3c9 2018-03-17 stsp
402 b43fbaa0 2018-06-11 stsp err = got_commit_graph_iter_next(&id, graph);
403 372ccdbb 2018-06-10 stsp if (err) {
404 9ba79e04 2018-06-11 stsp if (err->code == GOT_ERR_ITER_COMPLETED) {
405 9ba79e04 2018-06-11 stsp err = NULL;
406 9ba79e04 2018-06-11 stsp break;
407 9ba79e04 2018-06-11 stsp }
408 372ccdbb 2018-06-10 stsp if (err->code != GOT_ERR_ITER_NEED_MORE)
409 372ccdbb 2018-06-10 stsp break;
410 372ccdbb 2018-06-10 stsp err = got_commit_graph_fetch_commits(&ncommits,
411 372ccdbb 2018-06-10 stsp graph, 1, repo);
412 372ccdbb 2018-06-10 stsp if (err)
413 372ccdbb 2018-06-10 stsp break;
414 372ccdbb 2018-06-10 stsp else
415 372ccdbb 2018-06-10 stsp continue;
416 7e665116 2018-04-02 stsp }
417 b43fbaa0 2018-06-11 stsp if (id == NULL)
418 7e665116 2018-04-02 stsp break;
419 b43fbaa0 2018-06-11 stsp
420 f8e900f3 2018-06-11 stsp err = got_object_open_as_commit(&commit, repo, id);
421 b43fbaa0 2018-06-11 stsp if (err)
422 b43fbaa0 2018-06-11 stsp return err;
423 1fd6d7ea 2018-06-13 stsp err = print_commit(commit, id, repo, show_patch);
424 b43fbaa0 2018-06-11 stsp got_object_commit_close(commit);
425 372ccdbb 2018-06-10 stsp if (err || (limit && --limit == 0))
426 7e665116 2018-04-02 stsp break;
427 372ccdbb 2018-06-10 stsp } while (ncommits > 0);
428 8bf5b3c9 2018-03-17 stsp
429 372ccdbb 2018-06-10 stsp got_commit_graph_close(graph);
430 f42b1b34 2018-03-12 stsp return err;
431 f42b1b34 2018-03-12 stsp }
432 5c860e29 2018-03-12 stsp
433 4ed7e80c 2018-05-20 stsp __dead static void
434 6f3d1eb0 2018-03-12 stsp usage_log(void)
435 6f3d1eb0 2018-03-12 stsp {
436 6238ee32 2018-06-13 stsp fprintf(stderr, "usage: %s log [-c commit] [-f] [ -l N ] [-p] "
437 64a96a6d 2018-04-01 stsp "[repository-path]\n", getprogname());
438 6f3d1eb0 2018-03-12 stsp exit(1);
439 6f3d1eb0 2018-03-12 stsp }
440 6f3d1eb0 2018-03-12 stsp
441 4ed7e80c 2018-05-20 stsp static const struct got_error *
442 f42b1b34 2018-03-12 stsp cmd_log(int argc, char *argv[])
443 f42b1b34 2018-03-12 stsp {
444 f42b1b34 2018-03-12 stsp const struct got_error *error;
445 f42b1b34 2018-03-12 stsp struct got_repository *repo;
446 3235492e 2018-04-01 stsp struct got_object_id *id = NULL;
447 d1f2edc9 2018-06-13 stsp struct got_object *obj = NULL;
448 6f3d1eb0 2018-03-12 stsp char *repo_path = NULL;
449 d142fc45 2018-04-01 stsp char *start_commit = NULL;
450 79109fed 2018-03-27 stsp int ch;
451 1fd6d7ea 2018-06-13 stsp int show_patch = 0, limit = 0, first_parent_traversal = 0;
452 64a96a6d 2018-04-01 stsp const char *errstr;
453 5c860e29 2018-03-12 stsp
454 6715a751 2018-03-16 stsp #ifndef PROFILE
455 442a3ddc 2018-04-23 stsp if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
456 f42b1b34 2018-03-12 stsp err(1, "pledge");
457 6715a751 2018-03-16 stsp #endif
458 79109fed 2018-03-27 stsp
459 1fd6d7ea 2018-06-13 stsp while ((ch = getopt(argc, argv, "pc:l:f")) != -1) {
460 79109fed 2018-03-27 stsp switch (ch) {
461 79109fed 2018-03-27 stsp case 'p':
462 79109fed 2018-03-27 stsp show_patch = 1;
463 d142fc45 2018-04-01 stsp break;
464 d142fc45 2018-04-01 stsp case 'c':
465 d142fc45 2018-04-01 stsp start_commit = optarg;
466 64a96a6d 2018-04-01 stsp break;
467 64a96a6d 2018-04-01 stsp case 'l':
468 64a96a6d 2018-04-01 stsp limit = strtonum(optarg, 1, INT_MAX, &errstr);
469 64a96a6d 2018-04-01 stsp if (errstr != NULL)
470 64a96a6d 2018-04-01 stsp err(1, "-l option %s", errstr);
471 79109fed 2018-03-27 stsp break;
472 0ed6ed4c 2018-06-13 stsp case 'f':
473 0ed6ed4c 2018-06-13 stsp first_parent_traversal = 1;
474 a0603db2 2018-06-10 stsp break;
475 79109fed 2018-03-27 stsp default:
476 79109fed 2018-03-27 stsp usage();
477 79109fed 2018-03-27 stsp /* NOTREACHED */
478 79109fed 2018-03-27 stsp }
479 79109fed 2018-03-27 stsp }
480 79109fed 2018-03-27 stsp
481 79109fed 2018-03-27 stsp argc -= optind;
482 79109fed 2018-03-27 stsp argv += optind;
483 79109fed 2018-03-27 stsp
484 79109fed 2018-03-27 stsp if (argc == 0) {
485 6f3d1eb0 2018-03-12 stsp repo_path = getcwd(NULL, 0);
486 6f3d1eb0 2018-03-12 stsp if (repo_path == NULL)
487 e1e3f570 2018-04-01 stsp return got_error_from_errno();
488 3235492e 2018-04-01 stsp } else if (argc == 1) {
489 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
490 76089277 2018-04-01 stsp if (repo_path == NULL)
491 76089277 2018-04-01 stsp return got_error_from_errno();
492 3235492e 2018-04-01 stsp } else
493 6f3d1eb0 2018-03-12 stsp usage_log();
494 f42b1b34 2018-03-12 stsp
495 f42b1b34 2018-03-12 stsp error = got_repo_open(&repo, repo_path);
496 76089277 2018-04-01 stsp free(repo_path);
497 d7d4f210 2018-03-12 stsp if (error != NULL)
498 d7d4f210 2018-03-12 stsp return error;
499 f42b1b34 2018-03-12 stsp
500 d142fc45 2018-04-01 stsp if (start_commit == NULL) {
501 3235492e 2018-04-01 stsp struct got_reference *head_ref;
502 3235492e 2018-04-01 stsp error = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
503 3235492e 2018-04-01 stsp if (error != NULL)
504 3235492e 2018-04-01 stsp return error;
505 3235492e 2018-04-01 stsp error = got_ref_resolve(&id, repo, head_ref);
506 3235492e 2018-04-01 stsp got_ref_close(head_ref);
507 3235492e 2018-04-01 stsp if (error != NULL)
508 3235492e 2018-04-01 stsp return error;
509 3235492e 2018-04-01 stsp error = got_object_open(&obj, repo, id);
510 3235492e 2018-04-01 stsp } else {
511 d1f2edc9 2018-06-13 stsp struct got_reference *ref;
512 d1f2edc9 2018-06-13 stsp error = got_ref_open(&ref, repo, start_commit);
513 3235492e 2018-04-01 stsp if (error == NULL) {
514 d1f2edc9 2018-06-13 stsp error = got_ref_resolve(&id, repo, ref);
515 d1f2edc9 2018-06-13 stsp got_ref_close(ref);
516 d1f2edc9 2018-06-13 stsp if (error != NULL)
517 d1f2edc9 2018-06-13 stsp return error;
518 d1f2edc9 2018-06-13 stsp error = got_object_open(&obj, repo, id);
519 d1f2edc9 2018-06-13 stsp if (error != NULL)
520 d1f2edc9 2018-06-13 stsp return error;
521 d1f2edc9 2018-06-13 stsp }
522 d1f2edc9 2018-06-13 stsp if (obj == NULL) {
523 d1f2edc9 2018-06-13 stsp error = got_object_open_by_id_str(&obj, repo,
524 d1f2edc9 2018-06-13 stsp start_commit);
525 d1f2edc9 2018-06-13 stsp if (error != NULL)
526 d1f2edc9 2018-06-13 stsp return error;
527 3235492e 2018-04-01 stsp id = got_object_get_id(obj);
528 3235492e 2018-04-01 stsp if (id == NULL)
529 3235492e 2018-04-01 stsp error = got_error_from_errno();
530 3235492e 2018-04-01 stsp }
531 3235492e 2018-04-01 stsp }
532 d7d4f210 2018-03-12 stsp if (error != NULL)
533 d7d4f210 2018-03-12 stsp return error;
534 8bf5b3c9 2018-03-17 stsp if (got_object_get_type(obj) == GOT_OBJ_TYPE_COMMIT)
535 a0603db2 2018-06-10 stsp error = print_commits(obj, id, repo, show_patch, limit,
536 1fd6d7ea 2018-06-13 stsp first_parent_traversal);
537 8bf5b3c9 2018-03-17 stsp else
538 8bf5b3c9 2018-03-17 stsp error = got_error(GOT_ERR_OBJ_TYPE);
539 f42b1b34 2018-03-12 stsp got_object_close(obj);
540 f42b1b34 2018-03-12 stsp free(id);
541 f42b1b34 2018-03-12 stsp got_repo_close(repo);
542 8bf5b3c9 2018-03-17 stsp return error;
543 5c860e29 2018-03-12 stsp }
544 5c860e29 2018-03-12 stsp
545 4ed7e80c 2018-05-20 stsp __dead static void
546 3f8b7d6a 2018-04-01 stsp usage_diff(void)
547 3f8b7d6a 2018-04-01 stsp {
548 3f8b7d6a 2018-04-01 stsp fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
549 3f8b7d6a 2018-04-01 stsp getprogname());
550 3f8b7d6a 2018-04-01 stsp exit(1);
551 b00d56cd 2018-04-01 stsp }
552 b00d56cd 2018-04-01 stsp
553 4ed7e80c 2018-05-20 stsp static const struct got_error *
554 b00d56cd 2018-04-01 stsp cmd_diff(int argc, char *argv[])
555 b00d56cd 2018-04-01 stsp {
556 b00d56cd 2018-04-01 stsp const struct got_error *error;
557 b00d56cd 2018-04-01 stsp struct got_repository *repo = NULL;
558 b00d56cd 2018-04-01 stsp struct got_object_id *id1 = NULL, *id2 = NULL;
559 b00d56cd 2018-04-01 stsp struct got_object *obj1 = NULL, *obj2 = NULL;
560 b00d56cd 2018-04-01 stsp char *repo_path = NULL;
561 b00d56cd 2018-04-01 stsp char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
562 b00d56cd 2018-04-01 stsp int ch;
563 b00d56cd 2018-04-01 stsp
564 b00d56cd 2018-04-01 stsp #ifndef PROFILE
565 442a3ddc 2018-04-23 stsp if (pledge("stdio rpath wpath cpath flock proc", NULL) == -1)
566 b00d56cd 2018-04-01 stsp err(1, "pledge");
567 b00d56cd 2018-04-01 stsp #endif
568 b00d56cd 2018-04-01 stsp
569 b00d56cd 2018-04-01 stsp while ((ch = getopt(argc, argv, "")) != -1) {
570 b00d56cd 2018-04-01 stsp switch (ch) {
571 b00d56cd 2018-04-01 stsp default:
572 b00d56cd 2018-04-01 stsp usage();
573 b00d56cd 2018-04-01 stsp /* NOTREACHED */
574 b00d56cd 2018-04-01 stsp }
575 b00d56cd 2018-04-01 stsp }
576 b00d56cd 2018-04-01 stsp
577 b00d56cd 2018-04-01 stsp argc -= optind;
578 b00d56cd 2018-04-01 stsp argv += optind;
579 b00d56cd 2018-04-01 stsp
580 b00d56cd 2018-04-01 stsp if (argc == 0) {
581 b00d56cd 2018-04-01 stsp usage_diff(); /* TODO show local worktree changes */
582 3f8b7d6a 2018-04-01 stsp } else if (argc == 2) {
583 3f8b7d6a 2018-04-01 stsp repo_path = getcwd(NULL, 0);
584 3f8b7d6a 2018-04-01 stsp if (repo_path == NULL)
585 e1e3f570 2018-04-01 stsp return got_error_from_errno();
586 3f8b7d6a 2018-04-01 stsp obj_id_str1 = argv[0];
587 3f8b7d6a 2018-04-01 stsp obj_id_str2 = argv[1];
588 b00d56cd 2018-04-01 stsp } else if (argc == 3) {
589 76089277 2018-04-01 stsp repo_path = realpath(argv[0], NULL);
590 76089277 2018-04-01 stsp if (repo_path == NULL)
591 76089277 2018-04-01 stsp return got_error_from_errno();
592 b00d56cd 2018-04-01 stsp obj_id_str1 = argv[1];
593 b00d56cd 2018-04-01 stsp obj_id_str2 = argv[2];
594 b00d56cd 2018-04-01 stsp } else
595 b00d56cd 2018-04-01 stsp usage_diff();
596 b00d56cd 2018-04-01 stsp
597 b00d56cd 2018-04-01 stsp error = got_repo_open(&repo, repo_path);
598 76089277 2018-04-01 stsp free(repo_path);
599 b00d56cd 2018-04-01 stsp if (error != NULL)
600 b00d56cd 2018-04-01 stsp goto done;
601 b00d56cd 2018-04-01 stsp
602 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
603 b00d56cd 2018-04-01 stsp if (error == NULL) {
604 b00d56cd 2018-04-01 stsp id1 = got_object_get_id(obj1);
605 b00d56cd 2018-04-01 stsp if (id1 == NULL)
606 b00d56cd 2018-04-01 stsp error = got_error_from_errno();
607 b00d56cd 2018-04-01 stsp }
608 b00d56cd 2018-04-01 stsp if (error != NULL)
609 b00d56cd 2018-04-01 stsp goto done;
610 b00d56cd 2018-04-01 stsp
611 b00d56cd 2018-04-01 stsp error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
612 b00d56cd 2018-04-01 stsp if (error == NULL) {
613 b00d56cd 2018-04-01 stsp id2 = got_object_get_id(obj2);
614 b00d56cd 2018-04-01 stsp if (id2 == NULL)
615 b00d56cd 2018-04-01 stsp error = got_error_from_errno();
616 b00d56cd 2018-04-01 stsp }
617 b00d56cd 2018-04-01 stsp if (error != NULL)
618 b00d56cd 2018-04-01 stsp goto done;
619 b00d56cd 2018-04-01 stsp
620 b00d56cd 2018-04-01 stsp if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
621 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
622 b00d56cd 2018-04-01 stsp goto done;
623 b00d56cd 2018-04-01 stsp }
624 b00d56cd 2018-04-01 stsp
625 b00d56cd 2018-04-01 stsp switch (got_object_get_type(obj1)) {
626 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_BLOB:
627 11528a82 2018-05-19 stsp error = got_diff_objects_as_blobs(obj1, obj2, repo, stdout);
628 b00d56cd 2018-04-01 stsp break;
629 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_TREE:
630 11528a82 2018-05-19 stsp error = got_diff_objects_as_trees(obj1, obj2, repo, stdout);
631 b00d56cd 2018-04-01 stsp break;
632 b00d56cd 2018-04-01 stsp case GOT_OBJ_TYPE_COMMIT:
633 11528a82 2018-05-19 stsp error = got_diff_objects_as_commits(obj1, obj2, repo, stdout);
634 b00d56cd 2018-04-01 stsp break;
635 b00d56cd 2018-04-01 stsp default:
636 b00d56cd 2018-04-01 stsp error = got_error(GOT_ERR_OBJ_TYPE);
637 b00d56cd 2018-04-01 stsp }
638 b00d56cd 2018-04-01 stsp
639 b00d56cd 2018-04-01 stsp done:
640 b00d56cd 2018-04-01 stsp if (obj1)
641 b00d56cd 2018-04-01 stsp got_object_close(obj1);
642 b00d56cd 2018-04-01 stsp if (obj2)
643 b00d56cd 2018-04-01 stsp got_object_close(obj2);
644 b00d56cd 2018-04-01 stsp if (id1)
645 b00d56cd 2018-04-01 stsp free(id1);
646 b00d56cd 2018-04-01 stsp if (id2)
647 b00d56cd 2018-04-01 stsp free(id2);
648 b00d56cd 2018-04-01 stsp if (repo)
649 b00d56cd 2018-04-01 stsp got_repo_close(repo);
650 b00d56cd 2018-04-01 stsp return error;
651 b00d56cd 2018-04-01 stsp }
652 b00d56cd 2018-04-01 stsp
653 f42b1b34 2018-03-12 stsp #ifdef notyet
654 4ed7e80c 2018-05-20 stsp static const struct got_error *
655 5c860e29 2018-03-12 stsp cmd_status(int argc __unused, char *argv[] __unused)
656 5c860e29 2018-03-12 stsp {
657 5c860e29 2018-03-12 stsp git_repository *repo = NULL;
658 5c860e29 2018-03-12 stsp git_status_list *status;
659 5c860e29 2018-03-12 stsp git_status_options statusopts;
660 5c860e29 2018-03-12 stsp size_t i;
661 5c860e29 2018-03-12 stsp
662 5c860e29 2018-03-12 stsp git_libgit2_init();
663 5c860e29 2018-03-12 stsp
664 5c860e29 2018-03-12 stsp if (git_repository_open_ext(&repo, ".", 0, NULL))
665 5c860e29 2018-03-12 stsp errx(1, "git_repository_open: %s", giterr_last()->message);
666 5c860e29 2018-03-12 stsp
667 5c860e29 2018-03-12 stsp if (git_repository_is_bare(repo))
668 5c860e29 2018-03-12 stsp errx(1, "bar repository");
669 5c860e29 2018-03-12 stsp
670 5c860e29 2018-03-12 stsp if (git_status_init_options(&statusopts, GIT_STATUS_OPTIONS_VERSION))
671 5c860e29 2018-03-12 stsp errx(1, "git_status_init_options: %s", giterr_last()->message);
672 5c860e29 2018-03-12 stsp
673 5c860e29 2018-03-12 stsp statusopts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
674 5c860e29 2018-03-12 stsp statusopts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
675 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
676 5c860e29 2018-03-12 stsp GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
677 5c860e29 2018-03-12 stsp
678 5c860e29 2018-03-12 stsp if (git_status_list_new(&status, repo, &statusopts))
679 5c860e29 2018-03-12 stsp errx(1, "git_status_list_new: %s", giterr_last()->message);
680 5c860e29 2018-03-12 stsp
681 5c860e29 2018-03-12 stsp for (i = 0; i < git_status_list_entrycount(status); i++) {
682 5c860e29 2018-03-12 stsp const git_status_entry *se;
683 5c860e29 2018-03-12 stsp
684 5c860e29 2018-03-12 stsp se = git_status_byindex(status, i);
685 5c860e29 2018-03-12 stsp switch (se->status) {
686 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_NEW:
687 5c860e29 2018-03-12 stsp printf("? %s\n", se->index_to_workdir->new_file.path);
688 5c860e29 2018-03-12 stsp break;
689 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_MODIFIED:
690 5c860e29 2018-03-12 stsp printf("M %s\n", se->index_to_workdir->new_file.path);
691 5c860e29 2018-03-12 stsp break;
692 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_DELETED:
693 5c860e29 2018-03-12 stsp printf("R %s\n", se->index_to_workdir->new_file.path);
694 5c860e29 2018-03-12 stsp break;
695 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_RENAMED:
696 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
697 5c860e29 2018-03-12 stsp se->index_to_workdir->old_file.path,
698 5c860e29 2018-03-12 stsp se->index_to_workdir->new_file.path);
699 5c860e29 2018-03-12 stsp break;
700 5c860e29 2018-03-12 stsp case GIT_STATUS_WT_TYPECHANGE:
701 5c860e29 2018-03-12 stsp printf("t %s\n", se->index_to_workdir->new_file.path);
702 5c860e29 2018-03-12 stsp break;
703 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_NEW:
704 5c860e29 2018-03-12 stsp printf("A %s\n", se->head_to_index->new_file.path);
705 5c860e29 2018-03-12 stsp break;
706 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_MODIFIED:
707 5c860e29 2018-03-12 stsp printf("M %s\n", se->head_to_index->old_file.path);
708 5c860e29 2018-03-12 stsp break;
709 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_DELETED:
710 5c860e29 2018-03-12 stsp printf("R %s\n", se->head_to_index->old_file.path);
711 5c860e29 2018-03-12 stsp break;
712 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_RENAMED:
713 5c860e29 2018-03-12 stsp printf("m %s -> %s\n",
714 5c860e29 2018-03-12 stsp se->head_to_index->old_file.path,
715 5c860e29 2018-03-12 stsp se->head_to_index->new_file.path);
716 5c860e29 2018-03-12 stsp break;
717 5c860e29 2018-03-12 stsp case GIT_STATUS_INDEX_TYPECHANGE:
718 5c860e29 2018-03-12 stsp printf("t %s\n", se->head_to_index->old_file.path);
719 5c860e29 2018-03-12 stsp break;
720 5c860e29 2018-03-12 stsp case GIT_STATUS_CURRENT:
721 5c860e29 2018-03-12 stsp default:
722 5c860e29 2018-03-12 stsp break;
723 5c860e29 2018-03-12 stsp }
724 5c860e29 2018-03-12 stsp }
725 5c860e29 2018-03-12 stsp
726 5c860e29 2018-03-12 stsp git_status_list_free(status);
727 5c860e29 2018-03-12 stsp git_repository_free(repo);
728 5c860e29 2018-03-12 stsp git_libgit2_shutdown();
729 5c860e29 2018-03-12 stsp
730 5c860e29 2018-03-12 stsp return 0;
731 5c860e29 2018-03-12 stsp }
732 f42b1b34 2018-03-12 stsp #endif