Add update-server-info.
PATCH 4/6 Add update-server-info.
The git-update-server-info command prepares informational files to help clients discover the contents of a repository, and pull from it via a dumb transport protocols. Currently, the following files are produced.
- The $repo/info/refs file lists the name of heads and tags available in the $repo/refs/ directory, along with their SHA1. This can be used by git-ls-remote command running on the client side.
- The $repo/info/rev-cache file describes the commit ancestry reachable from references in the $repo/refs/ directory. This file is in an append-only binary format to make the server side friendly to rsync mirroring scheme, and can be read by git-show-rev-cache command.
- The $repo/objects/info/pack file lists the name of the packs available, the interdependencies among them, and the head commits and tags contained in them. Along with the other two files, this is designed to help clients to make smart pull decisions.
The git-receive-pack command is changed to invoke it at the end, so just after a push to a public repository finishes via "git push", the server info is automatically updated.
In addition, building of the rev-cache file can be done by a standalone git-build-rev-cache command separately.
---
Makefile | 11 + build-rev-cache.c | 56 +++++ cache.h | 3 receive-pack.c | 1 rev-cache.c | 320 ++++++++++++++++++++++++++++ rev-cache.h | 29 +++ server-info.c | 565 ++++++++++++++++++++++++++++++++++++++++++++++++++ show-rev-cache.c | 18 ++ update-server-info.c | 23 ++ 9 files changed, 1025 insertions(+), 1 deletions(-) create mode 100644 build-rev-cache.c create mode 100644 rev-cache.c create mode 100644 rev-cache.h create mode 100644 server-info.c create mode 100644 show-rev-cache.c create mode 100644 update-server-info.c
895f412b3df0a9a4884db6231bb590fd1e388db7
Makefile +10 -1
@@ -50,7 +50,8 @@ PROG= git-update-cache git-diff-files git-diff-stages git-rev-parse git-patch-id git-pack-objects \ git-unpack-objects git-verify-pack git-receive-pack git-send-pack \ git-prune-packed git-fetch-pack git-upload-pack git-clone-pack \ - git-show-index git-daemon git-var git-peek-remote + git-show-index git-daemon git-var git-peek-remote \ + git-update-server-info git-show-rev-cache git-build-rev-cache all: $(PROG)
@@ -65,6 +66,9 @@ LIB_FILE=libgit.a LIB_H=cache.h object.h blob.h tree.h commit.h tag.h delta.h epoch.h csum-file.h \ pack.h pkt-line.h refs.h +LIB_H += rev-cache.h +LIB_OBJS += rev-cache.o + LIB_H += strbuf.h LIB_OBJS += strbuf.o
@@ -76,6 +80,7 @@ LIB_OBJS += diff.o diffcore-rename.o dif count-delta.o diffcore-break.o diffcore-order.o LIB_OBJS += gitenv.o +LIB_OBJS += server-info.o LIBS = $(LIB_FILE) LIBS += -lz
@@ -152,6 +157,9 @@ git-prune-packed: prune-packed.c git-fetch-pack: fetch-pack.c git-var: var.c git-peek-remote: peek-remote.c +git-update-server-info: update-server-info.c +git-build-rev-cache: build-rev-cache.c +git-show-rev-cache: show-rev-cache.c git-http-pull: LIBS += -lcurl git-rev-list: LIBS += -lssl
@@ -165,6 +173,7 @@ object.o: $(LIB_H) read-cache.o: $(LIB_H) sha1_file.o: $(LIB_H) usage.o: $(LIB_H) +rev-cache.o: $(LIB_H) strbuf.o: $(LIB_H) gitenv.o: $(LIB_H) entry.o: $(LIB_H)
build-rev-cache.c new file +56 -0
56 lines not on this page · raw message
cache.h +3 -0
@@ -308,4 +308,7 @@ extern int find_pack_entry_one(const unsextern void *unpack_entry_gently (struct pack_entry *,char *,unsigned long *);extern void packed_object_info_detail (struct pack_entry *,char *,unsigned long *,unsigned long *,int *,unsigned char *); +/* Dumb servers support */ +extern int update_server_info (int ); +#endif /* CACHE_H */
receive-pack.c +1 -0
@@ -110,6 +110,7 @@ static void execute_commands(void)update (cmd->ref_name, cmd->old_sha1, cmd->new_sha1); cmd = cmd->next; } +update_server_info (0 ); }static void read_head_info (void )
rev-cache.c new file +320 -0
320 lines not on this page · raw message
rev-cache.h new file +29 -0
@@ -0,0 +1,29 @@ +#ifndef REV_CACHE_H +#define REV_CACHE_H + +extern struct rev_cache { +struct rev_cache *head_list; +struct rev_list_elem *children; +struct rev_list_elem *parents; +struct rev_list_elem *parents_tail; +unsigned short num_parents; +unsigned short num_children; +unsigned int written :1 ; +unsigned int parsed :1 ; +unsigned int work :30 ; +void *work_ptr; +unsigned char sha1[20 ]; +} **rev_cache; +extern int nr_revs, alloc_revs; + +struct rev_list_elem { +struct rev_list_elem *next; +struct rev_cache *ri; +}; + +extern int find_rev_cache (const unsigned char *); +extern int read_rev_cache (const char *,FILE *,int ); +extern int record_rev_cache (const unsigned char *,FILE *); +extern void write_rev_cache (const char *new,const char *old); + +#endif
server-info.c new file +565 -0
565 lines not on this page · raw message
show-rev-cache.c new file +18 -0
@@ -0,0 +1,18 @@ +#include "cache.h" +#include "rev-cache.h" + +static char *show_rev_cache_usage = +"git-show-rev-cache <rev-cache-file>" ; + +int main (int ac,char **av) +{ +while (1 < ac && av[0 ][1 ] =='-' ) { +/* do flags here */ +break ; + ac--; av++; + } +if (ac !=2 ) +usage (show_rev_cache_usage); + +return read_rev_cache (av[1 ], stdout,1 ); +}
update-server-info.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "cache.h" + +static const char update_server_info_usage[] = +"git-update-server-info [--force]" ; + +int main (int ac,char **av) +{ +int i; +int force =0 ; +for (i =1 ; i < ac; i++) { +if (av[i][0 ] =='-' ) { +if (!strcmp ("--force" , av[i]) || + !strcmp ("-f" , av[i])) + force =1 ; +else +usage (update_server_info_usage); + } + } +if (i != ac) +usage (update_server_info_usage); + +return !!update_server_info (force); +}