# [PATCH] Add git-pack-ls-objects tool

3 messages from 2006-01-22 to 2006-01-22. Participants: Petr Baudis, Junio C Hamano.
Thread: https://gitlist.dev/t/3124

## Petr Baudis, 2006-01-22 02:27

Subject: [PATCH] Add git-pack-ls-objects tool
Message-ID: <20060122022711.16333.93404.stgit@machine.or.cz>
URL: https://gitlist.dev/e/20060122022711.16333.93404.stgit%40machine.or.cz

```
This tool takes pack index on stdin and produces the list of indexed
objects on stdout.

Very simple, but I've been always somewhat nervous that I cannot list
all (even unreferenced) objects in a repository, and in a given pack in
particular. The immediate use will be in the git-count-objects script,
but I can imagine it being useful also in various troubleshooting
situations.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---

 Documentation/git-pack-ls-objects.txt |   32 ++++++++++++++++++++++++++++++++
 Makefile                              |    2 +-
 pack-ls-objects.c                     |   31 +++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-pack-ls-objects.txt b/Documentation/git-pack-ls-objects.txt
new file mode 100644
index 0000000..bf2a4a4
--- /dev/null
+++ b/Documentation/git-pack-ls-objects.txt
@@ -0,0 +1,32 @@
+git-pack-ls-objects(1)
+======================
+
+NAME
+----
+git-pack-ls-objects - List objects in a pack based on its index
+
+
+SYNOPSIS
+--------
+'git-pack-ls-objects' < pack-index
+
+
+DESCRIPTION
+-----------
+Reads a packed archive index (.idx) from its standard input and
+produces the list of indexed objects (that is, the objects packed
+in the corresponding .pack file) on its standard output.
+
+
+Author
+------
+Written by Petr Baudis <pasky@suse.cz>
+
+Documentation
+-------------
+Documentation by Petr Baudis
+
+GIT
+---
+Part of the gitlink:git[7] suite
+
diff --git a/Makefile b/Makefile
index a291bb1..7c54507 100644
--- a/Makefile
+++ b/Makefile
@@ -143,7 +143,7 @@ PROGRAMS = \
 	git-upload-pack$X git-verify-pack$X git-write-tree$X \
 	git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \
 	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
-	git-describe$X
+	git-describe$X git-pack-ls-objects$X
 
 # what 'all' will build and 'install' will install, in gitexecdir
 ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
diff --git a/pack-ls-objects.c b/pack-ls-objects.c
new file mode 100644
index 0000000..caee59c
--- /dev/null
+++ b/pack-ls-objects.c
@@ -0,0 +1,31 @@
+/*
+ * GIT - The information manager from hell
+ *
+ * Copyright (C) Petr Baudis, 2006
+ */
+
+#include <stdio.h>
+#include "cache.h"
+
+static const char pack_usage[] = "git-pack-ls-objects < pack-idx";
+
+int main(int argc, char **argv)
+{
+	unsigned char buf[1024];
+	unsigned char entry[24];
+
+	if (argc > 1)
+		usage(pack_usage);
+
+	/* We are doing these charades because we do not want to print
+	 * the last sha1. */
+
+	if (!fread(buf, 256 * 4, 1, stdin) || !fread(entry, 24, 1, stdin))
+		die("invalid pack index");
+
+	while (fread(buf, 24, 1, stdin)) {
+		printf("%s\n", sha1_to_hex(entry + 4));
+		memcpy(entry, buf, 24);
+	}
+	return 0;
+}

```

## Junio C Hamano, 2006-01-22 02:46

Subject: Re: [PATCH] Add git-pack-ls-objects tool
Message-ID: <7vzmlphtct.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzmlphtct.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060122022711.16333.93404.stgit@machine.or.cz>

```
Petr Baudis <pasky@suse.cz> writes:

> This tool takes pack index on stdin and produces the list of indexed
> objects on stdout.

Isn't this essentially what git-show-index does?

```

## Petr Baudis, 2006-01-22 03:00

Subject: Re: [PATCH] Add git-pack-ls-objects tool
Message-ID: <20060122030042.GS28365@pasky.or.cz>
URL: https://gitlist.dev/e/20060122030042.GS28365%40pasky.or.cz
In-Reply-To: <7vzmlphtct.fsf@assigned-by-dhcp.cox.net>

```
Dear diary, on Sun, Jan 22, 2006 at 03:46:58AM CET, I got a letter
where Junio C Hamano <junkio@cox.net> said that...
> Petr Baudis <pasky@suse.cz> writes:
> 
> > This tool takes pack index on stdin and produces the list of indexed
> > objects on stdout.
> 
> Isn't this essentially what git-show-index does?

Yes, I just had no idea this existed. ;)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Of the 3 great composers Mozart tells us what it's like to be human,
Beethoven tells us what it's like to be Beethoven and Bach tells us
what it's like to be the universe.  -- Douglas Adams

```
