Skip to content

Commit 70b006b

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f67b45f commit 70b006b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ strip: $(PROGRAMS) git$X
450450

451451
git$X: git.c $(LIB_FILE)
452452
$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
453-
$(CFLAGS) $(COMPAT_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE)
453+
$(ALL_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE) $(LIBS)
454454

455455
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
456456
rm -f $@

git.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "git-compat-util.h"
1313
#include "exec_cmd.h"
1414

15+
#include "cache.h"
16+
#include "commit.h"
17+
#include "revision.h"
18+
1519
#ifndef PATH_MAX
1620
# define PATH_MAX 4096
1721
#endif
@@ -245,6 +249,25 @@ static int cmd_help(int argc, char **argv, char **envp)
245249
return 0;
246250
}
247251

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+
248271
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
249272

250273
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)
256279
} commands[] = {
257280
{ "version", cmd_version },
258281
{ "help", cmd_help },
282+
{ "log", cmd_log },
259283
};
260284
int i;
261285

0 commit comments

Comments
 (0)