@matheusbsbs / matheus-bagliano / commits / 70b006b971
Fork 0

Tie it all together: "git log"

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>

Linus Torvalds committed Feb 28, 2006 at 11:30 UTC 70b006b9712b57741ec1320b15aef2f8b1d6a905
2 files changed +25 -1
Makefile
+1 -1
@@ -450,7 +450,7 @@ strip: $(PROGRAMS) git$X
450
451 git$X: git.c $(LIB_FILE)
452 $(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
453 - $(CFLAGS) $(COMPAT_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE)
453 + $(ALL_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE) $(LIBS)
454
455 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
456 rm -f $@
git.c
+24
@@ -12,6 +12,10 @@
12 #include "git-compat-util.h"
13 #include "exec_cmd.h"
14
15 +#include "cache.h"
16 +#include "commit.h"
17 +#include "revision.h"
18 +
19 #ifndef PATH_MAX
20 # define PATH_MAX 4096
21 #endif
@@ -245,6 +249,25 @@ static int cmd_help(int argc, char **argv, char **envp)
249 return 0;
250 }
251
252 +#define LOGSIZE (65536)
253 +
254 +static int cmd_log(int argc, char **argv, char **envp)
255 +{
256 + struct rev_info rev;
257 + struct commit *commit;
258 + char *buf = xmalloc(LOGSIZE);
259 +
260 + argc = setup_revisions(argc, argv, &rev, "HEAD");
261 + prepare_revision_walk(&rev);
262 + setup_pager();
263 + while ((commit = get_revision(&rev)) != NULL) {
264 + pretty_print_commit(CMIT_FMT_DEFAULT, commit, ~0, buf, LOGSIZE, 18);
265 + printf("%s\n", buf);
266 + }
267 + free(buf);
268 + return 0;
269 +}
270 +
271 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
272
273 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)
279 } commands[] = {
280 { "version", cmd_version },
281 { "help", cmd_help },
282 + { "log", cmd_log },
283 };
284 int i;
285