Skip to content

Commit

Permalink
[PATCH] Add update-server-info.
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Junio C Hamano authored and Linus Torvalds committed Jul 24, 2005
1 parent 0fec082 commit 8f3f9b0
Show file tree
Hide file tree
Showing 9 changed files with 1,025 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -50,7 +50,8 @@ PROG= git-update-cache git-diff-files git-init-db git-write-tree \
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)

Expand All @@ -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

Expand All @@ -76,6 +80,7 @@ LIB_OBJS += diff.o diffcore-rename.o diffcore-pickaxe.o diffcore-pathspec.o \
count-delta.o diffcore-break.o diffcore-order.o

LIB_OBJS += gitenv.o
LIB_OBJS += server-info.o

LIBS = $(LIB_FILE)
LIBS += -lz
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions build-rev-cache.c
@@ -0,0 +1,56 @@
#include "refs.h"
#include "cache.h"
#include "commit.h"
#include "rev-cache.h"

static void process_head_list(int verbose)
{
char buf[512];

while (fgets(buf, sizeof(buf), stdin)) {
unsigned char sha1[20];
struct commit *commit;

if (get_sha1_hex(buf, sha1)) {
error("ignoring: %s", buf);
continue;
}
if (!(commit = lookup_commit_reference(sha1))) {
error("not a commit: %s", sha1_to_hex(sha1));
continue;
}
record_rev_cache(commit->object.sha1, verbose ? stderr : NULL);
}
}


static const char *build_rev_cache_usage =
"git-build-rev-cache <rev-cache-file> < list-of-heads";

int main(int ac, char **av)
{
int verbose = 0;
const char *path;

while (1 < ac && av[1][0] == '-') {
if (!strcmp(av[1], "-v"))
verbose = 1;
else
usage(build_rev_cache_usage);
ac--; av++;
}

if (ac != 2)
usage(build_rev_cache_usage);

path = av[1];

/* read existing rev-cache */
read_rev_cache(path, NULL, 0);

process_head_list(verbose);

/* update the rev-cache database by appending newly found one to it */
write_rev_cache(path, path);
return 0;
}
3 changes: 3 additions & 0 deletions cache.h
Expand Up @@ -308,4 +308,7 @@ extern int find_pack_entry_one(const unsigned char *, struct pack_entry *, struc
extern 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 */
1 change: 1 addition & 0 deletions receive-pack.c
Expand Up @@ -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)
Expand Down

0 comments on commit 8f3f9b0

Please sign in to comment.