Re: [PATCH v5 28/28] count-objects: report unused files in $GIT_DIR/repos/...

2014-03-09 Thread Eric Sunshine
On Fri, Mar 7, 2014 at 9:48 PM, Nguyễn Thái Ngọc Duy pclo...@gmail.com wrote:
 In linked checkouts, borrowed parts like config is taken from
 $GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as
 garbage.

 Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
 ---
 diff --git a/path.c b/path.c
 index ddb5962..5a7dc45 100644
 --- a/path.c
 +++ b/path.c
 @@ -4,6 +4,7 @@
  #include cache.h
  #include strbuf.h
  #include string-list.h
 +#include dir.h

  static int get_st_mode_bits(const char *path, int *mode)
  {
 @@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, const 
 char *newdir)
  }

Do you want to add a comment here explaining what the ! prefix on
some entries means, or is it sufficiently self-evident to anyone
looking at the consumers of this array?

  static const char *common_list[] = {
 -   /branches, /hooks, /info, /logs, /lost-found, /modules,
 +   /branches, /hooks, /info, !/logs, /lost-found, /modules,
 /objects, /refs, /remotes, /repos, /rr-cache, /svn,
 -   config, gc.pid, packed-refs, shallow,
 +   config, !gc.pid, packed-refs, shallow,
 NULL
  };

 @@ -107,6 +108,8 @@ static void update_common_dir(struct strbuf *buf, int 
 git_dir_len)
 for (p = common_list; *p; p++) {
 const char *path = *p;
 int is_dir = 0;
 +   if (*path == '!')
 +   path++;
 if (*path == '/') {
 path++;
 is_dir = 1;
 @@ -122,6 +125,28 @@ static void update_common_dir(struct strbuf *buf, int 
 git_dir_len)
 }
  }

 +void report_linked_checkout_garbage(void)
 +{
 +   struct strbuf sb = STRBUF_INIT;
 +   const char **p;
 +   int len;
 +
 +   if (!git_common_dir_env)
 +   return;
 +   strbuf_addf(sb, %s/, get_git_dir());
 +   len = sb.len;
 +   for (p = common_list; *p; p++) {
 +   const char *path = *p;
 +   if (*path == '!')
 +   continue;
 +   strbuf_setlen(sb, len);
 +   strbuf_addstr(sb, path);
 +   if (file_exists(sb.buf))
 +   report_garbage(unused in linked checkout, sb.buf);
 +   }
 +   strbuf_release(sb);
 +}
 +
  static void adjust_git_path(struct strbuf *buf, int git_dir_len)
  {
 const char *base = buf-buf + git_dir_len;
 --
 1.9.0.40.gaa8c3ea
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 28/28] count-objects: report unused files in $GIT_DIR/repos/...

2014-03-09 Thread Duy Nguyen
On Sun, Mar 9, 2014 at 3:21 PM, Eric Sunshine sunsh...@sunshineco.com wrote:
 On Fri, Mar 7, 2014 at 9:48 PM, Nguyễn Thái Ngọc Duy pclo...@gmail.com 
 wrote:
 In linked checkouts, borrowed parts like config is taken from
 $GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as
 garbage.

 Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
 ---
 diff --git a/path.c b/path.c
 index ddb5962..5a7dc45 100644
 --- a/path.c
 +++ b/path.c
 @@ -4,6 +4,7 @@
  #include cache.h
  #include strbuf.h
  #include string-list.h
 +#include dir.h

  static int get_st_mode_bits(const char *path, int *mode)
  {
 @@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, const 
 char *newdir)
  }

 Do you want to add a comment here explaining what the ! prefix on
 some entries means, or is it sufficiently self-evident to anyone
 looking at the consumers of this array?

I was hoping it was clear from the patch how this ! was used (or /
in the patch that introduces common_list[]). But if any reader thinks
otherwise, I'm happy to add a comment.
-- 
Duy
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 28/28] count-objects: report unused files in $GIT_DIR/repos/...

2014-03-07 Thread Nguyễn Thái Ngọc Duy
In linked checkouts, borrowed parts like config is taken from
$GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as
garbage.

Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
---
 builtin/count-objects.c |  4 +++-
 cache.h |  1 +
 path.c  | 29 +++--
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a7f70cb..d3a1620 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -102,8 +102,10 @@ int cmd_count_objects(int argc, const char **argv, const 
char *prefix)
/* we do not take arguments other than flags for now */
if (argc)
usage_with_options(count_objects_usage, opts);
-   if (verbose)
+   if (verbose) {
report_garbage = real_report_garbage;
+   report_linked_checkout_garbage();
+   }
memcpy(path, objdir, len);
if (len  objdir[len-1] != '/')
path[len++] = '/';
diff --git a/cache.h b/cache.h
index 979ac6e..a0ff430 100644
--- a/cache.h
+++ b/cache.h
@@ -662,6 +662,7 @@ extern const char *mkpath(const char *fmt, ...) 
__attribute__((format (printf, 1
 extern const char *git_path(const char *fmt, ...) __attribute__((format 
(printf, 1, 2)));
 extern const char *git_path_submodule(const char *path, const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
+extern void report_linked_checkout_garbage(void);
 
 extern char *sha1_file_name(const unsigned char *sha1);
 extern char *sha1_pack_name(const unsigned char *sha1);
diff --git a/path.c b/path.c
index ddb5962..5a7dc45 100644
--- a/path.c
+++ b/path.c
@@ -4,6 +4,7 @@
 #include cache.h
 #include strbuf.h
 #include string-list.h
+#include dir.h
 
 static int get_st_mode_bits(const char *path, int *mode)
 {
@@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, const 
char *newdir)
 }
 
 static const char *common_list[] = {
-   /branches, /hooks, /info, /logs, /lost-found, /modules,
+   /branches, /hooks, /info, !/logs, /lost-found, /modules,
/objects, /refs, /remotes, /repos, /rr-cache, /svn,
-   config, gc.pid, packed-refs, shallow,
+   config, !gc.pid, packed-refs, shallow,
NULL
 };
 
@@ -107,6 +108,8 @@ static void update_common_dir(struct strbuf *buf, int 
git_dir_len)
for (p = common_list; *p; p++) {
const char *path = *p;
int is_dir = 0;
+   if (*path == '!')
+   path++;
if (*path == '/') {
path++;
is_dir = 1;
@@ -122,6 +125,28 @@ static void update_common_dir(struct strbuf *buf, int 
git_dir_len)
}
 }
 
+void report_linked_checkout_garbage(void)
+{
+   struct strbuf sb = STRBUF_INIT;
+   const char **p;
+   int len;
+
+   if (!git_common_dir_env)
+   return;
+   strbuf_addf(sb, %s/, get_git_dir());
+   len = sb.len;
+   for (p = common_list; *p; p++) {
+   const char *path = *p;
+   if (*path == '!')
+   continue;
+   strbuf_setlen(sb, len);
+   strbuf_addstr(sb, path);
+   if (file_exists(sb.buf))
+   report_garbage(unused in linked checkout, sb.buf);
+   }
+   strbuf_release(sb);
+}
+
 static void adjust_git_path(struct strbuf *buf, int git_dir_len)
 {
const char *base = buf-buf + git_dir_len;
-- 
1.9.0.40.gaa8c3ea

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html