# [RFC/PATCH] git-show: also handle blobs

2 messages from 2006-12-03 to 2006-12-03. Participants: Johannes Schindelin, Jakub Narebski.
Thread: https://gitlist.dev/t/43531

## Johannes Schindelin, 2006-12-03 18:54

Subject: [RFC/PATCH] git-show: also handle blobs
Message-ID: <Pine.LNX.4.63.0612031952050.28348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612031952050.28348%40wbgn013.biozentrum.uni-wuerzburg.de

```

Now you can say "git show v1.4.4.1:Makefile" and it pipes the requested 
contents into your favourite pager.

While at it, the manpage for -show is updated; it no longer pipes 
anything, but rather uses the internal revision walking machinery. Better 
not mention it at all.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---

	This combines the "wouldn't it be nice to have git-cat or
	git-less" wishes with "we do not want to clutter up the
	namespace any more.

	If people like this approach, we could easily enhance this patch 
	to be a synonym for "-p cat-file -p" for _every_ non-commit on the 
	command line.

 Documentation/git-show.txt |   11 +++++------
 builtin-log.c              |   12 ++++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index 4c880a8..9d4e93e 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -3,7 +3,7 @@ git-show(1)
 
 NAME
 ----
-git-show - Show one commit with difference it introduces
+git-show - Show one blob or one commit with difference it introduces
 
 
 SYNOPSIS
@@ -12,11 +12,10 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-Shows commit log and textual diff for a single commit.  The
-command internally invokes 'git-rev-list' piped to
-'git-diff-tree', and takes command line options for both of
-these commands. It also presents the merge commit in a special
-format as produced by 'git-diff-tree --cc'.
+Shows a commit or blob. In case of a commit it shows the
+log message and textual diff for a single commit. It also
+presents the merge commit in a special format as produced by
+'git-diff-tree --cc'.
 
 This manual page describes only the most frequently used options.
 
diff --git a/builtin-log.c b/builtin-log.c
index 7acf5d3..c252c40 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -85,6 +85,18 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 	rev.ignore_merges = 0;
 	rev.no_walk = 1;
 	cmd_log_init(argc, argv, prefix, &rev);
+	if (rev.pending.nr == 1
+			&& rev.pending.objects[0].item->type == OBJ_BLOB) {
+		unsigned long size;
+		char type[20];
+		void *buf = read_sha1_file(rev.pending.objects[0].item->sha1,
+				type, &size);
+		if (!buf)
+			return error("Could not read blob?");
+		fwrite(buf, size, 1, stdout);
+		free(buf);
+		return 0;
+	}
 	return cmd_log_walk(&rev);
 }
 
-- 
1.4.4.1.g317bd

```

## Jakub Narebski, 2006-12-03 19:03

Subject: Re: [RFC/PATCH] git-show: also handle blobs
Message-ID: <ekv721$5el$1@sea.gmane.org>
URL: https://gitlist.dev/e/ekv721%245el%241%40sea.gmane.org
In-Reply-To: <Pine.LNX.4.63.0612031952050.28348@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin wrote:

>  
>  DESCRIPTION
>  -----------
> -Shows commit log and textual diff for a single commit.  The
> -command internally invokes 'git-rev-list' piped to
> -'git-diff-tree', and takes command line options for both of
> -these commands. It also presents the merge commit in a special
> -format as produced by 'git-diff-tree --cc'.
> +Shows a commit or blob. In case of a commit it shows the
> +log message and textual diff for a single commit. It also
> +presents the merge commit in a special format as produced by
> +'git-diff-tree --cc'.
>  
>  This manual page describes only the most frequently used options.
>  

This loses the information that you can use all the options
of git-diff-tree and all the options of git-rev-list in git-show.

But I agre that technical information should not be in DESCRIPTION
section of manpage... perhaps later, if it is needed.
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```
