2 * Builtin "git log" and related commands (show, whatchanged)
4 * (C) Copyright 2006 Linus Torvalds
14 static int cmd_log_wc(int argc
, const char **argv
, char **envp
,
17 struct commit
*commit
;
19 rev
->abbrev
= DEFAULT_ABBREV
;
20 rev
->commit_format
= CMIT_FMT_DEFAULT
;
21 rev
->verbose_header
= 1;
22 argc
= setup_revisions(argc
, argv
, rev
, "HEAD");
25 die("unrecognized argument: %s", argv
[1]);
27 prepare_revision_walk(rev
);
29 while ((commit
= get_revision(rev
)) != NULL
) {
30 log_tree_commit(rev
, commit
);
32 commit
->buffer
= NULL
;
37 int cmd_whatchanged(int argc
, const char **argv
, char **envp
)
43 rev
.diffopt
.recursive
= 1;
44 return cmd_log_wc(argc
, argv
, envp
, &rev
);
47 int cmd_show(int argc
, const char **argv
, char **envp
)
53 rev
.diffopt
.recursive
= 1;
54 rev
.combine_merges
= 1;
55 rev
.dense_combined_merges
= 1;
56 rev
.always_show_header
= 1;
57 rev
.ignore_merges
= 0;
59 return cmd_log_wc(argc
, argv
, envp
, &rev
);
62 int cmd_log(int argc
, const char **argv
, char **envp
)
67 rev
.always_show_header
= 1;
68 rev
.diffopt
.recursive
= 1;
69 return cmd_log_wc(argc
, argv
, envp
, &rev
);
72 static int istitlechar(char c
)
74 return (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z') ||
75 (c
>= '0' && c
<= '9') || c
== '.' || c
== '_';
78 static void reopen_stdout(struct commit
*commit
, int nr
)
85 sprintf(filename
, "%04d", nr
);
86 len
= strlen(filename
);
88 sol
= strstr(commit
->buffer
, "\n\n");
93 /* strip [PATCH] or [PATCH blabla] */
94 if (!strncmp(sol
, "[PATCH", 6)) {
95 char *eos
= strchr(sol
+ 6, ']');
103 for (j
= 0; len
< 1024 - 6 && sol
[j
] && sol
[j
] != '\n'; j
++) {
104 if (istitlechar(sol
[j
])) {
106 filename
[len
++] = '-';
109 filename
[len
++] = sol
[j
];
111 while (sol
[j
+ 1] == '.')
116 while (filename
[len
- 1] == '.' || filename
[len
- 1] == '-')
119 strcpy(filename
+ len
, ".txt");
120 fprintf(stderr
, "%s\n", filename
);
121 freopen(filename
, "w", stdout
);
124 int cmd_format_patch(int argc
, const char **argv
, char **envp
)
126 struct commit
*commit
;
127 struct commit
**list
= NULL
;
132 init_revisions(&rev
);
133 rev
.commit_format
= CMIT_FMT_EMAIL
;
134 rev
.verbose_header
= 1;
136 rev
.diffopt
.with_raw
= 0;
137 rev
.diffopt
.with_stat
= 1;
138 rev
.combine_merges
= 0;
139 rev
.ignore_merges
= 1;
140 rev
.diffopt
.output_format
= DIFF_FORMAT_PATCH
;
141 argc
= setup_revisions(argc
, argv
, &rev
, "HEAD");
144 if (!strcmp(argv
[1], "--stdout"))
147 die ("unrecognized argument: %s", argv
[1]);
152 prepare_revision_walk(&rev
);
153 while ((commit
= get_revision(&rev
)) != NULL
) {
155 if (commit
->parents
&& commit
->parents
->next
)
158 list
= realloc(list
, nr
* sizeof(list
[0]));
159 list
[nr
- 1] = commit
;
166 reopen_stdout(commit
, total
- nr
);
167 shown
= log_tree_commit(&rev
, commit
);
168 free(commit
->buffer
);
169 commit
->buffer
= NULL
;
171 printf("-- \n%s\n\n", git_version_string
);