Tie it all together: "git log"
authorLinus Torvalds <torvalds@osdl.org>
Tue, 28 Feb 2006 19:30:19 +0000 (11:30 -0800)
committerJunio C Hamano <junkio@cox.net>
Tue, 28 Feb 2006 22:49:34 +0000 (14:49 -0800)
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile
git.c

index 0b1a9988b45944ece4769e4ac5de47e51dad69c5..ead13bec0dc49415397b34f937cdc7e4ccf222a9 100644 (file)
--- 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 993cd0d4904be11edb6234e47d10376733928740..b0da6b19457cf06f8e880bd0b18f270da94069b1 100644 (file)
--- a/git.c
+++ b/git.c
 #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 **argv, char **envp)
        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 argc, char **argv, char **envp)
        } commands[] = {
                { "version", cmd_version },
                { "help", cmd_help },
+               { "log", cmd_log },
        };
        int i;