MCPcopy Index your code
hub / github.com/git/git / should_prune_worktree

Function should_prune_worktree

worktree.c:929–1018  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

927}
928
929int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, timestamp_t expire)
930{
931 struct stat st;
932 struct strbuf dotgit = STRBUF_INIT;
933 struct strbuf gitdir = STRBUF_INIT;
934 struct strbuf repo = STRBUF_INIT;
935 struct strbuf file = STRBUF_INIT;
936 char *path = NULL;
937 int rc = 0;
938 int fd;
939 size_t len;
940 ssize_t read_result;
941
942 *wtpath = NULL;
943
944 path = repo_common_path(the_repository, "worktrees/%s", id);
945 strbuf_realpath(&repo, path, 1);
946 FREE_AND_NULL(path);
947
948 strbuf_addf(&gitdir, "%s/gitdir", repo.buf);
949 if (!is_directory(repo.buf)) {
950 strbuf_addstr(reason, _("not a valid directory"));
951 rc = 1;
952 goto done;
953 }
954 strbuf_addf(&file, "%s/locked", repo.buf);
955 if (file_exists(file.buf)) {
956 goto done;
957 }
958 if (stat(gitdir.buf, &st)) {
959 strbuf_addstr(reason, _("gitdir file does not exist"));
960 rc = 1;
961 goto done;
962 }
963 fd = open(gitdir.buf, O_RDONLY);
964 if (fd < 0) {
965 strbuf_addf(reason, _("unable to read gitdir file (%s)"),
966 strerror(errno));
967 rc = 1;
968 goto done;
969 }
970 len = xsize_t(st.st_size);
971 path = xmallocz(len);
972
973 read_result = read_in_full(fd, path, len);
974 close(fd);
975 if (read_result < 0) {
976 strbuf_addf(reason, _("unable to read gitdir file (%s)"),
977 strerror(errno));
978 rc = 1;
979 goto done;
980 } else if (read_result != len) {
981 strbuf_addf(reason,
982 _("short read (expected %"PRIuMAX" bytes, read %"PRIuMAX")"),
983 (uintmax_t)len, (uintmax_t)read_result);
984 rc = 1;
985 goto done;
986 }

Callers 3

worktree_prune_reasonFunction · 0.85
prune_worktreesFunction · 0.85
worktree_prune_conditionFunction · 0.85

Calls 14

repo_common_pathFunction · 0.85
strbuf_realpathFunction · 0.85
strbuf_addfFunction · 0.85
is_directoryFunction · 0.85
strbuf_addstrFunction · 0.85
file_existsFunction · 0.85
xsize_tFunction · 0.85
xmalloczFunction · 0.85
read_in_fullFunction · 0.85
is_absolute_pathFunction · 0.85
strbuf_detachFunction · 0.85

Tested by

no test coverage detected