From 57059091fad25427bce9b3d47e073ce0518d164b Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 9 Apr 2007 01:06:28 -0400 Subject: get rid of num_packed_objects() The coming index format change doesn't allow for the number of objects to be determined from the size of the index file directly. Instead, Let's initialize a field in the packed_git structure with the object count when the index is validated since the count is always known at that point. While at it let's reorder some struct packed_git fields to avoid padding due to needed 64-bit alignment for some of them. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 6263d8af29..ff90ebd465 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -111,7 +111,7 @@ int cmd_count_objects(int ac, const char **av, const char *prefix) for (p = packed_git; p; p = p->next) { if (!p->pack_local) continue; - packed += num_packed_objects(p); + packed += p->num_objects; num_pack++; } printf("count: %lu\n", loose); -- cgit v1.2.3 From d079837eeeadc37d266113a1fd2deb0a01aaee91 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 26 May 2007 01:24:19 -0400 Subject: Lazily open pack index files on demand In some repository configurations the user may have many packfiles, but all of the recent commits/trees/tags/blobs are likely to be in the most recent packfile (the one with the newest mtime). It is therefore common to be able to complete an entire operation by accessing only one packfile, even if there are 25 packfiles available to the repository. Rather than opening and mmaping the corresponding .idx file for every pack found, we now only open and map the .idx when we suspect there might be an object of interest in there. Of course we cannot known in advance which packfile contains an object, so we still need to scan the entire packed_git list to locate anything. But odds are users want to access objects in the most recently created packfiles first, and that may be all they ever need for the current operation. Junio observed in b867092f that placing recent packfiles before older ones can slightly improve access times for recent objects, without degrading it for historical object access. This change improves upon Junio's observations by trying even harder to avoid the .idx files that we won't need. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index ff90ebd465..ac65e03e7f 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -111,6 +111,8 @@ int cmd_count_objects(int ac, const char **av, const char *prefix) for (p = packed_git; p; p = p->next) { if (!p->pack_local) continue; + if (!p->index_data && open_pack_index(p)) + continue; packed += p->num_objects; num_pack++; } -- cgit v1.2.3 From eaa867703927c1f383637979d16c40d996cea240 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 30 May 2007 02:12:28 -0400 Subject: Simplify index access condition in count-objects, pack-redundant My earlier lazy index opening patch changed this condition to check index_data and call open_pack_index if it was NULL. In truth we only care about num_objects. Since open_pack_index does no harm if the index is already open, and all indexes are likely to be closed in this application, the "performance optimization" of inlining the index_data check here was wrong. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index ac65e03e7f..4274ec1950 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -111,7 +111,7 @@ int cmd_count_objects(int ac, const char **av, const char *prefix) for (p = packed_git; p; p = p->next) { if (!p->pack_local) continue; - if (!p->index_data && open_pack_index(p)) + if (open_pack_index(p)) continue; packed += p->num_objects; num_pack++; -- cgit v1.2.3 From 833f3abd821434fd9b12d6cea66f04f232479c22 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 15 Oct 2007 22:38:51 +0200 Subject: Make builtin-count-objects.c use parse_options. Signed-off-by: Pierre Habouzit Signed-off-by: Shawn O. Pearce --- builtin-count-objects.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 4274ec1950..f00306fb67 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -6,8 +6,7 @@ #include "cache.h" #include "builtin.h" - -static const char count_objects_usage[] = "git-count-objects [-v]"; +#include "parse-options.h" static void count_objects(DIR *d, char *path, int len, int verbose, unsigned long *loose, @@ -67,29 +66,28 @@ static void count_objects(DIR *d, char *path, int len, int verbose, } } -int cmd_count_objects(int ac, const char **av, const char *prefix) +static char const * const count_objects_usage[] = { + "git-count-objects [-v]", + NULL +}; + +int cmd_count_objects(int argc, const char **argv, const char *prefix) { - int i; - int verbose = 0; + int i, verbose = 0; const char *objdir = get_object_directory(); int len = strlen(objdir); char *path = xmalloc(len + 50); unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0; unsigned long loose_size = 0; + struct option opts[] = { + OPT__VERBOSE(&verbose), + OPT_END(), + }; - for (i = 1; i < ac; i++) { - const char *arg = av[i]; - if (*arg != '-') - break; - else if (!strcmp(arg, "-v")) - verbose = 1; - else - usage(count_objects_usage); - } - + argc = parse_options(argc, argv, opts, count_objects_usage, 0); /* we do not take arguments other than flags for now */ - if (i < ac) - usage(count_objects_usage); + if (argc) + usage_with_options(count_objects_usage, opts); memcpy(path, objdir, len); if (len && objdir[len-1] != '/') path[len++] = '/'; -- cgit v1.2.3 From 1b1dd23f2d6a707b7077cdf6bc6d4055bd0bfb7d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 13 Jul 2008 15:36:15 +0200 Subject: Make usage strings dash-less When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index f00306fb67..91b5487478 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -67,7 +67,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, } static char const * const count_objects_usage[] = { - "git-count-objects [-v]", + "git count-objects [-v]", NULL }; -- cgit v1.2.3 From f223824943e23e593b5e9cc647417a4267acc82d Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Fri, 15 Aug 2008 00:20:20 -0400 Subject: count-objects: Add total pack size to verbose output Adds the total pack size (including indexes) the verbose count-objects output, floored to the nearest kilobyte. Updates documentation to match this addition. Signed-off-by: Marcus Griep Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 91b5487478..249040b96a 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -104,6 +104,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) if (verbose) { struct packed_git *p; unsigned long num_pack = 0; + unsigned long size_pack = 0; if (!packed_git) prepare_packed_git(); for (p = packed_git; p; p = p->next) { @@ -112,12 +113,14 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) if (open_pack_index(p)) continue; packed += p->num_objects; + size_pack += p->pack_size + p->index_size; num_pack++; } printf("count: %lu\n", loose); printf("size: %lu\n", loose_size / 2); printf("in-pack: %lu\n", packed); printf("packs: %lu\n", num_pack); + printf("size-pack: %lu\n", size_pack / 1024); printf("prune-packable: %lu\n", packed_loose); printf("garbage: %lu\n", garbage); } -- cgit v1.2.3 From fdb2a2a600969598fd80f01b009fbbb020d596ab Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Aug 2008 21:57:16 +0200 Subject: compat: introduce on_disk_bytes() Some platforms do not have st_blocks member in "struct stat"; mingw already emulates it by rounding it up to closest 512-byte blocks (even though it could overcount when a file has holes). The reason to use the member is only to figure out how many kilobytes the files occupy on-disk, so give a helper function in git-compat-util.h to compute this value. Signed-off-by: Junio C Hamano Acked-by: Johannes Sixt --- builtin-count-objects.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 91b5487478..a1c9eb41cb 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -43,7 +43,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, if (lstat(path, &st) || !S_ISREG(st.st_mode)) bad = 1; else - (*loose_size) += xsize_t(st.st_blocks); + (*loose_size) += xsize_t(on_disk_bytes(st)); } if (bad) { if (verbose) { @@ -115,7 +115,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) num_pack++; } printf("count: %lu\n", loose); - printf("size: %lu\n", loose_size / 2); + printf("size: %lu\n", loose_size / 1024); printf("in-pack: %lu\n", packed); printf("packs: %lu\n", num_pack); printf("prune-packable: %lu\n", packed_loose); -- cgit v1.2.3 From bfd083b734fe812b347ee71dca416d2bcfa87480 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 8 Sep 2008 19:56:32 +0200 Subject: Correct output of git-count-objects. The non-verbose output was not changed in fdb2a2a (compat: introduce on_disk_bytes(), 2008-08-18) which caused git-count-objects to claim 512 times too much space used for loose objects. Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 6e80fe7c01..ab35b65b07 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -126,6 +126,6 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) } else printf("%lu objects, %lu kilobytes\n", - loose, loose_size / 2); + loose, loose_size / 1024); return 0; } -- cgit v1.2.3 From 8ca12c0d62c0be4a4987c4a936467ea2a92e915a Mon Sep 17 00:00:00 2001 From: Alexander Potashev Date: Sat, 10 Jan 2009 15:07:50 +0300 Subject: add is_dot_or_dotdot inline function A new inline function is_dot_or_dotdot is used to check if the directory name is either "." or "..". It returns a non-zero value if the given string is "." or "..". It's applicable to a lot of Git source code. Signed-off-by: Alexander Potashev Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index ab35b65b07..62fd1f0961 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "dir.h" #include "builtin.h" #include "parse-options.h" @@ -21,9 +22,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, const char *cp; int bad = 0; - if ((ent->d_name[0] == '.') && - (ent->d_name[1] == 0 || - ((ent->d_name[1] == '.') && (ent->d_name[2] == 0)))) + if (is_dot_or_dotdot(ent->d_name)) continue; for (cp = ent->d_name; *cp; cp++) { int ch = *cp; -- cgit v1.2.3 From cd673c1f17228d272c4b7f81fbb28bc31cf0cac6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Feb 2009 23:15:53 -0800 Subject: has_sha1_pack(): refactor "pretend these packs do not exist" interface Most of the callers of this function except only one pass NULL to its last parameter, ignore_packed. Introduce has_sha1_kept_pack() function that has the function signature and the semantics of this function, and convert the sole caller that does not pass NULL to call this new function. All other callers and has_sha1_pack() lose the ignore_packed parameter. Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index 91b5487478..c095e8dd2b 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -61,7 +61,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, hex[40] = 0; if (get_sha1_hex(hex, sha1)) die("internal error"); - if (has_sha1_pack(sha1, NULL)) + if (has_sha1_pack(sha1)) (*packed_loose)++; } } -- cgit v1.2.3 From 377829201783b8a648e07af6ce7d747e0f45dc19 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Sat, 23 May 2009 11:53:12 -0700 Subject: parse-opts: prepare for OPT_FILENAME To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd Signed-off-by: Junio C Hamano --- builtin-count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-count-objects.c') diff --git a/builtin-count-objects.c b/builtin-count-objects.c index b814fe5070..1b0b6c84ea 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -83,7 +83,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) OPT_END(), }; - argc = parse_options(argc, argv, opts, count_objects_usage, 0); + argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0); /* we do not take arguments other than flags for now */ if (argc) usage_with_options(count_objects_usage, opts); -- cgit v1.2.3