]> git.ipfire.org Git - thirdparty/git.git/blobdiff - worktree.c
Merge branch 'ep/maint-equals-null-cocci' for maint-2.35
[thirdparty/git.git] / worktree.c
index f35ac40a84a5133d86aa2b92f10fe69ec13e2241..a7b184f4f590ecbb4e15b3e6cfbca6ecd4e54d1a 100644 (file)
@@ -28,11 +28,13 @@ static void add_head_info(struct worktree *wt)
 {
        int flags;
        const char *target;
+       int ignore_errno;
 
        target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
                                         "HEAD",
                                         0,
-                                        &wt->head_oid, &flags);
+                                        &wt->head_oid, &flags,
+                                        &ignore_errno);
        if (!target)
                return;
 
@@ -128,10 +130,8 @@ struct worktree **get_worktrees(void)
        dir = opendir(path.buf);
        strbuf_release(&path);
        if (dir) {
-               while ((d = readdir(dir)) != NULL) {
+               while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
                        struct worktree *linked = NULL;
-                       if (is_dot_or_dotdot(d->d_name))
-                               continue;
 
                        if ((linked = get_linked_worktree(d->d_name))) {
                                ALLOC_GROW(list, counter + 1, alloc);
@@ -267,6 +267,7 @@ const char *worktree_prune_reason(struct worktree *wt, timestamp_t expire)
 }
 
 /* convenient wrapper to deal with NULL strbuf */
+__attribute__((format (printf, 2, 3)))
 static void strbuf_addf_gently(struct strbuf *buf, const char *fmt, ...)
 {
        va_list params;
@@ -403,22 +404,19 @@ int is_worktree_being_bisected(const struct worktree *wt,
  * bisect). New commands that do similar things should update this
  * function as well.
  */
-const struct worktree *find_shared_symref(const char *symref,
+const struct worktree *find_shared_symref(struct worktree **worktrees,
+                                         const char *symref,
                                          const char *target)
 {
        const struct worktree *existing = NULL;
-       static struct worktree **worktrees;
        int i = 0;
 
-       if (worktrees)
-               free_worktrees(worktrees);
-       worktrees = get_worktrees();
-
        for (i = 0; worktrees[i]; i++) {
                struct worktree *wt = worktrees[i];
                const char *symref_target;
                struct ref_store *refs;
                int flags;
+               int ignore_errno;
 
                if (wt->is_bare)
                        continue;
@@ -436,7 +434,8 @@ const struct worktree *find_shared_symref(const char *symref,
 
                refs = get_worktree_ref_store(wt);
                symref_target = refs_resolve_ref_unsafe(refs, symref, 0,
-                                                       NULL, &flags);
+                                                       NULL, &flags,
+                                                       &ignore_errno);
                if ((flags & REF_ISSYMREF) &&
                    symref_target && !strcmp(symref_target, target)) {
                        existing = wt;
@@ -486,13 +485,9 @@ int submodule_uses_worktrees(const char *path)
        if (!dir)
                return 0;
 
-       while ((d = readdir(dir)) != NULL) {
-               if (is_dot_or_dotdot(d->d_name))
-                       continue;
-
+       d = readdir_skip_dot_and_dotdot(dir);
+       if (d)
                ret = 1;
-               break;
-       }
        closedir(dir);
        return ret;
 }
@@ -568,16 +563,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
                struct worktree *wt = *p;
                struct object_id oid;
                int flag;
+               int ignore_errno;
 
                if (wt->is_current)
                        continue;
 
                strbuf_reset(&refname);
                strbuf_worktree_ref(wt, &refname, "HEAD");
-               if (!refs_read_ref_full(get_main_ref_store(the_repository),
-                                       refname.buf,
-                                       RESOLVE_REF_READING,
-                                       &oid, &flag))
+               if (refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+                                           refname.buf,
+                                           RESOLVE_REF_READING,
+                                           &oid, &flag, &ignore_errno))
                        ret = fn(refname.buf, &oid, flag, cb_data);
                if (ret)
                        break;