Skip to content

Commit 445cac1

Browse files
committed
Merge branch 'maint'
* maint: tutorial: gentler illustration of Alice/Bob workflow using gitk pretty=format: respect date format options make git-shell paranoid about closed stdin/stdout/stderr Document gitk --argscmd flag. Fix '--dirstat' with cross-directory renaming for-each-ref: Allow a trailing slash in the patterns
2 parents e990501 + 53d1589 commit 445cac1

File tree

11 files changed

+80
-12
lines changed

11 files changed

+80
-12
lines changed

Documentation/gitk.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ frequently used options.
4949
the history between two branches (i.e. the HEAD and the MERGE_HEAD)
5050
that modify the conflicted files.
5151

52+
--argscmd=<command>::
53+
Command to be run each time gitk has to determine the list of
54+
<revs> to show. The command is expected to print on its standard
55+
output a list of additional revs to be shown, one per line.
56+
Use this instead of explicitly specifying <revs> if the set of
57+
commits to show may vary between refreshes.
58+
5259
<revs>::
5360

5461
Limit the revisions to show. This can be either a single revision

Documentation/gittutorial.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,37 @@ pulling, like this:
321321

322322
------------------------------------------------
323323
alice$ git fetch /home/bob/myrepo master
324-
alice$ git log -p ..FETCH_HEAD
324+
alice$ git log -p HEAD..FETCH_HEAD
325325
------------------------------------------------
326326

327327
This operation is safe even if Alice has uncommitted local changes.
328+
The range notation HEAD..FETCH_HEAD" means "show everything that is reachable
329+
from the FETCH_HEAD but exclude anything that is reachable from HEAD.
330+
Alice already knows everything that leads to her current state (HEAD),
331+
and reviewing what Bob has in his state (FETCH_HEAD) that she has not
332+
seen with this command
333+
334+
If Alice wants to visualize what Bob did since their histories forked
335+
she can issue the following command:
336+
337+
------------------------------------------------
338+
$ gitk HEAD..FETCH_HEAD
339+
------------------------------------------------
340+
341+
This uses the same two-dot range notation we saw earlier with 'git log'.
342+
343+
Alice may want to view what both of them did since they forked.
344+
She can use three-dot form instead of the two-dot form:
345+
346+
------------------------------------------------
347+
$ gitk HEAD...FETCH_HEAD
348+
------------------------------------------------
349+
350+
This means "show everything that is reachable from either one, but
351+
exclude anything that is reachable from both of them".
352+
353+
Please note that these range notation can be used with both gitk
354+
and "git log".
328355

329356
After inspecting what Bob did, if there is nothing urgent, Alice may
330357
decide to continue working without pulling from Bob. If Bob's history

Documentation/pretty-formats.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The placeholders are:
103103
- '%an': author name
104104
- '%aN': author name (respecting .mailmap)
105105
- '%ae': author email
106-
- '%ad': author date
106+
- '%ad': author date (format respects --date= option)
107107
- '%aD': author date, RFC2822 style
108108
- '%ar': author date, relative
109109
- '%at': author date, UNIX timestamp

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void format_subst(const struct commit *commit,
4848
strbuf_add(&fmt, b + 8, c - b - 8);
4949

5050
strbuf_add(buf, src, b - src);
51-
format_commit_message(commit, fmt.buf, buf);
51+
format_commit_message(commit, fmt.buf, buf, DATE_NORMAL);
5252
len -= c + 1 - src;
5353
src = c + 1;
5454
}

builtin-commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
882882

883883
if (!log_tree_commit(&rev, commit)) {
884884
struct strbuf buf = STRBUF_INIT;
885-
format_commit_message(commit, "%h: %s", &buf);
885+
format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL);
886886
printf("%s\n", buf.buf);
887887
strbuf_release(&buf);
888888
}

builtin-for-each-ref.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
652652
if ((plen <= namelen) &&
653653
!strncmp(refname, p, plen) &&
654654
(refname[plen] == '\0' ||
655-
refname[plen] == '/'))
655+
refname[plen] == '/' ||
656+
p[plen-1] == '/'))
656657
break;
657658
if (!fnmatch(p, refname, FNM_PATHNAME))
658659
break;

