From: Jason Holden <jason.k.holden@gmail.com>
To: git@vger.kernel.org
Cc: Jason Holden <jason.k.holden@gmail.com>
Subject: [PATCH 1/2] Add option to not delete a .git directory in remove_dir_recursively()
Date: Mon, 29 Jun 2009 22:10:44 -0400 [thread overview]
Message-ID: <1246327845-22718-2-git-send-email-jason.k.holden@gmail.com> (raw)
In-Reply-To: <1246327845-22718-1-git-send-email-jason.k.holden@gmail.com>
Because all existing calls to remove_dir_recursively() do not
currently have this protection, default all existing calls
to 0 (to not keep .git directories)
Signed-off-by: Jason Holden <jason.k.holden@gmail.com>
---
builtin-clean.c | 2 +-
builtin-clone.c | 4 ++--
dir.c | 17 +++++++++++++++--
dir.h | 2 +-
refs.c | 2 +-
transport.c | 4 ++--
6 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/builtin-clean.c b/builtin-clean.c
index 1c1b6d2..cd82407 100644
--- a/builtin-clean.c
+++ b/builtin-clean.c
@@ -141,7 +141,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
(matches == MATCHED_EXACTLY)) {
if (!quiet)
printf("Removing %s\n", qname);
- if (remove_dir_recursively(&directory, 0) != 0) {
+ if (remove_dir_recursively(&directory, 0, 0) != 0) {
warning("failed to remove '%s'", qname);
errors++;
}
diff --git a/builtin-clone.c b/builtin-clone.c
index 2ceacb7..0c00c87 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -304,12 +304,12 @@ static void remove_junk(void)
return;
if (junk_git_dir) {
strbuf_addstr(&sb, junk_git_dir);
- remove_dir_recursively(&sb, 0);
+ remove_dir_recursively(&sb, 0, 0);
strbuf_reset(&sb);
}
if (junk_work_tree) {
strbuf_addstr(&sb, junk_work_tree);
- remove_dir_recursively(&sb, 0);
+ remove_dir_recursively(&sb, 0, 0);
strbuf_reset(&sb);
}
}
diff --git a/dir.c b/dir.c
index bbfcb56..eadcddd 100644
--- a/dir.c
+++ b/dir.c
@@ -800,7 +800,7 @@ int is_empty_dir(const char *path)
return ret;
}
-int remove_dir_recursively(struct strbuf *path, int only_empty)
+int remove_dir_recursively(struct strbuf *path, int only_empty, int keep_dot_git)
{
DIR *dir = opendir(path->buf);
struct dirent *e;
@@ -812,6 +812,19 @@ int remove_dir_recursively(struct strbuf *path, int only_empty)
strbuf_addch(path, '/');
len = path->len;
+
+ if (keep_dot_git) {
+ char end_of_path[6]; /* enough space for ".git/"*/
+ memset(end_of_path, '\0', 6);
+ if (len >= 5) {
+ strncpy(end_of_path, path->buf + len - 5, 5);
+ if (strcmp(end_of_path, ".git/") == 0) {
+ printf("********Found .git!!!! Skipping delete\n");
+ return 0;
+ }
+ }
+ }
+
while ((e = readdir(dir)) != NULL) {
struct stat st;
if (is_dot_or_dotdot(e->d_name))
@@ -822,7 +835,7 @@ int remove_dir_recursively(struct strbuf *path, int only_empty)
if (lstat(path->buf, &st))
; /* fall thru */
else if (S_ISDIR(st.st_mode)) {
- if (!remove_dir_recursively(path, only_empty))
+ if (!remove_dir_recursively(path, only_empty, keep_dot_git))
continue; /* happy */
} else if (!only_empty && !unlink(path->buf))
continue; /* happy, too */
diff --git a/dir.h b/dir.h
index 541286a..8273bb9 100644
--- a/dir.h
+++ b/dir.h
@@ -89,7 +89,7 @@ static inline int is_dot_or_dotdot(const char *name)
extern int is_empty_dir(const char *dir);
extern void setup_standard_excludes(struct dir_struct *dir);
-extern int remove_dir_recursively(struct strbuf *path, int only_empty);
+extern int remove_dir_recursively(struct strbuf *path, int only_empty, int keep_dot_git);
/* tries to remove the path with empty directories along it, ignores ENOENT */
extern int remove_path(const char *path);
diff --git a/refs.c b/refs.c
index 24438c6..4ddb361 100644
--- a/refs.c
+++ b/refs.c
@@ -820,7 +820,7 @@ static int remove_empty_directories(const char *file)
strbuf_init(&path, 20);
strbuf_addstr(&path, file);
- result = remove_dir_recursively(&path, 1);
+ result = remove_dir_recursively(&path, 1, 0);
strbuf_release(&path);
diff --git a/transport.c b/transport.c
index 501a77b..067d6b1 100644
--- a/transport.c
+++ b/transport.c
@@ -196,7 +196,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
insert_packed_refs(temp_dir.buf, &tail);
strbuf_setlen(&temp_dir, temp_dir_len);
- if (remove_dir_recursively(&temp_dir, 0))
+ if (remove_dir_recursively(&temp_dir, 0, 0))
warning ("Error removing temporary directory %s.",
temp_dir.buf);
@@ -342,7 +342,7 @@ static int rsync_transport_push(struct transport *transport,
result = error("Could not push to %s",
rsync_url(transport->url));
- if (remove_dir_recursively(&temp_dir, 0))
+ if (remove_dir_recursively(&temp_dir, 0, 0))
warning ("Could not remove temporary directory %s.",
temp_dir.buf);
--
1.6.3.2.207.ga8208
next prev parent reply other threads:[~2009-06-30 2:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-30 2:10 [PATCH 0/2] Don't delete untracked submodule's .git dirs by default Jason Holden
2009-06-30 2:10 ` Jason Holden [this message]
2009-06-30 2:10 ` [PATCH 2/2] Don't clean any untracked submodule's .git dir by default in git-clean Jason Holden
2009-06-30 6:07 ` Paolo Bonzini
2009-06-30 6:40 ` Johannes Sixt
2009-06-30 7:34 ` Junio C Hamano
2009-06-30 23:05 ` Junio C Hamano
2009-07-01 1:44 ` Jason Holden
2009-07-01 2:13 ` Junio C Hamano
2009-06-30 6:48 ` [PATCH 1/2] Add option to not delete a .git directory in remove_dir_recursively() Johannes Sixt
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=1246327845-22718-2-git-send-email-jason.k.holden@gmail.com \
--to=jason.k.holden@gmail.com \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).