From ec1fcc16af94810dd822c6da533f58fa2750f14a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 7 Oct 2005 03:42:00 -0700 Subject: Show original and resulting blob object info in diff output. This adds more cruft to diff --git header to record the blob SHA1 and the mode the patch/diff is intended to be applied against, to help the receiving end fall back on a three-way merge. The new header looks like this: diff --git a/apply.c b/apply.c index 7be5041..8366082 100644 --- a/apply.c +++ b/apply.c @@ -14,6 +14,7 @@ // files that are being modified, but doesn't apply the patch // --stat does just a diffstat, and doesn't actually apply +// --show-index-info shows the old and new index info for... ... Upon receiving such a patch, if the patch did not apply cleanly to the target tree, the recipient can try to find the matching old objects in her object database and create a temporary tree, apply the patch to that temporary tree, and attempt a 3-way merge between the patched temporary tree and the target tree using the original temporary tree as the common ancestor. The patch lifts the code to compute the hash for an on-filesystem object from update-index.c and makes it available to the diff output routine. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ec2a1610b2..514adb8f8e 100644 --- a/cache.h +++ b/cache.h @@ -165,6 +165,7 @@ extern int ce_match_stat(struct cache_entry *ce, struct stat *st); extern int ce_modified(struct cache_entry *ce, struct stat *st); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type); +extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); struct cache_file { -- cgit v1.3 From 730d48a2ef88a7fb7aa4409d40b1e6964a93267f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 8 Oct 2005 15:54:36 -0700 Subject: [PATCH] If NO_MMAP is defined, fake mmap() and munmap() Since some platforms do not support mmap() at all, and others do only just so, this patch introduces the option to fake mmap() and munmap() by malloc()ing and read()ing explicitely. Signed-off-by: Johannes Schindelin --- Makefile | 6 ++++ cache.h | 16 +++++++++ compat/mmap.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mailsplit.c | 1 - 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 compat/mmap.c (limited to 'cache.h') diff --git a/Makefile b/Makefile index 1bdf4de75d..7ca77cf2af 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,8 @@ # Define NEEDS_SOCKET if linking with libc is not enough (SunOS, # Patrick Mauritz). # +# Define NO_MMAP if you want to avoid mmap. +# # Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3. # # Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). @@ -258,6 +260,10 @@ ifdef NO_STRCASESTR DEFINES += -Dstrcasestr=gitstrcasestr LIB_OBJS += compat/strcasestr.o endif +ifdef NO_MMAP + DEFINES += -Dmmap=gitfakemmap -Dmunmap=gitfakemunmap -DNO_MMAP + LIB_OBJS += compat/mmap.o +endif ifdef NO_IPV6 DEFINES += -DNO_IPV6 -Dsockaddr_storage=sockaddr_in endif diff --git a/cache.h b/cache.h index 514adb8f8e..5987d4c125 100644 --- a/cache.h +++ b/cache.h @@ -11,7 +11,9 @@ #include #include #include +#ifndef NO_MMAP #include +#endif #include #include #include @@ -356,4 +358,18 @@ extern void packed_object_info_detail(struct pack_entry *, char *, unsigned long /* Dumb servers support */ extern int update_server_info(int); +#ifdef NO_MMAP + +#ifndef PROT_READ +#define PROT_READ 1 +#define PROT_WRITE 2 +#define MAP_PRIVATE 1 +#define MAP_FAILED ((void*)-1) +#endif + +extern void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset); +extern int gitfakemunmap(void *start, size_t length); + +#endif + #endif /* CACHE_H */ diff --git a/compat/mmap.c b/compat/mmap.c new file mode 100644 index 0000000000..fca6321ce0 --- /dev/null +++ b/compat/mmap.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include "../cache.h" + +typedef struct fakemmapwritable { + void *start; + size_t length; + int fd; + off_t offset; + struct fakemmapwritable *next; +} fakemmapwritable; + +static fakemmapwritable *writablelist = NULL; + +void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset) +{ + int n = 0; + + if(start != NULL) + die("Invalid usage of gitfakemmap."); + + if(lseek(fd, offset, SEEK_SET)<0) { + errno = EINVAL; + return MAP_FAILED; + } + + start = xmalloc(length); + if(start == NULL) { + errno = ENOMEM; + return MAP_FAILED; + } + + while(n < length) { + int count = read(fd, start+n, length-n); + + if(count == 0) { + memset(start+n, 0, length-n); + break; + } + + if(count < 0) { + free(start); + errno = EACCES; + return MAP_FAILED; + } + + n += count; + } + + if(prot & PROT_WRITE) { + fakemmapwritable *next = xmalloc(sizeof(fakemmapwritable)); + next->start = start; + next->length = length; + next->fd = dup(fd); + next->offset = offset; + next->next = writablelist; + writablelist = next; + } + + return start; +} + +int gitfakemunmap(void *start, size_t length) +{ + fakemmapwritable *writable = writablelist, *before = NULL; + + while(writable && (writable->start > start + length + || writable->start + writable->length < start)) { + before = writable; + writable = writable->next; + } + + if(writable) { + /* need to write back the contents */ + int n = 0; + + if(writable->start != start || writable->length != length) + die("fakemmap does not support partial write back."); + + if(lseek(writable->fd, writable->offset, SEEK_SET) < 0) { + free(start); + errno = EBADF; + return -1; + } + + while(n < length) { + int count = write(writable->fd, start + n, length - n); + + if(count < 0) { + errno = EINVAL; + return -1; + } + + n += count; + } + + close(writable->fd); + + if(before) + before->next = writable->next; + else + writablelist = writable->next; + + free(writable); + } + + free(start); + + return 0; +} + diff --git a/mailsplit.c b/mailsplit.c index 7981f87a72..0f8100dcca 100644 --- a/mailsplit.c +++ b/mailsplit.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include -- cgit v1.3 From 17712991a59824a8d22d5115c0c154d3122fc17b Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 10 Oct 2005 16:31:08 -0700 Subject: Add ".git/config" file parser This is a first cut at a very simple parser for a git config file. The format of the file is a simple ini-file like thing, with simple variable/value pairs. You can (and should) make the variables have a simple single-level scope, ie a valid file looks something like this: # # This is the config file, and # a '#' or ';' character indicates # a comment # ; core variables [core] ; Don't trust file modes filemode = false ; Our diff algorithm [diff] external = "/usr/local/bin/gnu-diff -u" renames = true which parses into three variables: "core.filemode" is associated with the string "false", and "diff.external" gets the appropriate quoted value. Right now we only react to one variable: "core.filemode" is a boolean that decides if we should care about the 0100 (user-execute) bit of the stat information. Even that is just a parsing demonstration - this doesn't actually implement that st_mode compare logic itself. Different programs can react to different config options, although they should always fall back to calling "git_default_config()" on any config option name that they don't recognize. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- Makefile | 2 +- cache.h | 8 +++ config.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff-files.c | 1 + diff-tree.c | 1 + read-cache.c | 1 + 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 config.c (limited to 'cache.h') diff --git a/Makefile b/Makefile index 0ca8e8d270..c31af7b3c3 100644 --- a/Makefile +++ b/Makefile @@ -158,7 +158,7 @@ LIB_OBJS = \ object.o pack-check.o patch-delta.o path.o pkt-line.o \ quote.o read-cache.o refs.o run-command.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ - tag.o tree.o usage.o $(DIFF_OBJS) + tag.o tree.o usage.o config.o $(DIFF_OBJS) LIBS = $(LIB_FILE) LIBS += -lz diff --git a/cache.h b/cache.h index 5987d4c125..0571282e8c 100644 --- a/cache.h +++ b/cache.h @@ -178,6 +178,8 @@ extern int hold_index_file_for_update(struct cache_file *, const char *path); extern int commit_index_file(struct cache_file *); extern void rollback_index_file(struct cache_file *); +extern int trust_executable_bit; + #define MTIME_CHANGED 0x0001 #define CTIME_CHANGED 0x0002 #define OWNER_CHANGED 0x0004 @@ -372,4 +374,10 @@ extern int gitfakemunmap(void *start, size_t length); #endif +typedef int (*config_fn_t)(const char *, const char *); +extern int git_default_config(const char *, const char *); +extern int git_config(config_fn_t fn); +extern int git_config_int(const char *, const char *); +extern int git_config_bool(const char *, const char *); + #endif /* CACHE_H */ diff --git a/config.c b/config.c new file mode 100644 index 0000000000..f3c4fa42ac --- /dev/null +++ b/config.c @@ -0,0 +1,222 @@ +#include + +#include "cache.h" + +#define MAXNAME (256) + +static FILE *config_file; +static int config_linenr; +static int get_next_char(void) +{ + int c; + FILE *f; + + c = '\n'; + if ((f = config_file) != NULL) { + c = fgetc(f); + if (c == '\n') + config_linenr++; + if (c == EOF) { + config_file = NULL; + c = '\n'; + } + } + return c; +} + +static char *parse_value(void) +{ + static char value[1024]; + int quote = 0, comment = 0, len = 0, space = 0; + + for (;;) { + int c = get_next_char(); + if (len >= sizeof(value)) + return NULL; + if (c == '\n') { + if (quote) + return NULL; + value[len] = 0; + return value; + } + if (comment) + continue; + if (isspace(c) && !quote) { + space = 1; + continue; + } + if (space) { + if (len) + value[len++] = ' '; + space = 0; + } + if (c == '\\') { + c = get_next_char(); + switch (c) { + case '\n': + continue; + case 't': + c = '\t'; + break; + case 'b': + c = '\b'; + break; + case 'n': + c = '\n'; + break; + return NULL; + } + value[len++] = c; + continue; + } + if (c == '"') { + quote = 1-quote; + continue; + } + if (!quote) { + if (c == ';' || c == '#') { + comment = 1; + continue; + } + } + value[len++] = c; + } +} + +static int get_value(config_fn_t fn, char *name, unsigned int len) +{ + int c; + char *value; + + /* Get the full name */ + for (;;) { + c = get_next_char(); + if (c == EOF) + break; + if (!isalnum(c)) + break; + name[len++] = tolower(c); + if (len >= MAXNAME) + return -1; + } + name[len] = 0; + while (c == ' ' || c == '\t') + c = get_next_char(); + + value = NULL; + if (c != '\n') { + if (c != '=') + return -1; + value = parse_value(); + if (!value) + return -1; + } + return fn(name, value); +} + +static int get_base_var(char *name) +{ + int baselen = 0; + + for (;;) { + int c = get_next_char(); + if (c == EOF) + return -1; + if (c == ']') + return baselen; + if (!isalnum(c)) + return -1; + if (baselen > MAXNAME / 2) + return -1; + name[baselen++] = tolower(c); + } +} + +static int git_parse_file(config_fn_t fn) +{ + int comment = 0; + int baselen = 0; + static char var[MAXNAME]; + + for (;;) { + int c = get_next_char(); + if (c == '\n') { + /* EOF? */ + if (!config_file) + return 0; + comment = 0; + continue; + } + if (comment || isspace(c)) + continue; + if (c == '#' || c == ';') { + comment = 1; + continue; + } + if (c == '[') { + baselen = get_base_var(var); + if (baselen <= 0) + break; + var[baselen++] = '.'; + var[baselen] = 0; + continue; + } + if (!isalpha(c)) + break; + var[baselen] = c; + if (get_value(fn, var, baselen+1) < 0) + break; + } + die("bad config file line %d", config_linenr); +} + +int git_config_int(const char *name, const char *value) +{ + if (value && *value) { + char *end; + int val = strtol(value, &end, 0); + if (!*end) + return val; + } + die("bad config value for '%s'", name); +} + +int git_config_bool(const char *name, const char *value) +{ + if (!value) + return 1; + if (!*value) + return 0; + if (!strcasecmp(value, "true")) + return 1; + if (!strcasecmp(value, "false")) + return 0; + return git_config_int(name, value) != 0; +} + +int git_default_config(const char *var, const char *value) +{ + /* This needs a better name */ + if (!strcmp(var, "core.filemode")) { + trust_executable_bit = git_config_bool(var, value); + return 0; + } + + /* Add other config variables here.. */ + return 0; +} + +int git_config(config_fn_t fn) +{ + int ret; + FILE *f = fopen(git_path("config"), "r"); + + ret = -1; + if (f) { + config_file = f; + config_linenr = 1; + ret = git_parse_file(fn); + fclose(f); + } + return ret; +} diff --git a/diff-files.c b/diff-files.c index 5e598322ff..96d2c7f19f 100644 --- a/diff-files.c +++ b/diff-files.c @@ -38,6 +38,7 @@ int main(int argc, const char **argv) const char *prefix = setup_git_directory(); int entries, i; + git_config(git_default_config); diff_setup(&diff_options); while (1 < argc && argv[1][0] == '-') { if (!strcmp(argv[1], "-q")) diff --git a/diff-tree.c b/diff-tree.c index b2d74eb1d1..2203fa56d0 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -408,6 +408,7 @@ int main(int argc, const char **argv) unsigned char sha1[2][20]; const char *prefix = setup_git_directory(); + git_config(git_default_config); nr_sha1 = 0; diff_setup(&diff_options); diff --git a/read-cache.c b/read-cache.c index d2aebdd6bc..c7f3b26862 100644 --- a/read-cache.c +++ b/read-cache.c @@ -5,6 +5,7 @@ */ #include "cache.h" +int trust_executable_bit = 1; struct cache_entry **active_cache = NULL; unsigned int active_nr = 0, active_alloc = 0, active_cache_changed = 0; -- cgit v1.3 From b721e01f6efd84b04c6946553cd566f2707c964d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 10 Oct 2005 23:22:01 -0700 Subject: Use the same move_temp_to_file in git-http-fetch. The http commit walker cannot use the same temporary file creation code because it needs to use predictable temporary filename for partial fetch continuation purposes, but the code to move the temporary file to the final location should be usable from the ordinary object creation codepath. Export move_temp_to_file from sha1_file.c and use it, while losing the custom relink_or_rename function from http-fetch.c. Also the temporary object file creation part needs to make sure the leading path exists, in preparation of the really lazy fan-out directory creation. Signed-off-by: Junio C Hamano --- cache.h | 1 + http-fetch.c | 48 ++++++++++++++++++------------------------------ sha1_file.c | 2 +- 3 files changed, 20 insertions(+), 31 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0571282e8c..64cbcac5b8 100644 --- a/cache.h +++ b/cache.h @@ -223,6 +223,7 @@ extern int read_tree(void *buffer, unsigned long size, int stage, const char **p extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer, size_t bufsize, size_t *bufposn); extern int write_sha1_to_fd(int fd, const unsigned char *sha1); +extern int move_temp_to_file(const char *tmpfile, char *filename); extern int has_sha1_pack(const unsigned char *sha1); extern int has_sha1_file(const unsigned char *sha1); diff --git a/http-fetch.c b/http-fetch.c index 5d0e3e3923..5821c9e5e9 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -138,25 +138,6 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, return size; } -int relink_or_rename(char *old, char *new) { - int ret; - - ret = link(old, new); - if (ret < 0) { - /* Same Coda hack as in write_sha1_file(sha1_file.c) */ - ret = errno; - if (ret == EXDEV && !rename(old, new)) - return 0; - } - unlink(old); - if (ret) { - if (ret != EEXIST) - return ret; - } - - return 0; -} - #ifdef USE_CURL_MULTI void process_curl_messages(); void process_request_queue(); @@ -295,6 +276,20 @@ void start_request(struct transfer_request *request) request->local = open(request->tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0666); + /* This could have failed due to the "lazy directory creation"; + * try to mkdir the last path component. + */ + if (request->local < 0 && errno == ENOENT) { + char *dir = strrchr(request->tmpfile, '/'); + if (dir) { + *dir = 0; + mkdir(request->tmpfile, 0777); + *dir = '/'; + } + request->local = open(request->tmpfile, + O_WRONLY | O_CREAT | O_EXCL, 0666); + } + if (request->local < 0) { request->state = ABORTED; error("Couldn't create temporary file %s for %s: %s\n", @@ -408,7 +403,7 @@ void finish_request(struct transfer_request *request) return; } request->rename = - relink_or_rename(request->tmpfile, request->filename); + move_temp_to_file(request->tmpfile, request->filename); if (request->rename == 0) pull_say("got %s\n", sha1_to_hex(request->sha1)); @@ -542,7 +537,6 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1) char *filename; char *url; char tmpfile[PATH_MAX]; - int ret; long prev_posn = 0; char range[RANGE_HEADER_SIZE]; struct curl_slist *range_header = NULL; @@ -599,12 +593,7 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1) fclose(indexfile); - ret = relink_or_rename(tmpfile, filename); - if (ret) - return error("unable to write index filename %s: %s", - filename, strerror(ret)); - - return 0; + return move_temp_to_file(tmpfile, filename); } static int setup_index(struct alt_base *repo, unsigned char *sha1) @@ -869,10 +858,9 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1) fclose(packfile); - ret = relink_or_rename(tmpfile, filename); + ret = move_temp_to_file(tmpfile, filename); if (ret) - return error("unable to write pack filename %s: %s", - filename, strerror(ret)); + return ret; lst = &repo->packs; while (*lst != target) diff --git a/sha1_file.c b/sha1_file.c index baaa4c00da..6e3ea232ee 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1287,7 +1287,7 @@ static int link_temp_to_file(const char *tmpfile, char *filename) /* * Move the just written object into its final resting place */ -static int move_temp_to_file(const char *tmpfile, char *filename) +int move_temp_to_file(const char *tmpfile, char *filename) { int ret = link_temp_to_file(tmpfile, filename); if (ret) { -- cgit v1.3 From 013f276eb78967f9742654ebde303c2fbe7a6cd6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 11 Oct 2005 15:22:48 -0700 Subject: show-branch: optionally use unique prefix as name. git-show-branch acquires two new options. --sha1-name to name commits using the unique prefix of their object names, and --no-name to not to show names at all. This was outlined in <7vk6gpyuyr.fsf@assigned-by-dhcp.cox.net> Signed-off-by: Junio C Hamano --- Documentation/git-show-branch.txt | 26 +++++++---------- cache.h | 1 + sha1_name.c | 40 +++++++++++++++++++++----- show-branch.c | 59 +++++++++++++++++++++++++-------------- 4 files changed, 82 insertions(+), 44 deletions(-) (limited to 'cache.h') diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt index e0dce7ec12..c6c97b21c3 100644 --- a/Documentation/git-show-branch.txt +++ b/Documentation/git-show-branch.txt @@ -7,7 +7,7 @@ git-show-branch - Show branches and their commits. SYNOPSIS -------- -'git-show-branch [--all] [--heads] [--tags] [--more= | --list | --independent | --merge-base] ...' +'git-show-branch [--all] [--heads] [--tags] [--more= | --list | --independent | --merge-base] [--no-name | --sha1-name] ...' DESCRIPTION ----------- @@ -44,6 +44,15 @@ OPTIONS Among the s given, display only the ones that cannot be reached from any other . +--no-name:: + Do not show naming strings for each commit. + +--sha1-name:: + Instead of naming the commits using the path to reach + them from heads (e.g. "master~2" to mean the grandparent + of "master"), name them with the unique prefix of their + object names. + Note that --more, --list, --independent and --merge-base options are mutually exclusive. @@ -88,21 +97,6 @@ whose commit message is "Add 'git show-branch'. "fixes" branch adds one commit 'Introduce "reset type"'. "mhf" branch has many other commits. -When only one head is given, the output format changes slightly -to conserve space. The '+' sign to show which commit is -reachable from which head and the first N lines to show the list -of heads being displayed are both meaningless so they are -omitted. Also the label given to each commit does not repeat -the name of the branch because it is obvious. - ------------------------------------------------- -$ git show-branch --more=4 master -[master] Add 'git show-branch'. -[~1] Add a new extended SHA1 syntax ~ -[~2] Fix "git-diff A B" -[~3] git-ls-files: generalized pathspecs -[~4] Make "git-ls-files" work in subdirectories ------------------------------------------------- Author ------ diff --git a/cache.h b/cache.h index 64cbcac5b8..41cc22c1a1 100644 --- a/cache.h +++ b/cache.h @@ -194,6 +194,7 @@ extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2) extern char *sha1_file_name(const unsigned char *sha1); extern char *sha1_pack_name(const unsigned char *sha1); extern char *sha1_pack_index_name(const unsigned char *sha1); +extern const char *find_unique_abbrev(const unsigned char *sha1, int); extern const unsigned char null_sha1[20]; int git_mkstemp(char *path, size_t n, const char *template); diff --git a/sha1_name.c b/sha1_name.c index f64755fbce..4e9a052333 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -119,6 +119,9 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne return found; } +#define SHORT_NAME_NOT_FOUND (-1) +#define SHORT_NAME_AMBIGUOUS (-2) + static int find_unique_short_object(int len, char *canonical, unsigned char *res, unsigned char *sha1) { @@ -128,23 +131,24 @@ static int find_unique_short_object(int len, char *canonical, has_unpacked = find_short_object_filename(len, canonical, unpacked_sha1); has_packed = find_short_packed_object(len, res, packed_sha1); if (!has_unpacked && !has_packed) - return -1; + return SHORT_NAME_NOT_FOUND; if (1 < has_unpacked || 1 < has_packed) - return error("short SHA1 %.*s is ambiguous.", len, canonical); + return SHORT_NAME_AMBIGUOUS; if (has_unpacked != has_packed) { memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20); return 0; } /* Both have unique ones -- do they match? */ if (memcmp(packed_sha1, unpacked_sha1, 20)) - return error("short SHA1 %.*s is ambiguous.", len, canonical); + return -2; memcpy(sha1, packed_sha1, 20); return 0; } -static int get_short_sha1(const char *name, int len, unsigned char *sha1) +static int get_short_sha1(const char *name, int len, unsigned char *sha1, + int quietly) { - int i; + int i, status; char canonical[40]; unsigned char res[20]; @@ -171,7 +175,29 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1) res[i >> 1] |= val; } - return find_unique_short_object(i, canonical, res, sha1); + status = find_unique_short_object(i, canonical, res, sha1); + if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) + return error("short SHA1 %.*s is ambiguous.", len, canonical); + return status; +} + +const char *find_unique_abbrev(const unsigned char *sha1, int len) +{ + int status; + static char hex[41]; + memcpy(hex, sha1_to_hex(sha1), 40); + while (len < 40) { + unsigned char sha1_ret[20]; + status = get_short_sha1(hex, len, sha1_ret, 1); + if (!status) { + hex[len] = 0; + return hex; + } + if (status != SHORT_NAME_AMBIGUOUS) + return NULL; + len++; + } + return NULL; } static int get_sha1_basic(const char *str, int len, unsigned char *sha1) @@ -292,7 +318,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1) ret = get_sha1_basic(name, len, sha1); if (!ret) return 0; - return get_short_sha1(name, len, sha1); + return get_short_sha1(name, len, sha1, 0); } /* diff --git a/show-branch.c b/show-branch.c index 8429c171cf..bb14c8677a 100644 --- a/show-branch.c +++ b/show-branch.c @@ -133,25 +133,28 @@ static void name_commits(struct commit_list *list, nth = 0; while (parents) { struct commit *p = parents->item; - char newname[1000]; + char newname[1000], *en; parents = parents->next; nth++; if (p->object.util) continue; + en = newname; switch (n->generation) { case 0: - sprintf(newname, "%s^%d", - n->head_name, nth); + en += sprintf(en, "%s", n->head_name); break; case 1: - sprintf(newname, "%s^^%d", - n->head_name, nth); + en += sprintf(en, "%s^", n->head_name); break; default: - sprintf(newname, "%s~%d^%d", - n->head_name, n->generation, - nth); + en += sprintf(en, "%s~%d", + n->head_name, n->generation); + break; } + if (nth == 1) + en += sprintf(en, "^"); + else + en += sprintf(en, "^%d", nth); name_commit(p, strdup(newname), 0); i++; name_first_parent_chain(p); @@ -205,7 +208,7 @@ static void join_revs(struct commit_list **list_p, } } -static void show_one_commit(struct commit *commit) +static void show_one_commit(struct commit *commit, int no_name) { char pretty[128], *cp; struct commit_name *name = commit->object.util; @@ -218,11 +221,21 @@ static void show_one_commit(struct commit *commit) cp = pretty + 8; else cp = pretty; - if (name && name->head_name) { - printf("[%s", name->head_name); - if (name->generation) - printf("~%d", name->generation); - printf("] "); + + if (!no_name) { + if (name && name->head_name) { + printf("[%s", name->head_name); + if (name->generation) { + if (name->generation == 1) + printf("^"); + else + printf("~%d", name->generation); + } + printf("] "); + } + else + printf("[%s] ", + find_unique_abbrev(commit->object.sha1, 7)); } puts(cp); } @@ -354,7 +367,8 @@ int main(int ac, char **av) unsigned char head_sha1[20]; int merge_base = 0; int independent = 0; - char **label; + int no_name = 0; + int sha1_name = 0; setup_git_directory(); @@ -370,6 +384,10 @@ int main(int ac, char **av) extra = 1; else if (!strcmp(arg, "--list")) extra = -1; + else if (!strcmp(arg, "--no-name")) + no_name = 1; + else if (!strcmp(arg, "--sha1-name")) + sha1_name = 1; else if (!strncmp(arg, "--more=", 7)) extra = atoi(arg + 7); else if (!strcmp(arg, "--merge-base")) @@ -465,7 +483,8 @@ int main(int ac, char **av) printf("%c [%s] ", is_head ? '*' : '!', ref_name[i]); } - show_one_commit(rev[i]); + /* header lines never need name */ + show_one_commit(rev[i], 1); } if (0 <= extra) { for (i = 0; i < num_rev; i++) @@ -480,7 +499,8 @@ int main(int ac, char **av) sort_in_topological_order(&seen); /* Give names to commits */ - name_commits(seen, rev, ref_name, num_rev); + if (!sha1_name && !no_name) + name_commits(seen, rev, ref_name, num_rev); all_mask = ((1u << (REV_SHIFT + num_rev)) - 1); all_revs = all_mask & ~((1u << REV_SHIFT) - 1); @@ -490,7 +510,6 @@ int main(int ac, char **av) struct commit *commit = pop_one_commit(&seen); int this_flag = commit->object.flags; int is_merge_point = (this_flag & all_revs) == all_revs; - static char *obvious[] = { "" }; if (is_merge_point) shown_merge_point = 1; @@ -501,9 +520,7 @@ int main(int ac, char **av) ? '+' : ' '); putchar(' '); } - show_one_commit(commit); - if (num_rev == 1) - label = obvious; + show_one_commit(commit, no_name); if (shown_merge_point && is_merge_point) if (--extra < 0) break; -- cgit v1.3 From e1b10391eabdaaa4c89c53099dd96d5f9d978719 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 11 Oct 2005 18:47:34 -0700 Subject: Use git config file for committer name and email info This starts using the "user.name" and "user.email" config variables if they exist as the default name and email when committing. This means that you don't have to use the GIT_COMMITTER_EMAIL environment variable to override your email - you can just edit the config file instead. The patch looks bigger than it is because it makes the default name and email information non-static and renames it appropriately. And it moves the common git environment variables into a new library file, so that you can link against libgit.a and get the git environment without having to link in zlib and libcrypt. In short, most of it is renaming and moving, the real change core is just a few new lines in "git_default_config()" that copies the user config values to the new base. It also changes "git-var -l" to list the config variables. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- Makefile | 2 +- cache.h | 4 ++++ commit-tree.c | 4 +++- config.c | 10 ++++++++ environment.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ident.c | 30 +++++++++++------------- read-cache.c | 1 - sha1_file.c | 59 ---------------------------------------------- var.c | 11 +++++++++ 9 files changed, 118 insertions(+), 78 deletions(-) create mode 100644 environment.c (limited to 'cache.h') diff --git a/Makefile b/Makefile index d345c5d116..5e7d0555ea 100644 --- a/Makefile +++ b/Makefile @@ -158,7 +158,7 @@ LIB_OBJS = \ object.o pack-check.o patch-delta.o path.o pkt-line.o \ quote.o read-cache.o refs.o run-command.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ - tag.o tree.o usage.o config.o $(DIFF_OBJS) + tag.o tree.o usage.o config.o environment.o $(DIFF_OBJS) LIBS = $(LIB_FILE) LIBS += -lz diff --git a/cache.h b/cache.h index 41cc22c1a1..1a7e047d76 100644 --- a/cache.h +++ b/cache.h @@ -382,4 +382,8 @@ extern int git_config(config_fn_t fn); extern int git_config_int(const char *, const char *); extern int git_config_bool(const char *, const char *); +#define MAX_GITNAME (1000) +extern char git_default_email[MAX_GITNAME]; +extern char git_default_name[MAX_GITNAME]; + #endif /* CACHE_H */ diff --git a/commit-tree.c b/commit-tree.c index b1ef0b590a..030fb704e5 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -89,6 +89,9 @@ int main(int argc, char **argv) char *buffer; unsigned int size; + setup_ident(); + git_config(git_default_config); + if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0) usage(commit_tree_usage); @@ -104,7 +107,6 @@ int main(int argc, char **argv) } if (!parents) fprintf(stderr, "Committing initial tree %s\n", argv[1]); - setup_ident(); init_buffer(&buffer, &size); add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1)); diff --git a/config.c b/config.c index 510456ceb5..cf803580c9 100644 --- a/config.c +++ b/config.c @@ -207,6 +207,16 @@ int git_default_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "user.name")) { + strncpy(git_default_name, value, sizeof(git_default_name)); + return 0; + } + + if (!strcmp(var, "user.email")) { + strncpy(git_default_email, value, sizeof(git_default_email)); + return 0; + } + /* Add other config variables here.. */ return 0; } diff --git a/environment.c b/environment.c new file mode 100644 index 0000000000..1dc7af56cf --- /dev/null +++ b/environment.c @@ -0,0 +1,75 @@ +/* + * We put all the git config variables in this same object + * file, so that programs can link against the config parser + * without having to link against all the rest of git. + * + * In particular, no need to bring in libz etc unless needed, + * even if you might want to know where the git directory etc + * are. + */ +#include "cache.h" + +char git_default_email[MAX_GITNAME]; +char git_default_name[MAX_GITNAME]; +int trust_executable_bit = 1; + +static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir, + *git_graft_file; +static void setup_git_env(void) +{ + git_dir = getenv(GIT_DIR_ENVIRONMENT); + if (!git_dir) + git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; + git_object_dir = getenv(DB_ENVIRONMENT); + if (!git_object_dir) { + git_object_dir = xmalloc(strlen(git_dir) + 9); + sprintf(git_object_dir, "%s/objects", git_dir); + } + git_refs_dir = xmalloc(strlen(git_dir) + 6); + sprintf(git_refs_dir, "%s/refs", git_dir); + git_index_file = getenv(INDEX_ENVIRONMENT); + if (!git_index_file) { + git_index_file = xmalloc(strlen(git_dir) + 7); + sprintf(git_index_file, "%s/index", git_dir); + } + git_graft_file = getenv(GRAFT_ENVIRONMENT); + if (!git_graft_file) + git_graft_file = strdup(git_path("info/grafts")); +} + +char *get_git_dir(void) +{ + if (!git_dir) + setup_git_env(); + return git_dir; +} + +char *get_object_directory(void) +{ + if (!git_object_dir) + setup_git_env(); + return git_object_dir; +} + +char *get_refs_directory(void) +{ + if (!git_refs_dir) + setup_git_env(); + return git_refs_dir; +} + +char *get_index_file(void) +{ + if (!git_index_file) + setup_git_env(); + return git_index_file; +} + +char *get_graft_file(void) +{ + if (!git_graft_file) + setup_git_env(); + return git_graft_file; +} + + diff --git a/ident.c b/ident.c index 562f5f1816..7a9f5672eb 100644 --- a/ident.c +++ b/ident.c @@ -11,9 +11,7 @@ #include #include -static char real_email[1000]; -static char real_name[1000]; -static char real_date[50]; +static char git_default_date[50]; static void copy_gecos(struct passwd *w, char *name, int sz) { @@ -58,22 +56,22 @@ int setup_ident(void) die("You don't exist. Go away!"); /* Get the name ("gecos") */ - copy_gecos(pw, real_name, sizeof(real_name)); + copy_gecos(pw, git_default_name, sizeof(git_default_name)); /* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */ len = strlen(pw->pw_name); - if (len > sizeof(real_email)/2) + if (len > sizeof(git_default_email)/2) die("Your sysadmin must hate you!"); - memcpy(real_email, pw->pw_name, len); - real_email[len++] = '@'; - gethostname(real_email + len, sizeof(real_email) - len); - if (!strchr(real_email+len, '.')) { - len = strlen(real_email); - real_email[len++] = '.'; - getdomainname(real_email+len, sizeof(real_email)-len); + memcpy(git_default_email, pw->pw_name, len); + git_default_email[len++] = '@'; + gethostname(git_default_email + len, sizeof(git_default_email) - len); + if (!strchr(git_default_email+len, '.')) { + len = strlen(git_default_email); + git_default_email[len++] = '.'; + getdomainname(git_default_email+len, sizeof(git_default_email)-len); } /* And set the default date */ - datestamp(real_date, sizeof(real_date)); + datestamp(git_default_date, sizeof(git_default_date)); return 0; } @@ -159,10 +157,10 @@ char *get_ident(const char *name, const char *email, const char *date_str) int i; if (!name) - name = real_name; + name = git_default_name; if (!email) - email = real_email; - strcpy(date, real_date); + email = git_default_email; + strcpy(date, git_default_date); if (date_str) parse_date(date_str, date, sizeof(date)); diff --git a/read-cache.c b/read-cache.c index 4ed369acf8..6932736203 100644 --- a/read-cache.c +++ b/read-cache.c @@ -5,7 +5,6 @@ */ #include "cache.h" -int trust_executable_bit = 1; struct cache_entry **active_cache = NULL; unsigned int active_nr = 0, active_alloc = 0, active_cache_changed = 0; diff --git a/sha1_file.c b/sha1_file.c index 6e3ea232ee..f059004909 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -48,65 +48,6 @@ int get_sha1_hex(const char *hex, unsigned char *sha1) return 0; } -static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir, - *git_graft_file; -static void setup_git_env(void) -{ - git_dir = getenv(GIT_DIR_ENVIRONMENT); - if (!git_dir) - git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; - git_object_dir = getenv(DB_ENVIRONMENT); - if (!git_object_dir) { - git_object_dir = xmalloc(strlen(git_dir) + 9); - sprintf(git_object_dir, "%s/objects", git_dir); - } - git_refs_dir = xmalloc(strlen(git_dir) + 6); - sprintf(git_refs_dir, "%s/refs", git_dir); - git_index_file = getenv(INDEX_ENVIRONMENT); - if (!git_index_file) { - git_index_file = xmalloc(strlen(git_dir) + 7); - sprintf(git_index_file, "%s/index", git_dir); - } - git_graft_file = getenv(GRAFT_ENVIRONMENT); - if (!git_graft_file) - git_graft_file = strdup(git_path("info/grafts")); -} - -char *get_git_dir(void) -{ - if (!git_dir) - setup_git_env(); - return git_dir; -} - -char *get_object_directory(void) -{ - if (!git_object_dir) - setup_git_env(); - return git_object_dir; -} - -char *get_refs_directory(void) -{ - if (!git_refs_dir) - setup_git_env(); - return git_refs_dir; -} - -char *get_index_file(void) -{ - if (!git_index_file) - setup_git_env(); - return git_index_file; -} - -char *get_graft_file(void) -{ - if (!git_graft_file) - setup_git_env(); - return git_graft_file; -} - int safe_create_leading_directories(char *path) { char *pos = path; diff --git a/var.c b/var.c index 3f13126cb8..51cf86a584 100644 --- a/var.c +++ b/var.c @@ -42,6 +42,15 @@ static const char *read_var(const char *var) return val; } +static int show_config(const char *var, const char *value) +{ + if (value) + printf("%s=%s\n", var, value); + else + printf("%s\n", var); + return git_default_config(var, value); +} + int main(int argc, char **argv) { const char *val; @@ -52,9 +61,11 @@ int main(int argc, char **argv) val = NULL; if (strcmp(argv[1], "-l") == 0) { + git_config(show_config); list_vars(); return 0; } + git_config(git_default_config); val = read_var(argv[1]); if (!val) usage(var_usage); -- cgit v1.3 From 9d835df246e81a6a03e3f633280c45e683e4c673 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 13 Oct 2005 15:38:28 -0700 Subject: Keep track of whether a pack is local or not If we want to re-pack just local packfiles, we need to know whether a particular object is local or not. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 3 ++- sha1_file.c | 11 ++++++----- verify-pack.c | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1a7e047d76..328658235b 100644 --- a/cache.h +++ b/cache.h @@ -313,6 +313,7 @@ extern struct packed_git { void *pack_base; unsigned int pack_last_used; unsigned int pack_use_cnt; + int pack_local; unsigned char sha1[20]; char pack_name[0]; /* something like ".git/objects/pack/xxxxx.pack" */ } *packed_git; @@ -352,7 +353,7 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1, extern int use_packed_git(struct packed_git *); extern void unuse_packed_git(struct packed_git *); -extern struct packed_git *add_packed_git(char *, int); +extern struct packed_git *add_packed_git(char *, int, int); extern int num_packed_objects(const struct packed_git *p); extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*); extern int find_pack_entry_one(const unsigned char *, struct pack_entry *, struct packed_git *); diff --git a/sha1_file.c b/sha1_file.c index f059004909..e45679975e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -416,7 +416,7 @@ int use_packed_git(struct packed_git *p) return 0; } -struct packed_git *add_packed_git(char *path, int path_len) +struct packed_git *add_packed_git(char *path, int path_len, int local) { struct stat st; struct packed_git *p; @@ -444,6 +444,7 @@ struct packed_git *add_packed_git(char *path, int path_len) p->pack_base = NULL; p->pack_last_used = 0; p->pack_use_cnt = 0; + p->pack_local = local; return p; } @@ -484,7 +485,7 @@ void install_packed_git(struct packed_git *pack) packed_git = pack; } -static void prepare_packed_git_one(char *objdir) +static void prepare_packed_git_one(char *objdir, int local) { char path[PATH_MAX]; int len; @@ -506,7 +507,7 @@ static void prepare_packed_git_one(char *objdir) /* we have .idx. Is it a file we can map? */ strcpy(path + len, de->d_name); - p = add_packed_git(path, len + namelen); + p = add_packed_git(path, len + namelen, local); if (!p) continue; p->next = packed_git; @@ -522,11 +523,11 @@ void prepare_packed_git(void) if (run_once) return; - prepare_packed_git_one(get_object_directory()); + prepare_packed_git_one(get_object_directory(), 1); prepare_alt_odb(); for (alt = alt_odb_list; alt; alt = alt->next) { alt->name[0] = 0; - prepare_packed_git_one(alt->base); + prepare_packed_git_one(alt->base, 0); } run_once = 1; } diff --git a/verify-pack.c b/verify-pack.c index 80b60a6b7c..c99db9dd79 100644 --- a/verify-pack.c +++ b/verify-pack.c @@ -15,12 +15,12 @@ static int verify_one_pack(char *arg, int verbose) len--; } /* Should name foo.idx now */ - if ((g = add_packed_git(arg, len))) + if ((g = add_packed_git(arg, len, 1))) break; /* No? did you name just foo? */ strcpy(arg + len, ".idx"); len += 4; - if ((g = add_packed_git(arg, len))) + if ((g = add_packed_git(arg, len, 1))) break; return error("packfile %s not found.", arg); } -- cgit v1.3 From 4546738b58a0134eef154231b07d60fc174d56e3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 13 Oct 2005 11:03:18 -0700 Subject: Unlocalized isspace and friends Do our own ctype.h, just to get the sane semantics: we want locale-independence, _and_ we want the right signed behaviour. Plus we only use a very small subset of ctype.h anyway (isspace, isalpha, isdigit and isalnum). Signed-off-by: Junio C Hamano --- Makefile | 3 ++- apply.c | 1 - cache.h | 26 ++++++++++++++++++++++++++ commit-tree.c | 1 - commit.c | 1 - config.c | 1 - convert-objects.c | 1 - ctype.c | 23 +++++++++++++++++++++++ date.c | 1 - diff-tree.c | 1 - ident.c | 1 - mailsplit.c | 1 - pack-objects.c | 1 - patch-id.c | 1 - refs.c | 1 - update-ref.c | 1 - 16 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 ctype.c (limited to 'cache.h') diff --git a/Makefile b/Makefile index e2e87f6beb..9fe65ba2be 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,8 @@ LIB_OBJS = \ object.o pack-check.o patch-delta.o path.o pkt-line.o \ quote.o read-cache.o refs.o run-command.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ - tag.o tree.o usage.o config.o environment.o $(DIFF_OBJS) + tag.o tree.o usage.o config.o environment.o ctype.o \ + $(DIFF_OBJS) LIBS = $(LIB_FILE) LIBS += -lz diff --git a/apply.c b/apply.c index 155fbe84da..f4d00f2835 100644 --- a/apply.c +++ b/apply.c @@ -6,7 +6,6 @@ * This applies patches on top of some (arbitrary) version of the SCM. * */ -#include #include #include "cache.h" diff --git a/cache.h b/cache.h index 328658235b..f1d15ab3c9 100644 --- a/cache.h +++ b/cache.h @@ -387,4 +387,30 @@ extern int git_config_bool(const char *, const char *); extern char git_default_email[MAX_GITNAME]; extern char git_default_name[MAX_GITNAME]; +/* Sane ctype - no locale, and works with signed chars */ +#undef isspace +#undef isdigit +#undef isalpha +#undef isalnum +#undef tolower +#undef toupper +extern unsigned char sane_ctype[256]; +#define GIT_SPACE 0x01 +#define GIT_DIGIT 0x02 +#define GIT_ALPHA 0x04 +#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) +#define isspace(x) sane_istest(x,GIT_SPACE) +#define isdigit(x) sane_istest(x,GIT_DIGIT) +#define isalpha(x) sane_istest(x,GIT_ALPHA) +#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) +#define tolower(x) sane_case((unsigned char)(x), 0x20) +#define toupper(x) sane_case((unsigned char)(x), 0) + +static inline int sane_case(int x, int high) +{ + if (sane_istest(x, GIT_ALPHA)) + x = (x & ~0x20) | high; + return x; +} + #endif /* CACHE_H */ diff --git a/commit-tree.c b/commit-tree.c index 030fb704e5..ea0fdd44e2 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -7,7 +7,6 @@ #include #include -#include #define BLOCKING (1ul << 14) diff --git a/commit.c b/commit.c index f735f981bb..8f403180e5 100644 --- a/commit.c +++ b/commit.c @@ -1,4 +1,3 @@ -#include #include "tag.h" #include "commit.h" #include "cache.h" diff --git a/config.c b/config.c index 9b7c6f2942..519fecfee4 100644 --- a/config.c +++ b/config.c @@ -1,4 +1,3 @@ -#include #include "cache.h" diff --git a/convert-objects.c b/convert-objects.c index 9ad0c77678..a892013f0f 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -1,6 +1,5 @@ #define _XOPEN_SOURCE /* glibc2 needs this */ #include -#include #include "cache.h" struct entry { diff --git a/ctype.c b/ctype.c new file mode 100644 index 0000000000..56bdffa636 --- /dev/null +++ b/ctype.c @@ -0,0 +1,23 @@ +/* + * Sane locale-independent, ASCII ctype. + * + * No surprises, and works with signed and unsigned chars. + */ +#include "cache.h" + +#define SS GIT_SPACE +#define AA GIT_ALPHA +#define DD GIT_DIGIT + +unsigned char sane_ctype[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, SS, SS, 0, 0, SS, 0, 0, /* 0-15 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-15 */ + SS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 32-15 */ + DD, DD, DD, DD, DD, DD, DD, DD, DD, DD, 0, 0, 0, 0, 0, 0, /* 48-15 */ + 0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 64-15 */ + AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 80-15 */ + 0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 96-15 */ + AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 112-15 */ + /* Nothing in the 128.. range */ +}; + diff --git a/date.c b/date.c index b21cadc4d6..63f5a09197 100644 --- a/date.c +++ b/date.c @@ -4,7 +4,6 @@ * Copyright (C) Linus Torvalds, 2005 */ -#include #include #include "cache.h" diff --git a/diff-tree.c b/diff-tree.c index 2203fa56d0..851722037d 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -1,4 +1,3 @@ -#include #include "cache.h" #include "diff.h" #include "commit.h" diff --git a/ident.c b/ident.c index 7a9f5672eb..1bfbc6ff35 100644 --- a/ident.c +++ b/ident.c @@ -9,7 +9,6 @@ #include #include -#include static char git_default_date[50]; diff --git a/mailsplit.c b/mailsplit.c index 0f8100dcca..189f4ed724 100644 --- a/mailsplit.c +++ b/mailsplit.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "cache.h" diff --git a/pack-objects.c b/pack-objects.c index 8a1ee746e0..b3e6152033 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1,4 +1,3 @@ -#include #include "cache.h" #include "object.h" #include "delta.h" diff --git a/patch-id.c b/patch-id.c index 960e7cedf9..edbc4aa3e8 100644 --- a/patch-id.c +++ b/patch-id.c @@ -1,4 +1,3 @@ -#include #include "cache.h" static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c) diff --git a/refs.c b/refs.c index 5a8cbd4ef3..42240d2769 100644 --- a/refs.c +++ b/refs.c @@ -2,7 +2,6 @@ #include "cache.h" #include -#include /* We allow "recursive" symbolic refs. Only within reason, though */ #define MAXDEPTH 5 diff --git a/update-ref.c b/update-ref.c index 4a1704c1a5..65dc3d6385 100644 --- a/update-ref.c +++ b/update-ref.c @@ -1,6 +1,5 @@ #include "cache.h" #include "refs.h" -#include static const char git_update_ref_usage[] = "git-update-ref []"; -- cgit v1.3 From 1a7141ff28e217312da4b289127875905c6ec479 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Oct 2005 18:57:40 -0700 Subject: Ignore funny refname sent from remote This allows the remote side (most notably, upload-pack) to show additional information without affecting the downloader. Peek-remote does not ignore them -- this is to make it useful for Pasky's automatic tag following. Signed-off-by: Junio C Hamano --- cache.h | 2 +- clone-pack.c | 2 +- connect.c | 8 +++++++- fetch-pack.c | 2 +- peek-remote.c | 2 +- send-pack.c | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f1d15ab3c9..d776016822 100644 --- a/cache.h +++ b/cache.h @@ -339,7 +339,7 @@ extern int path_match(const char *path, int nr, char **match); extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, int nr_refspec, char **refspec, int all); extern int get_ack(int fd, unsigned char *result_sha1); -extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match); +extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, int ignore_funny); extern struct packed_git *parse_pack_index(unsigned char *sha1); extern struct packed_git *parse_pack_index_file(const unsigned char *sha1, diff --git a/clone-pack.c b/clone-pack.c index 0ea7e7f65d..f9b263a441 100644 --- a/clone-pack.c +++ b/clone-pack.c @@ -287,7 +287,7 @@ static int clone_pack(int fd[2], int nr_match, char **match) struct ref *refs; int status; - get_remote_heads(fd[0], &refs, nr_match, match); + get_remote_heads(fd[0], &refs, nr_match, match, 1); if (!refs) { packet_flush(fd[1]); die("no matching remote head"); diff --git a/connect.c b/connect.c index 247f02fb4c..f71eba8af8 100644 --- a/connect.c +++ b/connect.c @@ -10,7 +10,8 @@ /* * Read all the refs from the other end */ -struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match) +struct ref **get_remote_heads(int in, struct ref **list, + int nr_match, char **match, int ignore_funny) { *list = NULL; for (;;) { @@ -29,6 +30,11 @@ struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **ma if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ') die("protocol error: expected sha/ref, got '%s'", buffer); name = buffer + 41; + + if (ignore_funny && 45 < len && !memcmp(name, "refs/", 5) && + check_ref_format(name + 5)) + continue; + if (nr_match && !path_match(name, nr_match, match)) continue; ref = xcalloc(1, sizeof(*ref) + len - 40); diff --git a/fetch-pack.c b/fetch-pack.c index 582f967a7a..953c0cf441 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -81,7 +81,7 @@ static int fetch_pack(int fd[2], int nr_match, char **match) int status; pid_t pid; - get_remote_heads(fd[0], &ref, nr_match, match); + get_remote_heads(fd[0], &ref, nr_match, match, 1); if (!ref) { packet_flush(fd[1]); die("no matching remote head"); diff --git a/peek-remote.c b/peek-remote.c index 4b1d0d5ba8..ee49bf3b7b 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -11,7 +11,7 @@ static int peek_remote(int fd[2]) { struct ref *ref; - get_remote_heads(fd[0], &ref, 0, NULL); + get_remote_heads(fd[0], &ref, 0, NULL, 0); packet_flush(fd[1]); while (ref) { diff --git a/send-pack.c b/send-pack.c index 55d8ff7e10..9f9a6e70b8 100644 --- a/send-pack.c +++ b/send-pack.c @@ -181,7 +181,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec) int new_refs; /* No funny business with the matcher */ - remote_tail = get_remote_heads(in, &remote_refs, 0, NULL); + remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, 1); get_local_heads(); /* match them up */ -- cgit v1.3 From f3123c4ab3d3698262e59561ac084de45b10365a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 22 Oct 2005 01:28:13 -0700 Subject: pack-objects: Allow use of pre-generated pack. git-pack-objects can reuse pack files stored in $GIT_DIR/pack-cache directory, when a necessary pack is found. This is hopefully useful when upload-pack (called from git-daemon) is expected to receive requests for the same set of objects many times (e.g full cloning request of any project, or updates from the set of heads previous day to the latest for a slow moving project). Currently git-pack-objects does *not* keep pack files it creates for reusing. It might be useful to add --update-cache option to it, which would allow it store pack files it created in the pack-cache directory, and prune rarely used ones from it. Signed-off-by: Junio C Hamano --- Makefile | 2 +- cache.h | 1 + copy.c | 37 ++++++++++++++++++++++++++ pack-objects.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 copy.c (limited to 'cache.h') diff --git a/Makefile b/Makefile index 5b0306d391..701067d435 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ LIB_OBJS = \ object.o pack-check.o patch-delta.o path.o pkt-line.o \ quote.o read-cache.o refs.o run-command.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ - tag.o tree.o usage.o config.o environment.o ctype.o \ + tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ $(DIFF_OBJS) LIBS = $(LIB_FILE) diff --git a/cache.h b/cache.h index d776016822..2e36cc5b8b 100644 --- a/cache.h +++ b/cache.h @@ -413,4 +413,5 @@ static inline int sane_case(int x, int high) return x; } +extern int copy_fd(int ifd, int ofd); #endif /* CACHE_H */ diff --git a/copy.c b/copy.c new file mode 100644 index 0000000000..20092757d3 --- /dev/null +++ b/copy.c @@ -0,0 +1,37 @@ +#include "cache.h" + +int copy_fd(int ifd, int ofd) +{ + while (1) { + int len; + char buffer[8192]; + char *buf = buffer; + len = read(ifd, buffer, sizeof(buffer)); + if (!len) + break; + if (len < 0) { + if (errno == EAGAIN) + continue; + return error("copy-fd: read returned %s", + strerror(errno)); + } + while (1) { + int written = write(ofd, buf, len); + if (written > 0) { + buf += written; + len -= written; + if (!len) + break; + } + if (!written) + return error("copy-fd: write returned 0"); + if (errno == EAGAIN || errno == EINTR) + continue; + return error("copy-fd: write returned %s", + strerror(errno)); + } + } + close(ifd); + return 0; +} + diff --git a/pack-objects.c b/pack-objects.c index b3e6152033..4e941e7392 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -400,6 +400,71 @@ static void find_deltas(struct object_entry **list, int window, int depth) free(array); } +static void prepare_pack(int window, int depth) +{ + get_object_details(); + + fprintf(stderr, "Packing %d objects\n", nr_objects); + + sorted_by_type = create_sorted_list(type_size_sort); + if (window && depth) + find_deltas(sorted_by_type, window+1, depth); + write_pack_file(); +} + +static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout) +{ + static const char cache[] = "pack-cache/pack-%s.%s"; + char *cached_pack, *cached_idx; + int ifd, ofd, ifd_ix = -1; + + cached_pack = git_path(cache, sha1_to_hex(sha1), "pack"); + ifd = open(cached_pack, O_RDONLY); + if (ifd < 0) + return 0; + + if (!pack_to_stdout) { + cached_idx = git_path(cache, sha1_to_hex(sha1), "idx"); + ifd_ix = open(cached_idx, O_RDONLY); + if (ifd_ix < 0) { + close(ifd); + return 0; + } + } + + fprintf(stderr, "Reusing %d objects pack %s\n", nr_objects, + sha1_to_hex(sha1)); + + if (pack_to_stdout) { + if (copy_fd(ifd, 1)) + exit(1); + close(ifd); + } + else { + char name[PATH_MAX]; + snprintf(name, sizeof(name), + "%s-%s.%s", base_name, sha1_to_hex(sha1), "pack"); + ofd = open(name, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (ofd < 0) + die("unable to open %s (%s)", name, strerror(errno)); + if (copy_fd(ifd, ofd)) + exit(1); + close(ifd); + + snprintf(name, sizeof(name), + "%s-%s.%s", base_name, sha1_to_hex(sha1), "idx"); + ofd = open(name, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (ofd < 0) + die("unable to open %s (%s)", name, strerror(errno)); + if (copy_fd(ifd_ix, ofd)) + exit(1); + close(ifd_ix); + puts(sha1_to_hex(sha1)); + } + + return 1; +} + int main(int argc, char **argv) { SHA_CTX ctx; @@ -472,9 +537,6 @@ int main(int argc, char **argv) } if (non_empty && !nr_objects) return 0; - get_object_details(); - - fprintf(stderr, "Packing %d objects\n", nr_objects); sorted_by_sha = create_sorted_list(sha1_sort); SHA1_Init(&ctx); @@ -485,14 +547,14 @@ int main(int argc, char **argv) } SHA1_Final(object_list_sha1, &ctx); - sorted_by_type = create_sorted_list(type_size_sort); - if (window && depth) - find_deltas(sorted_by_type, window+1, depth); - - write_pack_file(); - if (!pack_to_stdout) { - write_index_file(); - puts(sha1_to_hex(object_list_sha1)); + if (reuse_cached_pack(object_list_sha1, pack_to_stdout)) + ; + else { + prepare_pack(window, depth); + if (!pack_to_stdout) { + write_index_file(); + puts(sha1_to_hex(object_list_sha1)); + } } return 0; } -- cgit v1.3 From 211b5f9e62cc961acda59392fbf5a3efa8106c97 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 28 Oct 2005 04:48:54 +0200 Subject: Support receiving server capabilities This patch implements the client side of backward compatible upload-pack protocol extension, <20051027141619.0e8029f2.vsu@altlinux.ru> by Sergey. The updated server can append "server_capabilities" which is supposed to be a string containing space separated features of the server, after one of elements in the initial list of SHA1-refname line, hidden with an embedded NUL. After get_remote_heads(), check if the server supports the feature like if (server_supports("multi_ack")) do_something(); Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + connect.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2e36cc5b8b..677c6acc35 100644 --- a/cache.h +++ b/cache.h @@ -340,6 +340,7 @@ extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, int nr_refspec, char **refspec, int all); extern int get_ack(int fd, unsigned char *result_sha1); extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, int ignore_funny); +extern int server_supports(const char *feature); extern struct packed_git *parse_pack_index(unsigned char *sha1); extern struct packed_git *parse_pack_index_file(const unsigned char *sha1, diff --git a/connect.c b/connect.c index b171c5dbc8..5cc49f975a 100644 --- a/connect.c +++ b/connect.c @@ -8,6 +8,8 @@ #include #include +static char *server_capabilities = ""; + /* * Read all the refs from the other end */ @@ -20,7 +22,7 @@ struct ref **get_remote_heads(int in, struct ref **list, unsigned char old_sha1[20]; static char buffer[1000]; char *name; - int len; + int len, name_len; len = packet_read_line(in, buffer, sizeof(buffer)); if (!len) @@ -36,6 +38,13 @@ struct ref **get_remote_heads(int in, struct ref **list, check_ref_format(name + 5)) continue; + name_len = strlen(name); + if (len != name_len + 41) { + if (server_capabilities) + free(server_capabilities); + server_capabilities = strdup(name + name_len + 1); + } + if (nr_match && !path_match(name, nr_match, match)) continue; ref = xcalloc(1, sizeof(*ref) + len - 40); @@ -47,6 +56,11 @@ struct ref **get_remote_heads(int in, struct ref **list, return list; } +int server_supports(const char *feature) +{ + return strstr(feature, server_capabilities) != NULL; +} + int get_ack(int fd, unsigned char *result_sha1) { static char line[1000]; -- cgit v1.3