Skip to content

Commit a33fb40

Browse files
committed
Merge branch 'jm/mailmap' into maint
* jm/mailmap: t4203: do not let "git shortlog" DWIM based on tty t4203 (mailmap): stop hardcoding commit ids and dates mailmap: fix use of freed memory
2 parents 0f024af + 3e3e1ef commit a33fb40

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

mailmap.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ static void add_mapping(struct string_list *map,
7979
if (old_name == NULL) {
8080
debug_mm("mailmap: adding (simple) entry for %s at index %d\n", old_email, index);
8181
/* Replace current name and new email for simple entry */
82-
free(me->name);
83-
free(me->email);
84-
if (new_name)
82+
if (new_name) {
83+
free(me->name);
8584
me->name = xstrdup(new_name);
86-
if (new_email)
85+
}
86+
if (new_email) {
87+
free(me->email);
8788
me->email = xstrdup(new_email);
89+
}
8890
} else {
8991
struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));
9092
debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index);

t/t4203-mailmap.sh

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ test_description='.mailmap configurations'
44

55
. ./test-lib.sh
66

7+
fuzz_blame () {
8+
sed "
9+
s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g
10+
s/$_x05[0-9a-f][0-9a-f]/OBJI/g
11+
s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
12+
" "$@"
13+
}
14+
715
test_expect_success setup '
816
echo one >one &&
917
git add one &&
1018
test_tick &&
1119
git commit -m initial &&
1220
echo two >>one &&
1321
git add one &&
22+
test_tick &&
1423
git commit --author "nick1 <bugs@company.xx>" -m second
1524
'
1625

@@ -54,7 +63,7 @@ Repo Guy (1):
5463
5564
EOF
5665
test_expect_success 'mailmap.file set' '
57-
mkdir internal_mailmap &&
66+
mkdir -p internal_mailmap &&
5867
echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
5968
git config mailmap.file internal_mailmap/.mailmap &&
6069
git shortlog HEAD >actual &&
@@ -92,6 +101,40 @@ test_expect_success 'mailmap.file non-existant' '
92101
test_cmp expect actual
93102
'
94103

104+
cat >expect <<\EOF
105+
Internal Guy (1):
106+
second
107+
108+
Repo Guy (1):
109+
initial
110+
111+
EOF
112+
113+
test_expect_success 'name entry after email entry' '
114+
mkdir -p internal_mailmap &&
115+
echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
116+
echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
117+
git shortlog HEAD >actual &&
118+
test_cmp expect actual
119+
'
120+
121+
cat >expect <<\EOF
122+
Internal Guy (1):
123+
second
124+
125+
Repo Guy (1):
126+
initial
127+
128+
EOF
129+
130+
test_expect_success 'name entry after email entry, case-insensitive' '
131+
mkdir -p internal_mailmap &&
132+
echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
133+
echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
134+
git shortlog HEAD >actual &&
135+
test_cmp expect actual
136+
'
137+
95138
cat >expect <<\EOF
96139
A U Thor (1):
97140
initial
@@ -101,7 +144,7 @@ nick1 (1):
101144
102145
EOF
103146
test_expect_success 'No mailmap files, but configured' '
104-
rm .mailmap &&
147+
rm -f .mailmap internal_mailmap/.mailmap &&
105148
git shortlog HEAD >actual &&
106149
test_cmp expect actual
107150
'
@@ -153,7 +196,7 @@ test_expect_success 'Shortlog output (complex mapping)' '
153196
test_tick &&
154197
git commit --author "CTO <cto@coompany.xx>" -m seventh &&
155198
156-
mkdir internal_mailmap &&
199+
mkdir -p internal_mailmap &&
157200
echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
158201
echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
159202
echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
@@ -198,18 +241,18 @@ test_expect_success 'Log output (complex mapping)' '
198241

199242
# git blame
200243
cat >expect <<\EOF
201-
^3a2fdcb (A U Thor 2005-04-07 15:13:13 -0700 1) one
202-
7de6f99b (Some Dude 2005-04-07 15:13:13 -0700 2) two
203-
5815879d (Other Author 2005-04-07 15:14:13 -0700 3) three
204-
ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four
205-
5ab6d4fa (Santa Claus 2005-04-07 15:16:13 -0700 5) five
206-
38a42d8b (Santa Claus 2005-04-07 15:17:13 -0700 6) six
207-
8ddc0386 (CTO 2005-04-07 15:18:13 -0700 7) seven
244+
^OBJI (A U Thor DATE 1) one
245+
OBJID (Some Dude DATE 2) two
246+
OBJID (Other Author DATE 3) three
247+
OBJID (Other Author DATE 4) four
248+
OBJID (Santa Claus DATE 5) five
249+
OBJID (Santa Claus DATE 6) six
250+
OBJID (CTO DATE 7) seven
208251
EOF
209-
210252
test_expect_success 'Blame output (complex mapping)' '
211253
git blame one >actual &&
212-
test_cmp expect actual
254+
fuzz_blame actual >actual.fuzz &&
255+
test_cmp expect actual.fuzz
213256
'
214257

215258
test_done

0 commit comments

Comments
 (0)