MCPcopy Create free account
hub / github.com/git/git / cmd__path_utils

Function cmd__path_utils

t/helper/test-path-utils.c:304–549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304int cmd__path_utils(int argc, const char **argv)
305{
306 if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
307 char *buf = xmallocz(strlen(argv[2]));
308 int rv = normalize_path_copy(buf, argv[2]);
309 puts(rv ? "++failed++" : buf);
310 free(buf);
311 return 0;
312 }
313
314 if (argc >= 2 && !strcmp(argv[1], "real_path")) {
315 struct strbuf realpath = STRBUF_INIT;
316 while (argc > 2) {
317 strbuf_realpath(&realpath, argv[2], 1);
318 puts(realpath.buf);
319 argc--;
320 argv++;
321 }
322 strbuf_release(&realpath);
323 return 0;
324 }
325
326 if (argc >= 2 && !strcmp(argv[1], "readlink")) {
327 struct strbuf target = STRBUF_INIT;
328 while (argc > 2) {
329 if (strbuf_readlink(&target, argv[2], 0) < 0)
330 die_errno("cannot read link at '%s'", argv[2]);
331 puts(target.buf);
332 argc--;
333 argv++;
334 }
335 strbuf_release(&target);
336 return 0;
337 }
338
339 if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
340 while (argc > 2) {
341 puts(absolute_path(argv[2]));
342 argc--;
343 argv++;
344 }
345 return 0;
346 }
347
348 if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
349 int len;
350 struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
351 const char path_sep[] = { PATH_SEP, '\0' };
352 char *path = xstrdup(argv[2]);
353
354 /*
355 * We have to normalize the arguments because under
356 * Windows, bash mangles arguments that look like
357 * absolute POSIX paths or colon-separate lists of
358 * absolute POSIX paths into DOS paths (e.g.,
359 * "/foo:/foo/bar" might be converted to
360 * "D:\Src\msysgit\foo;D:\Src\msysgit\foo\bar"),
361 * whereas longest_ancestor_length() requires paths

Callers

nothing calls this directly

Calls 15

xmalloczFunction · 0.85
normalize_path_copyFunction · 0.85
strbuf_realpathFunction · 0.85
strbuf_releaseFunction · 0.85
strbuf_readlinkFunction · 0.85
die_errnoFunction · 0.85
absolute_pathFunction · 0.85
xstrdupFunction · 0.85
string_list_splitFunction · 0.85
filter_string_listFunction · 0.85
longest_ancestor_lengthFunction · 0.85
string_list_clearFunction · 0.85

Tested by

no test coverage detected