Retire info/rev-cache
It was one of those things that were well intentioned but did not turn out to be useful in practice. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 14, 2005 at 13:08 UTC
0f56479d7325083953be36b8c8ee90380ff27f92
12 files changed
+4
-558
.gitignore
-2
@@ -6,7 +6,6 @@ git-applypatch
6
git-archimport
7
git-bisect
8
git-branch
9
-git-build-rev-cache
9
git-cat-file
10
git-checkout
11
git-checkout-index
@@ -78,7 +77,6 @@ git-sh-setup
77
git-shortlog
78
git-show-branch
79
git-show-index
81
-git-show-rev-cache
80
git-ssh-fetch
81
git-ssh-upload
82
git-status
Documentation/git-build-rev-cache.txt
deleted
-38
@@ -1,38 +0,0 @@
1
-git-build-rev-cache(1)
2
-======================
3
-
4
-NAME
5
-----
6
-git-build-rev-cache - Create or update a rev-cache file.
7
-
8
-SYNOPSIS
9
---------
10
-'git-build-rev-cache' [-v] <rev-cache-file> < list-of-heads
11
-
12
-DESCRIPTION
13
------------
14
-Creates or updates a file that describes the commit ancestry reachable
15
-from the list-of-head read from stdin. This file is in an append-only
16
-binary format to make the server side friendly to rsync mirroring
17
-scheme, and can be read by the git-show-rev-cache command.
18
-
19
-OPTIONS
20
--------
21
--v::
22
- Verbose.
23
-
24
-<rev-cache-file>::
25
- The rev-cache to operate on.
26
-
27
-Author
28
-------
29
-Written by Junio C Hamano <junkio@cox.net>
30
-
31
-Documentation
32
---------------
33
-Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
34
-
35
-GIT
36
----
37
-Part of the link:git.html[git] suite
38
-
Documentation/git-show-rev-cache.txt
deleted
-37
@@ -1,37 +0,0 @@
1
-git-show-rev-cache(1)
2
-=====================
3
-
4
-NAME
5
-----
6
-git-show-rev-cache - Show the contents of a rev-cache file.
7
-
8
-SYNOPSIS
9
---------
10
-'git-show-rev-cache' <rev-cache-file>
11
-
12
-DESCRIPTION
13
------------
14
-Show the contents of <rev-cache-file>.
15
-
16
-A rev-cache file describes the commit ancestry reachable from references
17
-supplied as input to get-build-rev-cache. This file is in an
18
-append-only binary format to make the server side friendly to rsync
19
-mirroring scheme.
20
-
21
-OPTIONS
22
--------
23
-<rev-cache-file>::
24
- Rev-cache file to display.
25
-
26
-Author
27
-------
28
-Written by Junio C Hamano <junkio@cox.net>
29
-
30
-Documentation
31
---------------
32
-Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
33
-
34
-GIT
35
----
36
-Part of the link:git.html[git] suite
37
-
Documentation/git-update-server-info.txt
-2
@@ -38,8 +38,6 @@ of what they are for:
38
39
* info/refs
40
41
-* info/rev-cache
42
-
41
42
BUGS
43
----
Documentation/git.txt
-6
@@ -359,9 +359,6 @@ link:git-tag.html[git-tag]::
359
360
Interrogators:
361
362
-link:git-build-rev-cache.html[git-build-rev-cache]::
363
- Create or update a rev-cache file.
364
-
362
link:git-cherry.html[git-cherry]::
363
Find commits not merged upstream.
364
@@ -402,9 +399,6 @@ link:git-send-email.html[git-send-email]::
399
Send patch e-mails out of "format-patch --mbox" output.
400
Previously this command was known as git-send-email-script.
401
405
-link:git-show-rev-cache.html[git-show-rev-cache]::
406
- Show the contents of a rev-cache file.
407
-
402
link:git-stripspace.html[git-stripspace]::
403
Filter out empty lines.
404
Documentation/repository-layout.txt
-7
@@ -117,13 +117,6 @@ info/grafts::
117
listing their 40-byte hexadecimal object names separated
118
by a space and terminated by a newline.
119
120
-info/rev-cache::
121
- No higher-level tool currently takes advantage of this
122
- file, but it is generated when `git update-server-info`
123
- is run. It records the commit ancestry information of
124
- the commits in this repository in a concise binary
125
- format, and can be read with `git-show-rev-cache`.
126
-
120
info/exclude::
121
This file, by convention among Porcelains, stores the
122
exclude pattern list. `git status` looks at it, but
Makefile
+4
-4
@@ -92,7 +92,7 @@ SIMPLE_PROGRAMS = \
92
93
# ... and all the rest
94
PROGRAMS = \
95
- git-apply git-build-rev-cache git-cat-file \
95
+ git-apply git-cat-file \
96
git-checkout-index git-clone-pack git-commit-tree \
97
git-convert-objects git-diff-files \
98
git-diff-helper git-diff-index git-diff-stages \
@@ -103,7 +103,7 @@ PROGRAMS = \
103
git-peek-remote git-prune-packed git-read-tree \
104
git-receive-pack git-rev-list git-rev-parse \
105
git-rev-tree git-send-pack git-show-branch \
106
- git-show-index git-show-rev-cache git-ssh-fetch \
106
+ git-show-index git-ssh-fetch \
107
git-ssh-upload git-tar-tree git-unpack-file \
108
git-unpack-objects git-update-index git-update-server-info \
109
git-upload-pack git-verify-pack git-write-tree \
@@ -125,7 +125,7 @@ LIB_FILE=libgit.a
125
LIB_H = \
126
blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
127
diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \
128
- rev-cache.h run-command.h strbuf.h tag.h tree.h
128
+ run-command.h strbuf.h tag.h tree.h
129
130
DIFF_OBJS = \
131
diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
@@ -135,7 +135,7 @@ LIB_OBJS = \
135
blob.o commit.o connect.o count-delta.o csum-file.o \
136
date.o diff-delta.o entry.o ident.o index.o \
137
object.o pack-check.o patch-delta.o path.o pkt-line.o \
138
- quote.o read-cache.o refs.o rev-cache.o run-command.o \
138
+ quote.o read-cache.o refs.o run-command.o \
139
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
140
tag.o tree.o usage.o $(DIFF_OBJS)
141
build-rev-cache.c
deleted
-56
@@ -1,56 +0,0 @@
1
-#include "refs.h"
2
-#include "cache.h"
3
-#include "commit.h"
4
-#include "rev-cache.h"
5
-
6
-static void process_head_list(int verbose)
7
-{
8
- char buf[512];
9
-
10
- while (fgets(buf, sizeof(buf), stdin)) {
11
- unsigned char sha1[20];
12
- struct commit *commit;
13
-
14
- if (get_sha1_hex(buf, sha1)) {
15
- error("ignoring: %s", buf);
16
- continue;
17
- }
18
- if (!(commit = lookup_commit_reference(sha1))) {
19
- error("not a commit: %s", sha1_to_hex(sha1));
20
- continue;
21
- }
22
- record_rev_cache(commit->object.sha1, verbose ? stderr : NULL);
23
- }
24
-}
25
-
26
-
27
-static const char *build_rev_cache_usage =
28
-"git-build-rev-cache <rev-cache-file> < list-of-heads";
29
-
30
-int main(int ac, char **av)
31
-{
32
- int verbose = 0;
33
- const char *path;
34
-
35
- while (1 < ac && av[1][0] == '-') {
36
- if (!strcmp(av[1], "-v"))
37
- verbose = 1;
38
- else
39
- usage(build_rev_cache_usage);
40
- ac--; av++;
41
- }
42
-
43
- if (ac != 2)
44
- usage(build_rev_cache_usage);
45
-
46
- path = av[1];
47
-
48
- /* read existing rev-cache */
49
- read_rev_cache(path, NULL, 0);
50
-
51
- process_head_list(verbose);
52
-
53
- /* update the rev-cache database by appending newly found one to it */
54
- write_rev_cache(path, path);
55
- return 0;
56
-}
rev-cache.c
deleted
-318
@@ -1,318 +0,0 @@
1
-#include "refs.h"
2
-#include "cache.h"
3
-#include "rev-cache.h"
4
-
5
-struct rev_cache **rev_cache;
6
-int nr_revs, alloc_revs;
7
-
8
-static struct rev_list_elem *rle_free;
9
-
10
-#define BATCH_SIZE 512
11
-
12
-int find_rev_cache(const unsigned char *sha1)
13
-{
14
- int lo = 0, hi = nr_revs;
15
- while (lo < hi) {
16
- int mi = (lo + hi) / 2;
17
- struct rev_cache *ri = rev_cache[mi];
18
- int cmp = memcmp(sha1, ri->sha1, 20);
19
- if (!cmp)
20
- return mi;
21
- if (cmp < 0)
22
- hi = mi;
23
- else
24
- lo = mi + 1;
25
- }
26
- return -lo - 1;
27
-}
28
-
29
-static struct rev_list_elem *alloc_list_elem(void)
30
-{
31
- struct rev_list_elem *rle;
32
- if (!rle_free) {
33
- int i;
34
-
35
- rle = xmalloc(sizeof(*rle) * BATCH_SIZE);
36
- for (i = 0; i < BATCH_SIZE - 1; i++) {
37
- rle[i].ri = NULL;
38
- rle[i].next = &rle[i + 1];
39
- }
40
- rle[BATCH_SIZE - 1].ri = NULL;
41
- rle[BATCH_SIZE - 1].next = NULL;
42
- rle_free = rle;
43
- }
44
- rle = rle_free;
45
- rle_free = rle->next;
46
- return rle;
47
-}
48
-
49
-static struct rev_cache *create_rev_cache(const unsigned char *sha1)
50
-{
51
- struct rev_cache *ri;
52
- int pos = find_rev_cache(sha1);
53
-
54
- if (0 <= pos)
55
- return rev_cache[pos];
56
- pos = -pos - 1;
57
- if (alloc_revs <= ++nr_revs) {
58
- alloc_revs = alloc_nr(alloc_revs);
59
- rev_cache = xrealloc(rev_cache, sizeof(ri) * alloc_revs);
60
- }
61
- if (pos < nr_revs)
62
- memmove(rev_cache + pos + 1, rev_cache + pos,
63
- (nr_revs - pos - 1) * sizeof(ri));
64
- ri = xcalloc(1, sizeof(*ri));
65
- memcpy(ri->sha1, sha1, 20);
66
- rev_cache[pos] = ri;
67
- return ri;
68
-}
69
-
70
-static unsigned char last_sha1[20];
71
-
72
-static void write_one_rev_cache(FILE *rev_cache_file, struct rev_cache *ri)
73
-{
74
- unsigned char flag;
75
- struct rev_list_elem *rle;
76
-
77
- if (ri->written)
78
- return;
79
-
80
- if (ri->parsed) {
81
- /* We use last_sha1 compression only for the first parent;
82
- * otherwise the resulting rev-cache would lose the parent
83
- * order information.
84
- */
85
- if (ri->parents &&
86
- !memcmp(ri->parents->ri->sha1, last_sha1, 20))
87
- flag = (ri->num_parents - 1) | 0x80;
88
- else
89
- flag = ri->num_parents;
90
-
91
- fwrite(ri->sha1, 20, 1, rev_cache_file);
92
- fwrite(&flag, 1, 1, rev_cache_file);
93
- for (rle = ri->parents; rle; rle = rle->next) {
94
- if (flag & 0x80 && rle == ri->parents)
95
- continue;
96
- fwrite(rle->ri->sha1, 20, 1, rev_cache_file);
97
- }
98
- memcpy(last_sha1, ri->sha1, 20);
99
- ri->written = 1;
100
- }
101
- /* recursively write children depth first */
102
- for (rle = ri->children; rle; rle = rle->next)
103
- write_one_rev_cache(rev_cache_file, rle->ri);
104
-}
105
-
106
-void write_rev_cache(const char *newpath, const char *oldpath)
107
-{
108
- /* write the following commit ancestry information in
109
- * $GIT_DIR/info/rev-cache.
110
- *
111
- * The format is:
112
- * 20-byte SHA1 (commit ID)
113
- * 1-byte flag:
114
- * - bit 0-6 records "number of parent commit SHA1s to
115
- * follow" (i.e. up to 127 children can be listed).
116
- * - when the bit 7 is on, then "the entry immediately
117
- * before this entry is one of the parents of this
118
- * commit".
119
- * N x 20-byte SHA1 (parent commit IDs)
120
- */
121
- FILE *rev_cache_file;
122
- int i;
123
- struct rev_cache *ri;
124
-
125
- if (!strcmp(newpath, oldpath)) {
126
- /* If we are doing it in place */
127
- rev_cache_file = fopen(newpath, "a");
128
- }
129
- else {
130
- char buf[8096];
131
- size_t sz;
132
- FILE *oldfp = fopen(oldpath, "r");
133
- rev_cache_file = fopen(newpath, "w");
134
- if (oldfp) {
135
- while (1) {
136
- sz = fread(buf, 1, sizeof(buf), oldfp);
137
- if (sz == 0)
138
- break;
139
- fwrite(buf, 1, sz, rev_cache_file);
140
- }
141
- fclose(oldfp);
142
- }
143
- }
144
-
145
- memset(last_sha1, 0, 20);
146
-
147
- /* Go through available rev_cache structures, starting from
148
- * parentless ones first, so that we would get most out of
149
- * last_sha1 optimization by the depth first behaviour of
150
- * write_one_rev_cache().
151
- */
152
- for (i = 0; i < nr_revs; i++) {
153
- ri = rev_cache[i];
154
- if (ri->num_parents)
155
- continue;
156
- write_one_rev_cache(rev_cache_file, ri);
157
- }
158
- /* Then the rest */
159
- for (i = 0; i < nr_revs; i++) {
160
- ri = rev_cache[i];
161
- write_one_rev_cache(rev_cache_file, ri);
162
- }
163
- fclose(rev_cache_file);
164
-}
165
-
166
-static void add_parent(struct rev_cache *child,
167
- const unsigned char *parent_sha1)
168
-{
169
- struct rev_cache *parent = create_rev_cache(parent_sha1);
170
- struct rev_list_elem *e = alloc_list_elem();
171
-
172
- /* Keep the parent list ordered in the same way the commit
173
- * object records them.
174
- */
175
- e->ri = parent;
176
- e->next = NULL;
177
- if (!child->parents_tail)
178
- child->parents = e;
179
- else
180
- child->parents_tail->next = e;
181
- child->parents_tail = e;
182
- child->num_parents++;
183
-
184
- /* There is no inherent order of the children so we just
185
- * LIFO them together.
186
- */
187
- e = alloc_list_elem();
188
- e->next = parent->children;
189
- parent->children = e;
190
- e->ri = child;
191
- parent->num_children++;
192
-}
193
-
194
-int read_rev_cache(const char *path, FILE *dumpfile, int dry_run)
195
-{
196
- unsigned char *map;
197
- int fd;
198
- struct stat st;
199
- unsigned long ofs, len;
200
- struct rev_cache *ri = NULL;
201
-
202
- fd = open(path, O_RDONLY);
203
- if (fd < 0) {
204
- if (dry_run)
205
- return error("cannot open %s", path);
206
- if (errno == ENOENT)
207
- return 0;
208
- return -1;
209
- }
210
- if (fstat(fd, &st)) {
211
- close(fd);
212
- return -1;
213
- }
214
- map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
215
- close(fd);
216
- if (map == MAP_FAILED)
217
- return -1;
218
-
219
- memset(last_sha1, 0, 20);
220
- ofs = 0;
221
- len = st.st_size;
222
- while (ofs < len) {
223
- unsigned char sha1[20];
224
- int flag, cnt, i;
225
- if (len < ofs + 21)
226
- die("rev-cache too short");
227
- memcpy(sha1, map + ofs, 20);
228
- flag = map[ofs + 20];
229
- ofs += 21;
230
- cnt = (flag & 0x7f) + ((flag & 0x80) != 0);
231
- if (len < ofs + (flag & 0x7f) * 20)
232
- die("rev-cache too short to have %d more parents",
233
- (flag & 0x7f));
234
- if (dumpfile)
235
- fprintf(dumpfile, "%s", sha1_to_hex(sha1));
236
- if (!dry_run) {
237
- ri = create_rev_cache(sha1);
238
- if (!ri)
239
- die("cannot create rev-cache for %s",
240
- sha1_to_hex(sha1));
241
- ri->written = ri->parsed = 1;
242
- }
243
- i = 0;
244
- if (flag & 0x80) {
245
- if (!dry_run)
246
- add_parent(ri, last_sha1);
247
- if (dumpfile)
248
- fprintf(dumpfile, " %s",
249
- sha1_to_hex(last_sha1));
250
- i++;
251
- }
252
- while (i++ < cnt) {
253
- if (!dry_run)
254
- add_parent(ri, map + ofs);
255
- if (dumpfile)
256
- fprintf(dumpfile, " %s",
257
- sha1_to_hex(last_sha1));
258
- ofs += 20;
259
- }
260
- if (dumpfile)
261
- fprintf(dumpfile, "\n");
262
- memcpy(last_sha1, sha1, 20);
263
- }
264
- if (ofs != len)
265
- die("rev-cache truncated?");
266
- munmap(map, len);
267
- return 0;
268
-}
269
-
270
-int record_rev_cache(const unsigned char *sha1, FILE *dumpfile)
271
-{
272
- unsigned char parent[20];
273
- char type[20];
274
- unsigned long size, ofs;
275
- unsigned int cnt, i;
276
- void *buf;
277
- struct rev_cache *ri;
278
-
279
- buf = read_sha1_file(sha1, type, &size);
280
- if (!buf)
281
- return error("%s: not found", sha1_to_hex(sha1));
282
- if (strcmp(type, "commit")) {
283
- free(buf);
284
- return error("%s: not a commit but a %s",
285
- sha1_to_hex(sha1), type);
286
- }
287
- ri = create_rev_cache(sha1);
288
- if (ri->parsed)
289
- return 0;
290
- if (dumpfile)
291
- fprintf(dumpfile, "commit %s\n", sha1_to_hex(sha1));
292
-
293
- cnt = 0;
294
- ofs = 46; /* "tree " + hex-sha1 + "\n" */
295
- while (!memcmp(buf + ofs, "parent ", 7) &&
296
- !get_sha1_hex(buf + ofs + 7, parent)) {
297
- ofs += 48;
298
- cnt++;
299
- }
300
- if (cnt * 48 + 46 != ofs) {
301
- free(buf);
302
- die("internal error in record_rev_cache");
303
- }
304
-
305
- ri = create_rev_cache(sha1);
306
- ri->parsed = 1;
307
-
308
- for (i = 0; i < cnt; i++) {
309
- unsigned char parent_sha1[20];
310
-
311
- ofs = 46 + i * 48 + 7;
312
- get_sha1_hex(buf + ofs, parent_sha1);
313
- add_parent(ri, parent_sha1);
314
- record_rev_cache(parent_sha1, dumpfile);
315
- }
316
- free(buf);
317
- return 0;
318
-}
rev-cache.h
deleted
-29
@@ -1,29 +0,0 @@
1
-#ifndef REV_CACHE_H
2
-#define REV_CACHE_H
3
-
4
-extern struct rev_cache {
5
- struct rev_cache *head_list;
6
- struct rev_list_elem *children;
7
- struct rev_list_elem *parents;
8
- struct rev_list_elem *parents_tail;
9
- unsigned short num_parents;
10
- unsigned short num_children;
11
- unsigned int written : 1;
12
- unsigned int parsed : 1;
13
- unsigned int work : 30;
14
- void *work_ptr;
15
- unsigned char sha1[20];
16
-} **rev_cache;
17
-extern int nr_revs, alloc_revs;
18
-
19
-struct rev_list_elem {
20
- struct rev_list_elem *next;
21
- struct rev_cache *ri;
22
-};
23
-
24
-extern int find_rev_cache(const unsigned char *);
25
-extern int read_rev_cache(const char *, FILE *, int);
26
-extern int record_rev_cache(const unsigned char *, FILE *);
27
-extern void write_rev_cache(const char *new, const char *old);
28
-
29
-#endif
server-info.c
-41
@@ -3,7 +3,6 @@
3
#include "object.h"
4
#include "commit.h"
5
#include "tag.h"
6
-#include "rev-cache.h"
6
7
/* refs */
8
static FILE *info_ref_fp;
@@ -516,45 +515,6 @@ static int update_info_packs(int force)
515
return 0;
516
}
517
519
-/* rev-cache */
520
-static int record_rev_cache_ref(const char *path, const unsigned char *sha1)
521
-{
522
- struct object *obj = parse_object(sha1);
523
-
524
- if (!obj)
525
- return error("ref %s has bad sha %s", path, sha1_to_hex(sha1));
526
- while (obj && obj->type == tag_type)
527
- obj = parse_object(((struct tag *)obj)->tagged->sha1);
528
- if (!obj || obj->type != commit_type)
529
- /* tag pointing at a non-commit */
530
- return 0;
531
- return record_rev_cache(obj->sha1, NULL);
532
-}
533
-
534
-static int update_info_revs(int force)
535
-{
536
- char *path0 = strdup(git_path("info/rev-cache"));
537
- int len = strlen(path0);
538
- char *path1 = xmalloc(len + 2);
539
-
540
- strcpy(path1, path0);
541
- strcpy(path1 + len, "+");
542
-
543
- /* read existing rev-cache */
544
- if (!force)
545
- read_rev_cache(path0, NULL, 0);
546
- safe_create_leading_directories(path0);
547
-
548
- for_each_ref(record_rev_cache_ref);
549
-
550
- /* update the rev-cache database */
551
- write_rev_cache(path1, force ? "/dev/null" : path0);
552
- rename(path1, path0);
553
- free(path1);
554
- free(path0);
555
- return 0;
556
-}
557
-
518
/* public */
519
int update_server_info(int force)
520
{
@@ -566,7 +526,6 @@ int update_server_info(int force)
526
527
errs = errs | update_info_refs(force);
528
errs = errs | update_info_packs(force);
569
- errs = errs | update_info_revs(force);
529
530
return errs;
531
}
show-rev-cache.c
deleted
-18
@@ -1,18 +0,0 @@
1
-#include "cache.h"
2
-#include "rev-cache.h"
3
-
4
-static char *show_rev_cache_usage =
5
-"git-show-rev-cache <rev-cache-file>";
6
-
7
-int main(int ac, char **av)
8
-{
9
- while (1 < ac && av[0][1] == '-') {
10
- /* do flags here */
11
- break;
12
- ac--; av++;
13
- }
14
- if (ac != 2)
15
- usage(show_rev_cache_usage);
16
-
17
- return read_rev_cache(av[1], stdout, 1);
18
-}