commit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ extern int non_ascii(int);
6767
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
6868
extern void get_commit_format(const char *arg, struct rev_info *);
6969
extern void format_commit_message(const struct commit *commit,
70-
const void *format, struct strbuf *sb);
70+
const void *format, struct strbuf *sb,
71+
enum date_mode dmode);
7172
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
7273
struct strbuf *,
7374
int abbrev, const char *subject,

diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,13 @@ static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long ch
10601060
return this_dir;
10611061
}
10621062

1063+
static int dirstat_compare(const void *_a, const void *_b)
1064+
{
1065+
const struct dirstat_file *a = _a;
1066+
const struct dirstat_file *b = _b;
1067+
return strcmp(a->name, b->name);
1068+
}
1069+
10631070
static void show_dirstat(struct diff_options *options)
10641071
{
10651072
int i;
@@ -1119,6 +1126,7 @@ static void show_dirstat(struct diff_options *options)
11191126
return;
11201127

11211128
/* Show all directories with more than x% of the changes */
1129+
qsort(dir.files, dir.nr, sizeof(dir.files[0]), dirstat_compare);
11221130
gather_dirstat(options->file, &dir, changed, "", 0);
11231131
}
11241132

pretty.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static int mailmap_name(struct strbuf *sb, const char *email)
310310
}
311311

312312
static size_t format_person_part(struct strbuf *sb, char part,
313-
const char *msg, int len)
313+
const char *msg, int len, enum date_mode dmode)
314314
{
315315
/* currently all placeholders have same length */
316316
const int placeholder_len = 2;
@@ -377,7 +377,7 @@ static size_t format_person_part(struct strbuf *sb, char part,
377377

378378
switch (part) {
379379
case 'd': /* date */
380-
strbuf_addstr(sb, show_date(date, tz, DATE_NORMAL));
380+
strbuf_addstr(sb, show_date(date, tz, dmode));
381381
return placeholder_len;
382382
case 'D': /* date, RFC2822 style */
383383
strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822));
@@ -409,6 +409,7 @@ struct chunk {
409409

410410
struct format_commit_context {
411411
const struct commit *commit;
412+
enum date_mode dmode;
412413

413414
/* These offsets are relative to the start of the commit message. */
414415
int commit_header_parsed;
@@ -584,10 +585,12 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
584585
return 1;
585586
case 'a': /* author ... */
586587
return format_person_part(sb, placeholder[1],
587-
msg + c->author.off, c->author.len);
588+
msg + c->author.off, c->author.len,
589+
c->dmode);
588590
case 'c': /* committer ... */
589591
return format_person_part(sb, placeholder[1],
590-
msg + c->committer.off, c->committer.len);
592+
msg + c->committer.off, c->committer.len,
593+
c->dmode);
591594
case 'e': /* encoding */
592595
strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
593596
return 1;
@@ -599,12 +602,14 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
599602
}
600603

601604
void format_commit_message(const struct commit *commit,
602-
const void *format, struct strbuf *sb)
605+
const void *format, struct strbuf *sb,
606+
enum date_mode dmode)
603607
{
604608
struct format_commit_context context;
605609

606610
memset(&context, 0, sizeof(context));
607611
context.commit = commit;
612+
context.dmode = dmode;
608613
strbuf_expand(sb, format, format_commit_item, &context);
609614
}
610615

@@ -770,7 +775,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
770775
const char *encoding;
771776

772777
if (fmt == CMIT_FMT_USERFORMAT) {
773-
format_commit_message(commit, user_format, sb);
778+
format_commit_message(commit, user_format, sb, dmode);
774779
return;
775780
}
776781

shell.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ int main(int argc, char **argv)
4848
{
4949
char *prog;
5050
struct commands *cmd;
51+
int devnull_fd;
52+
53+
/*
54+
* Always open file descriptors 0/1/2 to avoid clobbering files
55+
* in die(). It also avoids not messing up when the pipes are
56+
* dup'ed onto stdin/stdout/stderr in the child processes we spawn.
57+
*/
58+
devnull_fd = open("/dev/null", O_RDWR);
59+
while (devnull_fd >= 0 && devnull_fd <= 2)
60+
devnull_fd = dup(devnull_fd);
61+
if (devnull_fd == -1)
62+
die("opening /dev/null failed (%s)", strerror(errno));
63+
close (devnull_fd);
5164

5265
/*
5366
* Special hack to pretend to be a CVS server

0 commit comments

Comments
 (0)