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

Function list

builtin/worktree.c:1081–1131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1079}
1080
1081static int list(int ac, const char **av, const char *prefix,
1082 struct repository *repo UNUSED)
1083{
1084 int porcelain = 0;
1085 int line_terminator = '\n';
1086
1087 struct option options[] = {
1088 OPT_BOOL(0, "porcelain", &porcelain, N_("machine-readable output")),
1089 OPT__VERBOSE(&verbose, N_("show extended annotations and reasons, if available")),
1090 OPT_EXPIRY_DATE(0, "expire", &expire,
1091 N_("add 'prunable' annotation to missing worktrees older than <time>")),
1092 OPT_SET_INT('z', NULL, &line_terminator,
1093 N_("terminate records with a NUL character"), '\0'),
1094 OPT_END()
1095 };
1096
1097 expire = TIME_MAX;
1098 ac = parse_options(ac, av, prefix, options, git_worktree_list_usage, 0);
1099 if (ac)
1100 usage_with_options(git_worktree_list_usage, options);
1101 else if (verbose && porcelain)
1102 die(_("options '%s' and '%s' cannot be used together"), "--verbose", "--porcelain");
1103 else if (!line_terminator && !porcelain)
1104 die(_("the option '%s' requires '%s'"), "-z", "--porcelain");
1105 else {
1106 struct worktree **worktrees = get_worktrees();
1107 int path_maxwidth = 0, abbrev = DEFAULT_ABBREV, i;
1108 struct worktree_display *display = NULL;
1109
1110 /* sort worktrees by path but keep main worktree at top */
1111 pathsort(worktrees + 1);
1112
1113 if (!porcelain)
1114 measure_widths(worktrees, &abbrev,
1115 &display, &path_maxwidth);
1116
1117 for (i = 0; worktrees[i]; i++) {
1118 if (porcelain)
1119 show_worktree_porcelain(worktrees[i],
1120 line_terminator);
1121 else
1122 show_worktree(worktrees[i],
1123 &display[i], path_maxwidth, abbrev);
1124 }
1125 for (i = 0; display && worktrees[i]; i++)
1126 free(display[i].path);
1127 free(display);
1128 free_worktrees(worktrees);
1129 }
1130 return 0;
1131}
1132
1133static int lock_worktree(int ac, const char **av, const char *prefix,
1134 struct repository *repo UNUSED)

Callers

nothing calls this directly

Calls 9

parse_optionsFunction · 0.85
usage_with_optionsFunction · 0.85
get_worktreesFunction · 0.85
pathsortFunction · 0.85
measure_widthsFunction · 0.85
show_worktree_porcelainFunction · 0.85
show_worktreeFunction · 0.85
free_worktreesFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected