From: Alex Riesen <raa.lkml@gmail.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] Fix memleak and the implementation of remove_file in builtin-rm.c
Date: Thu, 25 Sep 2008 22:22:37 +0200 [thread overview]
Message-ID: <20080925202237.GB18315@blimp.localhost> (raw)
In-Reply-To: <20080925201734.GA18315@blimp.localhost>
Actually, just replace it with the one from builtin-merge-recursive.c,
except for ignoring ENOENT error.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
It is the same as in merge-recursive, but they're so small so unless
we get a special file with such random routines there is no much point
exporting it. Actually, we do seem to have such a file: dir.c. It is
already plagued by file_exists kind of things, why not remove_path...
builtin-rm.c | 24 ++++++++++--------------
1 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/builtin-rm.c b/builtin-rm.c
index fdac34f..910a34d 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -31,22 +31,18 @@ static void add_list(const char *name)
static int remove_file(const char *name)
{
- int ret;
- char *slash;
-
- ret = unlink(name);
- if (ret && errno == ENOENT)
- /* The user has removed it from the filesystem by hand */
- ret = errno = 0;
-
- if (!ret && (slash = strrchr(name, '/'))) {
- char *n = xstrdup(name);
- do {
- n[slash - name] = 0;
- name = n;
- } while (!rmdir(name) && (slash = strrchr(name, '/')));
+ char *slash, *dirs;
+
+ if (unlink(name) && errno != ENOENT)
+ return -1;
+ dirs = xstrdup(name);
+ while ((slash = strrchr(name, '/'))) {
+ *slash = '\0';
+ if (rmdir(name) != 0)
+ break;
}
- return ret;
+ free(dirs);
+ return 0;
}
static int check_local_mod(unsigned char *head, int index_only)
--
1.6.0.2.328.g14651
next prev parent reply other threads:[~2008-09-25 20:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-24 16:32 [BUG] git merge does not prune empty directories Anders Melchiorsen
2008-09-25 20:12 ` [PATCH] Remove empty directories in recursive merge Alex Riesen
2008-09-25 20:17 ` [PATCH] Cleanup remove_path Alex Riesen
2008-09-25 20:22 ` Alex Riesen [this message]
2008-09-26 15:28 ` [PATCH] Fix memleak and the implementation of remove_file in builtin-rm.c Shawn O. Pearce
2008-09-26 22:56 ` [PATCH] Add remove_path: a function to remove as much as possible of a path Alex Riesen
2008-09-26 22:59 ` [PATCH] Use remove_path from dir.c instead of own implementation Alex Riesen
2008-09-25 20:33 ` [PATCH] Remove empty directories in recursive merge Alex Riesen
2008-09-26 15:06 ` Shawn O. Pearce
2008-09-26 5:58 ` 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=20080925202237.GB18315@blimp.localhost \
--to=raa.lkml@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.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).