* [PATCH] Extend cat-file to take multiple arguments or read input from stdin.
@ 2007-11-15 4:22 Han-Wen Nienhuys
2007-11-15 4:34 ` Johannes Schindelin
0 siblings, 1 reply; 5+ messages in thread
From: Han-Wen Nienhuys @ 2007-11-15 4:22 UTC (permalink / raw)
To: git
With this patch, cat-file can be invoked either on an arbitrary number
of objects, eg.
git cat-file commit HEAD HEAD^^^
the object names can also be supplied on stdin, like so
echo -e 'HEAD\nHEAD^^^' | git cat-file commit -
With this functionality, the entire object database can be dumped with
a limited number of processes: two cat-file processes for discovering size and
type, and one cat-file process per type.
Signed-off-by: Han-Wen Nienhuys <hanwen@xs4all.nl>
---
builtin-cat-file.c | 63 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index f132d58..57e2111 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -76,31 +76,17 @@ static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long
write_or_die(1, cp, endp - cp);
}
-int cmd_cat_file(int argc, const char **argv, const char *prefix)
+
+int cat_one_file (const char *obj_name, int opt, const char *exp_type)
{
unsigned char sha1[20];
- enum object_type type;
void *buf;
unsigned long size;
- int opt;
- const char *exp_type, *obj_name;
-
- git_config(git_default_config);
- if (argc != 3)
- usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
- exp_type = argv[1];
- obj_name = argv[2];
+ enum object_type type;
if (get_sha1(obj_name, sha1))
die("Not a valid object name %s", obj_name);
- opt = 0;
- if ( exp_type[0] == '-' ) {
- opt = exp_type[1];
- if ( !opt || exp_type[2] )
- opt = -1; /* Not a single character option */
- }
-
buf = NULL;
switch (opt) {
case 't':
@@ -157,3 +143,46 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
write_or_die(1, buf, size);
return 0;
}
+
+int cmd_cat_file(int argc, const char **argv, const char *prefix)
+{
+ int opt = 0;
+ const char *exp_type;
+ int all_exists = 1;
+ struct strbuf buf;
+
+ git_config(git_default_config);
+ if (argc < 3)
+ usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1> ... ");
+ exp_type = argv[1];
+
+ if ( exp_type[0] == '-' ) {
+ opt = exp_type[1];
+ if ( !opt || exp_type[2] )
+ opt = -1; /* Not a single character option */
+ }
+
+ argv += 2;
+ strbuf_init(&buf, 0);
+ do {
+ const char *arg = NULL;
+ if (argv[0] == NULL)
+ break;
+ if (strcmp(argv[0], "-")) {
+ arg = *argv;
+ argv++;
+ } else {
+ if (strbuf_getline(&buf, stdin, '\n') == EOF)
+ break;
+ arg = buf.buf;
+ }
+ int not_exists_one = cat_one_file(arg, opt, exp_type);
+ if (opt == 'e')
+ all_exists = all_exists && !not_exists_one;
+ if (not_exists_one)
+ break;
+ } while (1);
+ strbuf_release(&buf);
+ return !all_exists;
+}
+
--
1.5.3.4
--
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.
2007-11-15 4:22 [PATCH] Extend cat-file to take multiple arguments or read input from stdin Han-Wen Nienhuys
@ 2007-11-15 4:34 ` Johannes Schindelin
2007-11-15 4:41 ` Han-Wen Nienhuys
0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2007-11-15 4:34 UTC (permalink / raw)
To: Han-Wen Nienhuys; +Cc: git
Hi,
On Thu, 15 Nov 2007, Han-Wen Nienhuys wrote:
> With this functionality, the entire object database can be dumped with a
> limited number of processes: two cat-file processes for discovering size
> and type, and one cat-file process per type.
IMHO a better idea would be a counterpart to fast-import, probably called
"fast-export". You'd need only one process then, and it would not only be
faster, but would be usable by even more people, I guess.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.
2007-11-15 4:34 ` Johannes Schindelin
@ 2007-11-15 4:41 ` Han-Wen Nienhuys
2007-11-15 6:09 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Han-Wen Nienhuys @ 2007-11-15 4:41 UTC (permalink / raw)
To: git
Johannes Schindelin escreveu:
> Hi,
>
> On Thu, 15 Nov 2007, Han-Wen Nienhuys wrote:
>
>> With this functionality, the entire object database can be dumped with a
>> limited number of processes: two cat-file processes for discovering size
>> and type, and one cat-file process per type.
>
> IMHO a better idea would be a counterpart to fast-import, probably called
> "fast-export". You'd need only one process then, and it would not only be
> faster, but would be usable by even more people, I guess.
I know, and that's what I was thinking. However, I was hoping someone else
would pick up the hint :-)
I suppose fast-export would just be cat-file with a different name and
slightly saner interface. How about
type <sha1> <newline>
size <sha1> <newline>
dump <type> <sha1> <newline>
?
--
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-11-15 13:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-15 4:22 [PATCH] Extend cat-file to take multiple arguments or read input from stdin Han-Wen Nienhuys
2007-11-15 4:34 ` Johannes Schindelin
2007-11-15 4:41 ` Han-Wen Nienhuys
2007-11-15 6:09 ` Junio C Hamano
2007-11-15 13:33 ` Han-Wen Nienhuys
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).