git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 3/3] Tie it all together: "git log"
Date: Tue, 28 Feb 2006 11:30:19 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0602281126340.22647@g5.osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0602281115110.22647@g5.osdl.org>


This is what the previous diffs all built up to.

We can do "git log" as a trivial small helper function inside git.c, 
because the infrastructure is all there for us to use as a library.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
----

Again, this may not do exactly what the current "git log" does. That's not 
the point. The point is to introduce the fundamental functionality, so 
that people can play with this and improve on it, and fix any of my stupid 
bugs.

It should be pretty easy to change some of the other rev-list-walking 
functions to use the library interfaces too, instead of executing an 
external "git-rev-list" process. This was a perfect example of how to get 
something working, though.

		Linus

diff --git a/Makefile b/Makefile
index 0b1a998..ead13be 100644
--- a/Makefile
+++ b/Makefile
@@ -450,7 +450,7 @@ strip: $(PROGRAMS) git$X
 
 git$X: git.c $(LIB_FILE)
 	$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
-		$(CFLAGS) $(COMPAT_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE)
+		$(ALL_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE) $(LIBS)
 
 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
 	rm -f $@
diff --git a/git.c b/git.c
index 993cd0d..b0da6b1 100644
--- a/git.c
+++ b/git.c
@@ -12,6 +12,10 @@
 #include "git-compat-util.h"
 #include "exec_cmd.h"
 
+#include "cache.h"
+#include "commit.h"
+#include "revision.h"
+
 #ifndef PATH_MAX
 # define PATH_MAX 4096
 #endif
@@ -245,6 +249,25 @@ static int cmd_help(int argc, char **arg
 	return 0;
 }
 
+#define LOGSIZE (65536)
+
+static int cmd_log(int argc, char **argv, char **envp)
+{
+	struct rev_info rev;
+	struct commit *commit;
+	char *buf = xmalloc(LOGSIZE);
+
+	argc = setup_revisions(argc, argv, &rev, "HEAD");
+	prepare_revision_walk(&rev);
+	setup_pager();
+	while ((commit = get_revision(&rev)) != NULL) {
+		pretty_print_commit(CMIT_FMT_DEFAULT, commit, ~0, buf, LOGSIZE, 18);
+		printf("%s\n", buf);
+	}
+	free(buf);
+	return 0;
+}
+
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
 static void handle_internal_command(int argc, char **argv, char **envp)
@@ -256,6 +279,7 @@ static void handle_internal_command(int 
 	} commands[] = {
 		{ "version", cmd_version },
 		{ "help", cmd_help },
+		{ "log", cmd_log },
 	};
 	int i;
 

  parent reply	other threads:[~2006-02-28 19:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-28 19:19 [PATCH 0/3] git-rev-list libification effort: the next stage Linus Torvalds
2006-02-28 19:24 ` [PATCH 1/3] git-rev-list libification: rev-list walking Linus Torvalds
2006-02-28 19:26 ` [PATCH 2/3] Introduce trivial new pager.c helper infrastructure Linus Torvalds
2006-02-28 19:30 ` Linus Torvalds [this message]
2006-02-28 20:59   ` [PATCH 3/3] Tie it all together: "git log" Linus Torvalds
2006-02-28 22:22     ` Junio C Hamano
2006-02-28 23:07       ` Linus Torvalds
2006-03-01 12:24         ` [PATCH 1/2] git-log (internal): add approxidate Junio C Hamano
2006-03-01 12:24         ` [PATCH 2/2] git-log (internal): more options Junio C Hamano
2006-03-01 15:43           ` Linus Torvalds
2006-03-01 20:06             ` Junio C Hamano
2006-02-28 23:38       ` [PATCH 3/3] Tie it all together: "git log" Martin Langhoff
2006-03-01  9:02         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0602281126340.22647@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).