shortlog: default to HEAD when the standard input is a tty
Instead of warning the user that it is expecting git log output from the standard input (and waiting for the user to type the log from the keyboard, which is a silly thing to do), default to traverse from HEAD when there is no rev parameter given and the standard input is a tty. This factors out a useful helper "add_head()" from builtin-diff.c to a more appropriate place revision.c while renaming it to more descriptive name add_head_to_pending(), as that is what the function is about. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 11, 2007 at 10:09 UTC
3384a2dfc12f0fecd25ecfd6bfa9ee0d82517bf2
5 files changed
+19
-19
builtin-diff.c
+1
-13
@@ -176,18 +176,6 @@ static int builtin_diff_combined(struct rev_info *revs,
176
return 0;
177
}
178
179
-void add_head(struct rev_info *revs)
180
-{
181
- unsigned char sha1[20];
182
- struct object *obj;
183
- if (get_sha1("HEAD", sha1))
184
- return;
185
- obj = parse_object(sha1);
186
- if (!obj)
187
- return;
188
- add_pending_object(revs, obj, "HEAD");
189
-}
190
-
179
static void refresh_index_quietly(void)
180
{
181
struct lock_file *lock_file;
@@ -272,7 +260,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
260
if (!strcmp(arg, "--"))
261
break;
262
else if (!strcmp(arg, "--cached")) {
275
- add_head(&rev);
263
+ add_head_to_pending(&rev);
264
if (!rev.pending.nr)
265
die("No HEAD commit to compare with (yet)");
266
break;
builtin-log.c
+1
-4
@@ -18,9 +18,6 @@
18
static int default_show_root = 1;
19
static const char *fmt_patch_subject_prefix = "PATCH";
20
21
-/* this is in builtin-diff.c */
22
-void add_head(struct rev_info *revs);
23
-
21
static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
22
{
23
int plen = strlen(prefix);
@@ -746,7 +743,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
743
* does not have.
744
*/
745
rev.pending.objects[0].item->flags |= UNINTERESTING;
749
- add_head(&rev);
746
+ add_head_to_pending(&rev);
747
}
748
/*
749
* Otherwise, it is "format-patch -22 HEAD", and/or
builtin-shortlog.c
+3
-2
@@ -249,9 +249,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
249
250
read_mailmap(&mailmap, ".mailmap", &common_repo_prefix);
251
252
+ /* assume HEAD if from a tty */
253
+ if (!rev.pending.nr && isatty(0))
254
+ add_head_to_pending(&rev);
255
if (rev.pending.nr == 0) {
253
- if (isatty(0))
254
- fprintf(stderr, "(reading log to summarize from standard input)\n");
256
read_from_stdin(&list);
257
}
258
else
revision.c
+12
@@ -139,6 +139,18 @@ void add_pending_object(struct rev_info *revs, struct object *obj, const char *n
139
add_pending_object_with_mode(revs, obj, name, S_IFINVALID);
140
}
141
142
+void add_head_to_pending(struct rev_info *revs)
143
+{
144
+ unsigned char sha1[20];
145
+ struct object *obj;
146
+ if (get_sha1("HEAD", sha1))
147
+ return;
148
+ obj = parse_object(sha1);
149
+ if (!obj)
150
+ return;
151
+ add_pending_object(revs, obj, "HEAD");
152
+}
153
+
154
static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)
155
{
156
struct object *object;
revision.h
+2
@@ -130,6 +130,8 @@ extern void add_object(struct object *obj,
130
131
extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
132
133
+extern void add_head_to_pending(struct rev_info *);
134
+
135
enum commit_action {
136
commit_ignore,
137
commit_show,