@matheusbsbs / matheus-bagliano / commits / c9a42c4a12
Fork 0

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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 2, 2009 at 19:08 UTC c9a42c4a12cec17e858b76d6c68aa17c12c0aef1
2 files changed +65
bundle.c
+32
@@ -167,6 +167,32 @@ int list_bundle_refs(struct bundle_header *header, int argc, const char **argv)
167 return list_refs(&header->references, argc, argv);
168 }
169
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 +
196 int create_bundle(struct bundle_header *header, const char *path,
197 int argc, const char **argv)
198 {
@@ -255,6 +281,12 @@ int create_bundle(struct bundle_header *header, const char *path,
281 flag = 0;
282 display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
283
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 +
290 /*
291 * Make sure the refs we wrote out is correct; --max-count and
292 * other limiting options could have prevented all the tips
t/t5704-bundle.sh new
+33
@@ -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