Skip to content

Commit 74775a0

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 090ea12 commit 74775a0

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

builtin/log.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "string-list.h"
2121
#include "parse-options.h"
2222
#include "branch.h"
23+
#include "streaming.h"
2324

2425
/* Set a default date-time format for git log ("log.date" config variable) */
2526
static const char *default_date_mode = NULL;
@@ -381,8 +382,13 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
381382
strbuf_release(&out);
382383
}
383384

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)
386392
{
387393
unsigned long size;
388394
enum object_type type;
@@ -392,16 +398,16 @@ static int show_object(const unsigned char *sha1, int show_tag_object,
392398
if (!buf)
393399
return error(_("Could not read object %s"), sha1_to_hex(sha1));
394400

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+
}
405411

406412
if (offset < size)
407413
fwrite(buf + offset, size - offset, 1, stdout);
@@ -459,7 +465,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
459465
const char *name = objects[i].name;
460466
switch (o->type) {
461467
case OBJ_BLOB:
462-
ret = show_object(o->sha1, 0, NULL);
468+
ret = show_blob_object(o->sha1, NULL);
463469
break;
464470
case OBJ_TAG: {
465471
struct tag *t = (struct tag *)o;
@@ -470,7 +476,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
470476
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
471477
t->tag,
472478
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
473-
ret = show_object(o->sha1, 1, &rev);
479+
ret = show_tag_object(o->sha1, &rev);
474480
rev.shown_one = 1;
475481
if (ret)
476482
break;

t/t1050-large.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test_expect_success 'cat-file a large file from a tag' '
125125
git cat-file blob largefiletag >/dev/null
126126
'
127127

128-
test_expect_failure 'git-show a large file' '
128+
test_expect_success 'git-show a large file' '
129129
git show :large1 >/dev/null
130130
131131
'

0 commit comments

Comments
 (0)