From: Junio C Hamano Date: Fri, 12 Jan 2007 00:50:36 +0000 (-0800) Subject: Merge branch 'jc/bare' X-Git-Tag: v1.5.0-rc1~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e861ce1692fa9809f3e7b898804f8ddaf7cd8975?hp=-c Merge branch 'jc/bare' * jc/bare: Disallow working directory commands in a bare repository. git-fetch: allow updating the current branch in a bare repository. Introduce is_bare_repository() and core.bare configuration variable Move initialization of log_all_ref_updates --- e861ce1692fa9809f3e7b898804f8ddaf7cd8975 diff --combined cache.h index cbe398d3bd,cff25690f1..c482c32a03 --- a/cache.h +++ b/cache.h @@@ -127,7 -127,8 +127,8 @@@ extern int cache_errno #define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL" #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" - extern int is_bare_git_dir(const char *dir); + extern int is_bare_repository_cfg; + extern int is_bare_repository(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); extern char *get_refs_directory(void); @@@ -299,7 -300,7 +300,7 @@@ extern char *sha1_to_hex(const unsigne extern int read_ref(const char *filename, unsigned char *sha1); extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *); extern int create_symref(const char *ref, const char *refs_heads_master); -extern int validate_symref(const char *ref); +extern int validate_headref(const char *ref); extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2); @@@ -432,12 -433,10 +433,12 @@@ extern char *git_commit_encoding extern char *git_log_output_encoding; extern int copy_fd(int ifd, int ofd); +extern int read_in_full(int fd, void *buf, size_t count); extern void read_or_die(int fd, void *buf, size_t count); -extern int write_in_full(int fd, const void *buf, size_t count, const char *); +extern int write_in_full(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count); extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); +extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); /* pager.c */ extern void setup_pager(void); diff --combined config.c index 733fb1a34c,20e6ecc361..b6082f597c --- a/config.c +++ b/config.c @@@ -269,6 -269,11 +269,11 @@@ int git_default_config(const char *var return 0; } + if (!strcmp(var, "core.bare")) { + is_bare_repository_cfg = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "core.ignorestat")) { assume_unchanged = git_config_bool(var, value); return 0; @@@ -464,15 -469,7 +469,15 @@@ static int store_aux(const char* key, c return 0; } -static void store_write_section(int fd, const char* key) +static int write_error() +{ + fprintf(stderr, "Failed to write new configuration file\n"); + + /* Same error code as "failed to rename". */ + return 4; +} + +static int store_write_section(int fd, const char* key) { const char *dot = strchr(key, '.'); int len1 = store.baselen, len2 = -1; @@@ -486,74 -483,37 +491,74 @@@ } } - write(fd, "[", 1); - write(fd, key, len1); + if (write_in_full(fd, "[", 1) != 1 || + write_in_full(fd, key, len1) != len1) + return 0; if (len2 >= 0) { - write(fd, " \"", 2); + if (write_in_full(fd, " \"", 2) != 2) + return 0; while (--len2 >= 0) { unsigned char c = *++dot; if (c == '"') - write(fd, "\\", 1); - write(fd, &c, 1); + if (write_in_full(fd, "\\", 1) != 1) + return 0; + if (write_in_full(fd, &c, 1) != 1) + return 0; } - write(fd, "\"", 1); + if (write_in_full(fd, "\"", 1) != 1) + return 0; } - write(fd, "]\n", 2); + if (write_in_full(fd, "]\n", 2) != 2) + return 0; + + return 1; } -static void store_write_pair(int fd, const char* key, const char* value) +static int store_write_pair(int fd, const char* key, const char* value) { int i; + int length = strlen(key+store.baselen+1); + int quote = 0; - write(fd, "\t", 1); - write(fd, key+store.baselen+1, - strlen(key+store.baselen+1)); - write(fd, " = ", 3); + /* Check to see if the value needs to be quoted. */ + if (value[0] == ' ') + quote = 1; + for (i = 0; value[i]; i++) + if (value[i] == ';' || value[i] == '#') + quote = 1; + if (value[i-1] == ' ') + quote = 1; + + if (write_in_full(fd, "\t", 1) != 1 || + write_in_full(fd, key+store.baselen+1, length) != length || + write_in_full(fd, " = ", 3) != 3) + return 0; + if (quote && write_in_full(fd, "\"", 1) != 1) + return 0; for (i = 0; value[i]; i++) switch (value[i]) { - case '\n': write(fd, "\\n", 2); break; - case '\t': write(fd, "\\t", 2); break; - case '"': case '\\': write(fd, "\\", 1); - default: write(fd, value+i, 1); - } - write(fd, "\n", 1); + case '\n': + if (write_in_full(fd, "\\n", 2) != 2) + return 0; + break; + case '\t': + if (write_in_full(fd, "\\t", 2) != 2) + return 0; + break; + case '"': + case '\\': + if (write_in_full(fd, "\\", 1) != 1) + return 0; + default: + if (write_in_full(fd, value+i, 1) != 1) + return 0; + break; + } + if (quote && write_in_full(fd, "\"", 1) != 1) + return 0; + if (write_in_full(fd, "\n", 1) != 1) + return 0; + return 1; } static int find_beginning_of_line(const char* contents, int size, @@@ -693,10 -653,9 +698,10 @@@ int git_config_set_multivar(const char } store.key = (char*)key; - store_write_section(fd, key); - store_write_pair(fd, key, value); - } else{ + if (!store_write_section(fd, key) || + !store_write_pair(fd, key, value)) + goto write_err_out; + } else { struct stat st; char* contents; int i, copy_begin, copy_end, new_line = 0; @@@ -775,33 -734,25 +780,33 @@@ /* write the first part of the config */ if (copy_end > copy_begin) { - write(fd, contents + copy_begin, - copy_end - copy_begin); - if (new_line) - write(fd, "\n", 1); + if (write_in_full(fd, contents + copy_begin, + copy_end - copy_begin) < + copy_end - copy_begin) + goto write_err_out; + if (new_line && + write_in_full(fd, "\n", 1) != 1) + goto write_err_out; } copy_begin = store.offset[i]; } /* write the pair (value == NULL means unset) */ if (value != NULL) { - if (store.state == START) - store_write_section(fd, key); - store_write_pair(fd, key, value); + if (store.state == START) { + if (!store_write_section(fd, key)) + goto write_err_out; + } + if (!store_write_pair(fd, key, value)) + goto write_err_out; } /* write the rest of the config */ if (copy_begin < st.st_size) - write(fd, contents + copy_begin, - st.st_size - copy_begin); + if (write_in_full(fd, contents + copy_begin, + st.st_size - copy_begin) < + st.st_size - copy_begin) + goto write_err_out; munmap(contents, st.st_size); unlink(config_filename); @@@ -824,11 -775,6 +829,11 @@@ out_free free(lock_file); } return ret; + +write_err_out: + ret = write_error(); + goto out_free; + } int git_config_rename_section(const char *old_name, const char *new_name) @@@ -859,7 -805,6 +864,7 @@@ while (fgets(buf, sizeof(buf), config_file)) { int i; + int length; for (i = 0; buf[i] && isspace(buf[i]); i++) ; /* do nothing */ if (buf[i] == '[') { @@@ -890,22 -835,15 +895,22 @@@ /* old_name matches */ ret++; store.baselen = strlen(new_name); - store_write_section(out_fd, new_name); + if (!store_write_section(out_fd, new_name)) { + ret = write_error(); + goto out; + } continue; } } - write(out_fd, buf, strlen(buf)); + length = strlen(buf); + if (write_in_full(out_fd, buf, length) != length) { + ret = write_error(); + goto out; + } } fclose(config_file); if (close(out_fd) || commit_lock_file(lock) < 0) - ret = error("Cannot commit config file!"); + ret = error("Cannot commit config file!"); out: free(config_filename); return ret; diff --combined git-am.sh index 59d663ba9e,f50de61049..1252f26bbd --- a/git-am.sh +++ b/git-am.sh @@@ -2,11 -2,12 +2,12 @@@ # # Copyright (c) 2005, 2006 Junio C Hamano -USAGE='[--signoff] [--dotest=] [--utf8] [--binary] [--3way] +USAGE='[--signoff] [--dotest=] [--utf8 | --no-utf8] [--binary] [--3way] [--interactive] [--whitespace=