summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Riesen <raa.lkml@gmail.com>2008-09-26 22:59:14 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2008-09-29 15:37:07 (GMT)
commit175a494823c1eacd4da9c4a5b90ec0668f7051c0 (patch)
tree4877e614101afd3512573199e95f9b8b7dbdd0bb
parent4a92d1bfb784b09641180d164e7d719080165dc4 (diff)
downloadgit-175a494823c1eacd4da9c4a5b90ec0668f7051c0.zip
git-175a494823c1eacd4da9c4a5b90ec0668f7051c0.tar.gz
git-175a494823c1eacd4da9c4a5b90ec0668f7051c0.tar.bz2
Use remove_path from dir.c instead of own implementation
Besides, it fixes a memleak (builtin-rm.c) and accidental change of the input const argument (builtin-merge-recursive.c). Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--builtin-apply.c11
-rw-r--r--builtin-merge-recursive.c21
-rw-r--r--builtin-rm.c22
3 files changed, 5 insertions, 49 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 20bef1f..70c9f93 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -13,6 +13,7 @@
#include "delta.h"
#include "builtin.h"
#include "string-list.h"
+#include "dir.h"
/*
* --check turns on checking that the working tree matches the
@@ -2735,15 +2736,7 @@ static void remove_file(struct patch *patch, int rmdir_empty)
warning("unable to remove submodule %s",
patch->old_name);
} else if (!unlink(patch->old_name) && rmdir_empty) {
- char *name = xstrdup(patch->old_name);
- char *end = strrchr(name, '/');
- while (end) {
- *end = 0;
- if (rmdir(name))
- break;
- end = strrchr(name, '/');
- }
- free(name);
+ remove_path(patch->old_name);
}
}
}
diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
index f628a62..b973865 100644
--- a/builtin-merge-recursive.c
+++ b/builtin-merge-recursive.c
@@ -18,6 +18,7 @@
#include "ll-merge.h"
#include "interpolate.h"
#include "attr.h"
+#include "dir.h"
#include "merge-recursive.h"
static int subtree_merge;
@@ -416,24 +417,6 @@ static int update_stages(const char *path, struct diff_filespec *o,
return 0;
}
-static int remove_path(const char *name)
-{
- int ret;
- char *slash, *dirs;
-
- ret = unlink(name);
- if (ret)
- return ret;
- dirs = xstrdup(name);
- while ((slash = strrchr(name, '/'))) {
- *slash = '\0';
- if (rmdir(name) != 0)
- break;
- }
- free(dirs);
- return ret;
-}
-
static int remove_file(int clean, const char *path, int no_wd)
{
int update_cache = index_only || clean;
@@ -444,7 +427,7 @@ static int remove_file(int clean, const char *path, int no_wd)
return -1;
}
if (update_working_directory) {
- if (remove_path(path) && errno != ENOENT)
+ if (remove_path(path))
return -1;
}
return 0;
diff --git a/builtin-rm.c b/builtin-rm.c
index fdac34f..50ae6d5 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -29,26 +29,6 @@ static void add_list(const char *name)
list.name[list.nr++] = 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, '/')));
- }
- return ret;
-}
-
static int check_local_mod(unsigned char *head, int index_only)
{
/* items in list are already sorted in the cache order,
@@ -239,7 +219,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
int removed = 0;
for (i = 0; i < list.nr; i++) {
const char *path = list.name[i];
- if (!remove_file(path)) {
+ if (!remove_path(path)) {
removed = 1;
continue;
}