From: Stefan Beller <sbeller@google.com>
To: bmwill@google.com
Cc: git@vger.kernel.org, pclouds@gmail.com, gitster@pobox.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCHv6 5/7] worktree: add function to check if worktrees are in use
Date: Wed, 7 Dec 2016 17:46:21 -0800 [thread overview]
Message-ID: <20161208014623.7588-6-sbeller@google.com> (raw)
In-Reply-To: <20161208014623.7588-1-sbeller@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
worktree.c | 24 ++++++++++++++++++++++++
worktree.h | 7 +++++++
2 files changed, 31 insertions(+)
diff --git a/worktree.c b/worktree.c
index 75db689672..2559f33846 100644
--- a/worktree.c
+++ b/worktree.c
@@ -406,3 +406,27 @@ const struct worktree *find_shared_symref(const char *symref,
return existing;
}
+
+static int uses_worktree_internal(struct worktree **worktrees)
+{
+ int i;
+ for (i = 0; worktrees[i]; i++)
+ ; /* nothing */
+
+ free_worktrees(worktrees);
+ return i > 1;
+}
+
+int uses_worktrees(void)
+{
+ return uses_worktree_internal(get_worktrees(0));
+}
+
+int submodule_uses_worktrees(const char *path)
+{
+ struct worktree **worktrees = get_submodule_worktrees(path, 0);
+ if (!worktrees)
+ return 0;
+
+ return uses_worktree_internal(worktrees);
+}
diff --git a/worktree.h b/worktree.h
index 157fbc4a66..76027b1fd2 100644
--- a/worktree.h
+++ b/worktree.h
@@ -33,6 +33,13 @@ extern struct worktree **get_worktrees(unsigned flags);
extern struct worktree **get_submodule_worktrees(const char *path,
unsigned flags);
+/*
+ * Returns 1 if more than one worktree exists.
+ * Returns 0 if only the main worktree exists.
+ */
+extern int uses_worktrees(void);
+extern int submodule_uses_worktrees(const char *path);
+
/*
* Return git dir of the worktree. Note that the path may be relative.
* If wt is NULL, git dir of current worktree is returned.
--
2.11.0.rc2.30.gc512cbd.dirty
next prev parent reply other threads:[~2016-12-08 1:47 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 1:46 [PATCHv6 0/7] submodule embedgitdirs Stefan Beller
2016-12-08 1:46 ` [PATCHv6 1/7] submodule: use absolute path for computing relative path connecting Stefan Beller
2016-12-08 9:45 ` Duy Nguyen
2016-12-08 1:46 ` [PATCHv6 2/7] submodule helper: support super prefix Stefan Beller
2016-12-08 9:52 ` Duy Nguyen
2016-12-08 20:19 ` Stefan Beller
2016-12-08 1:46 ` [PATCHv6 3/7] test-lib-functions.sh: teach test_commit -C <dir> Stefan Beller
2016-12-08 1:46 ` [PATCHv6 4/7] worktree: get worktrees from submodules Stefan Beller
2016-12-08 10:09 ` Duy Nguyen
2016-12-08 18:55 ` Stefan Beller
2016-12-09 12:46 ` Duy Nguyen
2016-12-09 23:00 ` Brandon Williams
2016-12-09 23:10 ` Stefan Beller
2016-12-08 1:46 ` Stefan Beller [this message]
2016-12-08 10:40 ` [PATCHv6 5/7] worktree: add function to check if worktrees are in use Duy Nguyen
2016-12-08 10:51 ` Duy Nguyen
2016-12-08 19:32 ` Stefan Beller
2016-12-08 1:46 ` [PATCHv6 6/7] move connect_work_tree_and_git_dir to dir.h Stefan Beller
2016-12-08 1:46 ` [PATCHv6 7/7] submodule: add absorb-git-dir function Stefan Beller
2016-12-08 10:56 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161208014623.7588-6-sbeller@google.com \
--to=sbeller@google.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.