show: use streaming API for showing blobs
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 7, 2012 at 17:54 UTC
74775a09b166fb85f5dce816548e337f11124c6b
2 files changed
+21
-15
builtin/log.c
+20
-14
@@ -20,6 +20,7 @@
20
#include "string-list.h"
21
#include "parse-options.h"
22
#include "branch.h"
23
+#include "streaming.h"
24
25
/* Set a default date-time format for git log ("log.date" config variable) */
26
static const char *default_date_mode = NULL;
@@ -381,8 +382,13 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
382
strbuf_release(&out);
383
}
384
384
-static int show_object(const unsigned char *sha1, int show_tag_object,
385
- struct rev_info *rev)
385
+static int show_blob_object(const unsigned char *sha1, struct rev_info *rev)
386
+{
387
+ fflush(stdout);
388
+ return stream_blob_to_fd(1, sha1, NULL, 0);
389
+}
390
+
391
+static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
392
{
393
unsigned long size;
394
enum object_type type;
@@ -392,16 +398,16 @@ static int show_object(const unsigned char *sha1, int show_tag_object,
398
if (!buf)
399
return error(_("Could not read object %s"), sha1_to_hex(sha1));
400
395
- if (show_tag_object)
396
- while (offset < size && buf[offset] != '\n') {
397
- int new_offset = offset + 1;
398
- while (new_offset < size && buf[new_offset++] != '\n')
399
- ; /* do nothing */
400
- if (!prefixcmp(buf + offset, "tagger "))
401
- show_tagger(buf + offset + 7,
402
- new_offset - offset - 7, rev);
403
- offset = new_offset;
404
- }
401
+ assert(type == OBJ_TAG);
402
+ while (offset < size && buf[offset] != '\n') {
403
+ int new_offset = offset + 1;
404
+ while (new_offset < size && buf[new_offset++] != '\n')
405
+ ; /* do nothing */
406
+ if (!prefixcmp(buf + offset, "tagger "))
407
+ show_tagger(buf + offset + 7,
408
+ new_offset - offset - 7, rev);
409
+ offset = new_offset;
410
+ }
411
412
if (offset < size)
413
fwrite(buf + offset, size - offset, 1, stdout);
@@ -459,7 +465,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
465
const char *name = objects[i].name;
466
switch (o->type) {
467
case OBJ_BLOB:
462
- ret = show_object(o->sha1, 0, NULL);
468
+ ret = show_blob_object(o->sha1, NULL);
469
break;
470
case OBJ_TAG: {
471
struct tag *t = (struct tag *)o;
@@ -470,7 +476,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
476
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
477
t->tag,
478
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
473
- ret = show_object(o->sha1, 1, &rev);
479
+ ret = show_tag_object(o->sha1, &rev);
480
rev.shown_one = 1;
481
if (ret)
482
break;
t/t1050-large.sh
+1
-1
@@ -125,7 +125,7 @@ test_expect_success 'cat-file a large file from a tag' '
125
git cat-file blob largefiletag >/dev/null
126
'
127
128
-test_expect_failure 'git-show a large file' '
128
+test_expect_success 'git-show a large file' '
129
git show :large1 >/dev/null
130
131
'