@matheusbsbs / matheus-bagliano / commits / 175a494823
Fork 0

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>

Alex Riesen committed Sep 27, 2008 at 00:59 UTC 175a494823c1eacd4da9c4a5b90ec0668f7051c0
3 files changed +5 -49
builtin-apply.c
+2 -9
@@ -13,6 +13,7 @@
13 #include "delta.h"
14 #include "builtin.h"
15 #include "string-list.h"
16 +#include "dir.h"
17
18 /*
19 * --check turns on checking that the working tree matches the
@@ -2735,15 +2736,7 @@ static void remove_file(struct patch *patch, int rmdir_empty)
2736 warning("unable to remove submodule %s",
2737 patch->old_name);
2738 } else if (!unlink(patch->old_name) && rmdir_empty) {
2738 - char *name = xstrdup(patch->old_name);
2739 - char *end = strrchr(name, '/');
2740 - while (end) {
2741 - *end = 0;
2742 - if (rmdir(name))
2743 - break;
2744 - end = strrchr(name, '/');
2745 - }
2746 - free(name);
2739 + remove_path(patch->old_name);
2740 }
2741 }
2742 }
builtin-merge-recursive.c
+2 -19
@@ -18,6 +18,7 @@
18 #include "ll-merge.h"
19 #include "interpolate.h"
20 #include "attr.h"
21 +#include "dir.h"
22 #include "merge-recursive.h"
23
24 static int subtree_merge;
@@ -416,24 +417,6 @@ static int update_stages(const char *path, struct diff_filespec *o,
417 return 0;
418 }
419
419 -static int remove_path(const char *name)
420 -{
421 - int ret;
422 - char *slash, *dirs;
423 -
424 - ret = unlink(name);
425 - if (ret)
426 - return ret;
427 - dirs = xstrdup(name);
428 - while ((slash = strrchr(name, '/'))) {
429 - *slash = '\0';
430 - if (rmdir(name) != 0)
431 - break;
432 - }
433 - free(dirs);
434 - return ret;
435 -}
436 -
420 static int remove_file(int clean, const char *path, int no_wd)
421 {
422 int update_cache = index_only || clean;
@@ -444,7 +427,7 @@ static int remove_file(int clean, const char *path, int no_wd)
427 return -1;
428 }
429 if (update_working_directory) {
447 - if (remove_path(path) && errno != ENOENT)
430 + if (remove_path(path))
431 return -1;
432 }
433 return 0;
builtin-rm.c
+1 -21
@@ -29,26 +29,6 @@ static void add_list(const char *name)
29 list.name[list.nr++] = name;
30 }
31
32 -static int remove_file(const char *name)
33 -{
34 - int ret;
35 - char *slash;
36 -
37 - ret = unlink(name);
38 - if (ret && errno == ENOENT)
39 - /* The user has removed it from the filesystem by hand */
40 - ret = errno = 0;
41 -
42 - if (!ret && (slash = strrchr(name, '/'))) {
43 - char *n = xstrdup(name);
44 - do {
45 - n[slash - name] = 0;
46 - name = n;
47 - } while (!rmdir(name) && (slash = strrchr(name, '/')));
48 - }
49 - return ret;
50 -}
51 -
32 static int check_local_mod(unsigned char *head, int index_only)
33 {
34 /* 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)
219 int removed = 0;
220 for (i = 0; i < list.nr; i++) {
221 const char *path = list.name[i];
242 - if (!remove_file(path)) {
222 + if (!remove_path(path)) {
223 removed = 1;
224 continue;
225 }