Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
git
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
8b5157e
Documentation
arm
compat
contrib
gitweb
mozilla-sha1
perl
ppc
t
templates
xdiff
.gitignore
.mailmap
COPYING
GIT-VERSION-GEN
INSTALL
Makefile
README
alloc.c
archive-tar.c
archive-zip.c
archive.h
base85.c
blob.c
blob.h
builtin-add.c
builtin-annotate.c
builtin-apply.c
builtin-archive.c
builtin-blame.c
builtin-branch.c
builtin-cat-file.c
builtin-check-ref-format.c
builtin-checkout-index.c
builtin-commit-tree.c
builtin-count-objects.c
builtin-describe.c
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-stages.c
builtin-diff-tree.c
builtin-diff.c
builtin-fmt-merge-msg.c
builtin-for-each-ref.c
builtin-grep.c
builtin-init-db.c
builtin-log.c
builtin-ls-files.c
builtin-ls-tree.c
builtin-mailinfo.c
builtin-mailsplit.c
builtin-merge-file.c
builtin-mv.c
builtin-name-rev.c
builtin-pack-objects.c
builtin-pack-refs.c
builtin-prune-packed.c
builtin-prune.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-repo-config.c
builtin-rerere.c
builtin-rev-list.c
builtin-rev-parse.c
builtin-rm.c
builtin-runstatus.c
builtin-shortlog.c
builtin-show-branch.c
builtin-show-ref.c
builtin-stripspace.c
builtin-symbolic-ref.c
builtin-tar-tree.c
builtin-unpack-objects.c
builtin-update-index.c
builtin-update-ref.c
builtin-upload-archive.c
builtin-verify-pack.c
builtin-write-tree.c
builtin.h
cache-tree.c
cache-tree.h
cache.h
check-builtins.sh
check-racy.c
color.c
color.h
combine-diff.c
commit.c
commit.h
config.c
config.mak.in
configure.ac
connect.c
convert-objects.c
copy.c
csum-file.c
csum-file.h
ctype.c
daemon.c
date.c
delta.h
diff-delta.c
diff-lib.c
diff.c
diff.h
diffcore-break.c
diffcore-delta.c
diffcore-order.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h
dir.c
dir.h
dump-cache-tree.c
entry.c
environment.c
exec_cmd.c
exec_cmd.h
fetch-pack.c
fetch.c
fetch.h
fsck-objects.c
generate-cmdlist.sh
git-add--interactive.perl
git-am.sh
git-applymbox.sh
git-applypatch.sh
git-archimport.perl
git-bisect.sh
git-checkout.sh
git-clean.sh
git-clone.sh
git-commit.sh
git-compat-util.h
git-cvsexportcommit.perl
git-cvsimport.perl
git-cvsserver.perl
git-fetch.sh
git-gc.sh
git-instaweb.sh
git-lost-found.sh
git-ls-remote.sh
git-merge-octopus.sh
git-merge-one-file.sh
git-merge-ours.sh
git-merge-resolve.sh
git-merge-stupid.sh
git-merge.sh
git-p4import.py
git-parse-remote.sh
git-pull.sh
git-quiltimport.sh
git-rebase.sh
git-relink.perl
git-remote.perl
git-repack.sh
git-request-pull.sh
git-reset.sh
git-resolve.sh
git-revert.sh
git-send-email.perl
git-sh-setup.sh
git-svn.perl
git-svnimport.perl
git-tag.sh
git-verify-tag.sh
git.c
git.spec.in
gitk
grep.c
grep.h
hash-object.c
help.c
http-fetch.c
http-push.c
http.c
http.h
ident.c
imap-send.c
index-pack.c
interpolate.c
interpolate.h
list-objects.c
list-objects.h
local-fetch.c
lockfile.c
log-tree.c
log-tree.h
merge-base.c
merge-file.c
merge-index.c
merge-recursive.c
merge-tree.c
mktag.c
mktree.c
object-refs.c
object.c
object.h
pack-check.c
pack-redundant.c
pack.h
pager.c
patch-delta.c
patch-id.c
path-list.c
path-list.h
path.c
peek-remote.c
pkt-line.c
pkt-line.h
quote.c
quote.h
reachable.c
reachable.h
read-cache.c
receive-pack.c
reflog-walk.c
reflog-walk.h
refs.c
refs.h
revision.c
revision.h
rsh.c
rsh.h
run-command.c
run-command.h
send-pack.c
server-info.c
setup.c
sha1_file.c
sha1_name.c
shallow.c
shell.c
show-index.c
sideband.c
sideband.h
ssh-fetch.c
ssh-pull.c
ssh-push.c
ssh-upload.c
strbuf.c
strbuf.h
tag.c
tag.h
tar.h
test-date.c
test-delta.c
test-sha1.c
test-sha1.sh
trace.c
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
tree.h
unpack-file.c
unpack-trees.c
unpack-trees.h
update-server-info.c
upload-pack.c
usage.c
utf8.c
utf8.h
var.c
write_or_die.c
wt-status.c
wt-status.h
xdiff-interface.c
xdiff-interface.h
Breadcrumbs
git
/
server-info.c
Blame
Blame
Latest commit
History
History
248 lines (216 loc) · 5.1 KB
Breadcrumbs
git
/
server-info.c
Top
File metadata and controls
Code
Blame
248 lines (216 loc) · 5.1 KB
Raw
#include "cache.h" #include "refs.h" #include "object.h" #include "commit.h" #include "tag.h" /* refs */ static FILE *info_ref_fp; static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) { struct object *o = parse_object(sha1); fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path); if (o->type == OBJ_TAG) { o = deref_tag(o, path, 0); if (o) fprintf(info_ref_fp, "%s %s^{}\n", sha1_to_hex(o->sha1), path); } return 0; } static int update_info_refs(int force) { char *path0 = xstrdup(git_path("info/refs")); int len = strlen(path0); char *path1 = xmalloc(len + 2); strcpy(path1, path0); strcpy(path1 + len, "+"); safe_create_leading_directories(path0); info_ref_fp = fopen(path1, "w"); if (!info_ref_fp) return error("unable to update %s", path0); for_each_ref(add_info_ref, NULL); fclose(info_ref_fp); rename(path1, path0); free(path0); free(path1); return 0; } /* packs */ static struct pack_info { struct packed_git *p; int old_num; int new_num; int nr_alloc; int nr_heads; unsigned char (*head)[20]; } **info; static int num_pack; static const char *objdir; static int objdirlen; static struct pack_info *find_pack_by_name(const char *name) { int i; for (i = 0; i < num_pack; i++) { struct packed_git *p = info[i]->p; /* skip "/pack/" after ".git/objects" */ if (!strcmp(p->pack_name + objdirlen + 6, name)) return info[i]; } return NULL; } /* Returns non-zero when we detect that the info in the * old file is useless. */ static int parse_pack_def(const char *line, int old_cnt) { struct pack_info *i = find_pack_by_name(line + 2); if (i) { i->old_num = old_cnt; return 0; } else { /* The file describes a pack that is no longer here */ return 1; } } /* Returns non-zero when we detect that the info in the * old file is useless. */ static int read_pack_info_file(const char *infofile) { FILE *fp; char line[1000]; int old_cnt = 0; fp = fopen(infofile, "r"); if (!fp) return 1; /* nonexistent is not an error. */ while (fgets(line, sizeof(line), fp)) { int len = strlen(line); if (line[len-1] == '\n') line[--len] = 0; if (!len) continue; switch (line[0]) { case 'P': /* P name */ if (parse_pack_def(line, old_cnt++)) goto out_stale; break; case 'D': /* we used to emit D but that was misguided. */ goto out_stale; break; case 'T': /* we used to emit T but nobody uses it. */ goto out_stale; break; default: error("unrecognized: %s", line); break; } } fclose(fp); return 0; out_stale: fclose(fp); return 1; } static int compare_info(const void *a_, const void *b_) { struct pack_info * const* a = a_; struct pack_info * const* b = b_; if (0 <= (*a)->old_num && 0 <= (*b)->old_num) /* Keep the order in the original */ return (*a)->old_num - (*b)->old_num; else if (0 <= (*a)->old_num) /* Only A existed in the original so B is obviously newer */ return -1; else if (0 <= (*b)->old_num) /* The other way around. */ return 1; /* then it does not matter but at least keep the comparison stable */ if ((*a)->p == (*b)->p) return 0; else if ((*a)->p < (*b)->p) return -1; else return 1; } static void init_pack_info(const char *infofile, int force) { struct packed_git *p; int stale; int i = 0; objdir = get_object_directory(); objdirlen = strlen(objdir); prepare_packed_git(); for (p = packed_git; p; p = p->next) { /* we ignore things on alternate path since they are * not available to the pullers in general. */ if (!p->pack_local) continue; i++; } num_pack = i; info = xcalloc(num_pack, sizeof(struct pack_info *)); for (i = 0, p = packed_git; p; p = p->next) { if (!p->pack_local) continue; info[i] = xcalloc(1, sizeof(struct pack_info)); info[i]->p = p; info[i]->old_num = -1; i++; } if (infofile && !force) stale = read_pack_info_file(infofile); else stale = 1; for (i = 0; i < num_pack; i++) { if (stale) { info[i]->old_num = -1; info[i]->nr_heads = 0; } } /* renumber them */ qsort(info, num_pack, sizeof(info[0]), compare_info); for (i = 0; i < num_pack; i++) info[i]->new_num = i; } static void write_pack_info_file(FILE *fp) { int i; for (i = 0; i < num_pack; i++) fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6); fputc('\n', fp); } static int update_info_packs(int force) { char infofile[PATH_MAX]; char name[PATH_MAX]; int namelen; FILE *fp; namelen = sprintf(infofile, "%s/info/packs", get_object_directory()); strcpy(name, infofile); strcpy(name + namelen, "+"); init_pack_info(infofile, force); safe_create_leading_directories(name); fp = fopen(name, "w"); if (!fp) return error("cannot open %s", name); write_pack_info_file(fp); fclose(fp); rename(name, infofile); return 0; } /* public */ int update_server_info(int force) { /* We would add more dumb-server support files later, * including index of available pack files and their * intended audiences. */ int errs = 0; errs = errs | update_info_refs(force); errs = errs | update_info_packs(force); /* remove leftover rev-cache file if there is any */ unlink(git_path("info/rev-cache")); return errs; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
You can’t perform that action at this time.