* [PATCH] git-show: grok blobs, trees and tags, too
@ 2006-12-14 10:31 Johannes Schindelin
2006-12-14 10:37 ` Shawn Pearce
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Johannes Schindelin @ 2006-12-14 10:31 UTC (permalink / raw)
To: git, junkio
Since git-show is pure Porcelain, it is the ideal candidate to
pretty print other things than commits, too.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
Documentation/git-show.txt | 40 ++++++++++++++++++---
builtin-log.c | 82 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 114 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt
index 4c880a8..1d9d781 100644
--- a/Documentation/git-show.txt
+++ b/Documentation/git-show.txt
@@ -3,20 +3,27 @@ git-show(1)
NAME
----
-git-show - Show one commit with difference it introduces
+git-show - Show blobs, trees, tags and commits with difference they introduce
SYNOPSIS
--------
-'git-show' <option>...
+'git-show' [options] <object>...
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 one or more objects.
+
+For commits it shows the log message and textual diff. It also
+presents the merge commit in a special format as produced by
+'git-diff-tree --cc'.
+
+For tags, it shows the tag message and the referenced objects.
+
+For trees, it shows the names (equivalent to gitlink:git-ls-tree[1]
+with \--name-only).
+
+For plain blobs, it shows the plain contents.
This manual page describes only the most frequently used options.
@@ -28,6 +35,25 @@ OPTIONS
include::pretty-formats.txt[]
+
+EXAMPLES
+--------
+
+git show v1.0.0::
+ Shows the tag `v1.0.0`.
+
+git show v1.0.0^{tree}::
+ Shows the tree pointed to by the tag `v1.0.0`.
+
+git show next~10:Documentation/README
+ Shows the contents of the file `Documentation/README` as
+ they were current in the 10th last commit of the branch
+ `next`.
+
+git show master:Makefile master:t/Makefile
+ Concatenates the contents of said Makefiles in the head
+ of the branch `master`.
+
Author
------
Written by Linus Torvalds <torvalds@osdl.org> and
diff --git a/builtin-log.c b/builtin-log.c
index 6821a08..17014f7 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -10,6 +10,7 @@
#include "revision.h"
#include "log-tree.h"
#include "builtin.h"
+#include "tag.h"
#include <time.h>
#include <sys/time.h>
@@ -71,9 +72,43 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
return cmd_log_walk(&rev);
}
+static int show_object(const unsigned char *sha1, int suppress_header)
+{
+ unsigned long size;
+ char type[20];
+ char *buf = read_sha1_file(sha1, type, &size);
+ int offset = 0;
+
+ if (!buf)
+ return error("Could not read object %s", sha1_to_hex(sha1));
+
+ if (suppress_header)
+ while (offset < size && buf[offset++] != '\n') {
+ int new_offset = offset;
+ while (new_offset < size && buf[new_offset++] != '\n')
+ ; /* do nothing */
+ offset = new_offset;
+ }
+
+ if (offset < size)
+ fwrite(buf + offset, size - offset, 1, stdout);
+ free(buf);
+ return 0;
+}
+
+static int show_tree_object(const unsigned char *sha1,
+ const char *base, int baselen,
+ const char *pathname, unsigned mode, int stage)
+{
+ printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
+ return 0;
+}
+
int cmd_show(int argc, const char **argv, const char *prefix)
{
struct rev_info rev;
+ struct object_array_entry *objects;
+ int i, count, ret = 0;
git_config(git_log_config);
init_revisions(&rev, prefix);
@@ -85,7 +120,52 @@ 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);
- return cmd_log_walk(&rev);
+
+ count = rev.pending.nr;
+ objects = rev.pending.objects;
+ for (i = 0; i < count && !ret; i++) {
+ struct object *o = objects[i].item;
+ const char *name = objects[i].name;
+ switch (o->type) {
+ case OBJ_BLOB:
+ ret = show_object(o->sha1, 0);
+ break;
+ case OBJ_TAG: {
+ struct tag *t = (struct tag *)o;
+
+ printf("%stag %s%s\n\n",
+ diff_get_color(rev.diffopt.color_diff,
+ DIFF_COMMIT),
+ t->tag,
+ diff_get_color(rev.diffopt.color_diff,
+ DIFF_RESET));
+ ret = show_object(o->sha1, 1);
+ objects[i].item = (struct object *)t->tagged;
+ i--;
+ break;
+ }
+ case OBJ_TREE:
+ printf("%stree %s%s\n\n",
+ diff_get_color(rev.diffopt.color_diff,
+ DIFF_COMMIT),
+ name,
+ diff_get_color(rev.diffopt.color_diff,
+ DIFF_RESET));
+ read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
+ show_tree_object);
+ break;
+ case OBJ_COMMIT:
+ rev.pending.nr = rev.pending.alloc = 0;
+ rev.pending.objects = NULL;
+ add_object_array(o, name, &rev.pending);
+ ret = cmd_log_walk(&rev);
+ break;
+ default:
+ ret = error("Unknown type: %d", o->type);
+ }
+ }
+ free(objects);
+ return ret;
}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:31 [PATCH] git-show: grok blobs, trees and tags, too Johannes Schindelin
@ 2006-12-14 10:37 ` Shawn Pearce
2006-12-14 10:47 ` Johannes Schindelin
2006-12-14 10:50 ` Junio C Hamano
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Shawn Pearce @ 2006-12-14 10:37 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, junkio
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>..
Nice! I like this.
> +git show master:Makefile master:t/Makefile
> + Concatenates the contents of said Makefiles in the head
> + of the branch `master`.
> +
Uh, isn't that what cat does? Shouldn't this be "git cat"? :-)
Nevermind. :)
--
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:37 ` Shawn Pearce
@ 2006-12-14 10:47 ` Johannes Schindelin
0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2006-12-14 10:47 UTC (permalink / raw)
To: Shawn Pearce; +Cc: git, junkio
Hi,
On Thu, 14 Dec 2006, Shawn Pearce wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> > +git show master:Makefile master:t/Makefile
> > + Concatenates the contents of said Makefiles in the head
> > + of the branch `master`.
> > +
>
> Uh, isn't that what cat does? Shouldn't this be "git cat"? :-)
Shhh! The dogs are sleeping!
Ciao,
Dscho
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:31 [PATCH] git-show: grok blobs, trees and tags, too Johannes Schindelin
2006-12-14 10:37 ` Shawn Pearce
@ 2006-12-14 10:50 ` Junio C Hamano
2006-12-14 10:58 ` Johannes Schindelin
2006-12-15 8:50 ` Jakub Narebski
2006-12-15 9:18 ` Santi Béjar
3 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2006-12-14 10:50 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> + ret = show_object(o->sha1, 1);
> + objects[i].item = (struct object *)t->tagged;
> + i--;
> + break;
Good hack ;-).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:50 ` Junio C Hamano
@ 2006-12-14 10:58 ` Johannes Schindelin
0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2006-12-14 10:58 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi,
On Thu, 14 Dec 2006, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > + ret = show_object(o->sha1, 1);
> > + objects[i].item = (struct object *)t->tagged;
> > + i--;
> > + break;
>
> Good hack ;-).
Tail recursion ;-)
It has a nice side effect, too: the _name_ of the object is not changed,
so if you show a tag which references a tree, you will see the name of the
tag as if it were the name of the tree.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:31 [PATCH] git-show: grok blobs, trees and tags, too Johannes Schindelin
2006-12-14 10:37 ` Shawn Pearce
2006-12-14 10:50 ` Junio C Hamano
@ 2006-12-15 8:50 ` Jakub Narebski
2006-12-15 10:22 ` Johannes Schindelin
2006-12-15 9:18 ` Santi Béjar
3 siblings, 1 reply; 9+ messages in thread
From: Jakub Narebski @ 2006-12-15 8:50 UTC (permalink / raw)
To: git
Johannes Schindelin wrote:
> +For tags, it shows the tag message and the referenced objects.
[...]
> +EXAMPLES
> +--------
> +
> +git show v1.0.0::
> + Shows the tag `v1.0.0`.
This changes semantic. Before this patch "git show v1.0.0" showed
_commit_, not a tag. Well, you can get commit using "git show v1.0.0^{}"...
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-14 10:31 [PATCH] git-show: grok blobs, trees and tags, too Johannes Schindelin
` (2 preceding siblings ...)
2006-12-15 8:50 ` Jakub Narebski
@ 2006-12-15 9:18 ` Santi Béjar
2006-12-15 10:22 ` Johannes Schindelin
3 siblings, 1 reply; 9+ messages in thread
From: Santi Béjar @ 2006-12-15 9:18 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, junkio
On 12/14/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> Since git-show is pure Porcelain, it is the ideal candidate to
> pretty print other things than commits, too.
I think "git show ${tag}" should be more like "git show ${commit}",
that is, with the tagger and date information and the indent, as:
$ git show v1.4.4.2
tag v1.4.4.2
Tagger: Junio C Hamano <junkio@cox.net>
Date: ${Date}
GIT 1.4.4.2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQBFdx8+wMbZpPMRm5oRAsOXAJsGY8DIYey1TZlEXIGq5+8MNgEl1QCfQC0f
c5SmdLmAm2KPsCf+bCuoK+k=
=oDuA
-----END PGP SIGNATURE-----
commit 49ed2bc4660c7cd0592cf21cc514080574d06320
...
>
> +EXAMPLES
> +--------
> +
> +git show v1.0.0::
> + Shows the tag `v1.0.0`.
and the commit (or object) it references.
I would add:
git show v1.0.0^{}::
Shows only the commit referenced by the tag `v1.0.0`.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-15 8:50 ` Jakub Narebski
@ 2006-12-15 10:22 ` Johannes Schindelin
0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2006-12-15 10:22 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 485 bytes --]
Hi,
On Fri, 15 Dec 2006, Jakub Narebski wrote:
> Johannes Schindelin wrote:
>
> > +For tags, it shows the tag message and the referenced objects.
> [...]
> > +EXAMPLES
> > +--------
> > +
> > +git show v1.0.0::
> > + Shows the tag `v1.0.0`.
>
> This changes semantic. Before this patch "git show v1.0.0" showed
> _commit_, not a tag. Well, you can get commit using "git show
> v1.0.0^{}"...
As Santi pointed out, this also shows the commit. Not only the tag.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] git-show: grok blobs, trees and tags, too
2006-12-15 9:18 ` Santi Béjar
@ 2006-12-15 10:22 ` Johannes Schindelin
0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2006-12-15 10:22 UTC (permalink / raw)
To: Santi Béjar; +Cc: git, junkio
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1081 bytes --]
Hi,
On Fri, 15 Dec 2006, Santi Béjar wrote:
> On 12/14/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> >
> > Since git-show is pure Porcelain, it is the ideal candidate to
> > pretty print other things than commits, too.
>
> I think "git show ${tag}" should be more like "git show ${commit}",
> that is, with the tagger and date information and the indent, as:
>
> $ git show v1.4.4.2
> tag v1.4.4.2
> Tagger: Junio C Hamano <junkio@cox.net>
> Date: ${Date}
>
> GIT 1.4.4.2
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (GNU/Linux)
>
> iD8DBQBFdx8+wMbZpPMRm5oRAsOXAJsGY8DIYey1TZlEXIGq5+8MNgEl1QCfQC0f
> c5SmdLmAm2KPsCf+bCuoK+k=
> =oDuA
> -----END PGP SIGNATURE-----
> commit 49ed2bc4660c7cd0592cf21cc514080574d06320
> ...
Okay. You code it?
> > +EXAMPLES
> > +--------
> > +
> > +git show v1.0.0::
> > + Shows the tag `v1.0.0`.
>
> and the commit (or object) it references.
>
> I would add:
>
> git show v1.0.0^{}::
> Shows only the commit referenced by the tag `v1.0.0`.
Okay. You provide a patch?
Ciao,
Dscho
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-12-15 10:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-14 10:31 [PATCH] git-show: grok blobs, trees and tags, too Johannes Schindelin
2006-12-14 10:37 ` Shawn Pearce
2006-12-14 10:47 ` Johannes Schindelin
2006-12-14 10:50 ` Junio C Hamano
2006-12-14 10:58 ` Johannes Schindelin
2006-12-15 8:50 ` Jakub Narebski
2006-12-15 10:22 ` Johannes Schindelin
2006-12-15 9:18 ` Santi Béjar
2006-12-15 10:22 ` Johannes Schindelin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox