Skip to content

Commit c9a42c4

Browse files
dschogitster
authored andcommitted
bundle: allow rev-list options to exclude annotated tags
With options such as "--all --since=2.weeks.ago", annotated tags used to be included, when they should have been excluded. The reason is that we heavily abuse the revision walker to determine what needs to be included or excluded. And the revision walker does not show tags at all (and therefore never marks tags as uninteresting). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27c03aa commit c9a42c4

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

bundle.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ int list_bundle_refs(struct bundle_header *header, int argc, const char **argv)
167167
return list_refs(&header->references, argc, argv);
168168
}
169169

170+
static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
171+
{
172+
unsigned long size;
173+
enum object_type type;
174+
char *buf, *line, *lineend;
175+
unsigned long date;
176+
177+
if (revs->max_age == -1 && revs->min_age == -1)
178+
return 1;
179+
180+
buf = read_sha1_file(tag->sha1, &type, &size);
181+
if (!buf)
182+
return 1;
183+
line = memmem(buf, size, "\ntagger ", 8);
184+
if (!line++)
185+
return 1;
186+
lineend = memchr(line, buf + size - line, '\n');
187+
line = memchr(line, lineend ? lineend - line : buf + size - line, '>');
188+
if (!line++)
189+
return 1;
190+
date = strtoul(line, NULL, 10);
191+
free(buf);
192+
return (revs->max_age == -1 || revs->max_age < date) &&
193+
(revs->min_age == -1 || revs->min_age > date);
194+
}
195+
170196
int create_bundle(struct bundle_header *header, const char *path,
171197
int argc, const char **argv)
172198
{
@@ -255,6 +281,12 @@ int create_bundle(struct bundle_header *header, const char *path,
255281
flag = 0;
256282
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
257283

284+
if (e->item->type == OBJ_TAG &&
285+
!is_tag_in_date_range(e->item, &revs)) {
286+
e->item->flags |= UNINTERESTING;
287+
continue;
288+
}
289+
258290
/*
259291
* Make sure the refs we wrote out is correct; --max-count and
260292
* other limiting options could have prevented all the tips

t/t5704-bundle.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
test_description='some bundle related tests'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'setup' '
7+
8+
: > file &&
9+
git add file &&
10+
test_tick &&
11+
git commit -m initial &&
12+
test_tick &&
13+
git tag -m tag tag &&
14+
: > file2 &&
15+
git add file2 &&
16+
: > file3 &&
17+
test_tick &&
18+
git commit -m second &&
19+
git add file3 &&
20+
test_tick &&
21+
git commit -m third
22+
23+
'
24+
25+
test_expect_success 'tags can be excluded by rev-list options' '
26+
27+
git bundle create bundle --all --since=7.Apr.2005.15:16:00.-0700 &&
28+
git ls-remote bundle > output &&
29+
! grep tag output
30+
31+
'
32+
33+
test_done

0 commit comments

Comments
 (0)