Merge branch 'master' into next

* master:
  packed_object_info_detail(): check for corrupt packfile.
  cleanups: remove unused variable from exec_cmd.c
  cleanups: prevent leak of two strduped strings in config.c
  cleanups: Remove impossible case in quote.c
  cleanups: Remove unused vars from combine-diff.c
  cleanups: Fix potential bugs in connect.c
  Allow empty lines in info/grafts
This commit is contained in:
Junio C Hamano 2006-04-17 23:15:20 -07:00
commit e5de825fda
7 changed files with 50 additions and 33 deletions

View File

@ -589,7 +589,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
struct diff_options *opt) struct diff_options *opt)
{ {
unsigned long result_size, cnt, lno; unsigned long result_size, cnt, lno;
char *result, *cp, *ep; char *result, *cp;
struct sline *sline; /* survived lines */ struct sline *sline; /* survived lines */
int mode_differs = 0; int mode_differs = 0;
int i, show_hunks, shown_header = 0; int i, show_hunks, shown_header = 0;
@ -641,7 +641,6 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
cnt++; /* incomplete line */ cnt++; /* incomplete line */
sline = xcalloc(cnt+2, sizeof(*sline)); sline = xcalloc(cnt+2, sizeof(*sline));
ep = result;
sline[0].bol = result; sline[0].bol = result;
for (lno = 0; lno <= cnt + 1; lno++) { for (lno = 0; lno <= cnt + 1; lno++) {
sline[lno].lost_tail = &sline[lno].lost_head; sline[lno].lost_tail = &sline[lno].lost_head;
@ -752,7 +751,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt) static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
{ {
int i, offset, mod_type = 'A'; int i, offset;
const char *prefix; const char *prefix;
int line_termination, inter_name_termination; int line_termination, inter_name_termination;
@ -764,13 +763,6 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
if (header) if (header)
printf("%s%c", header, line_termination); printf("%s%c", header, line_termination);
for (i = 0; i < num_parent; i++) {
if (p->parent[i].mode)
mod_type = 'M';
}
if (!p->mode)
mod_type = 'D';
if (opt->output_format == DIFF_FORMAT_RAW) { if (opt->output_format == DIFF_FORMAT_RAW) {
offset = strlen(COLONS) - num_parent; offset = strlen(COLONS) - num_parent;
if (offset < 0) if (offset < 0)

View File

@ -160,7 +160,7 @@ struct commit_graft *read_graft_line(char *buf, int len)
if (buf[len-1] == '\n') if (buf[len-1] == '\n')
buf[--len] = 0; buf[--len] = 0;
if (buf[0] == '#') if (buf[0] == '#' || buf[0] == '\0')
return NULL; return NULL;
if ((len + 1) % 41) { if ((len + 1) % 41) {
bad_graft_data: bad_graft_data:

View File

@ -420,6 +420,7 @@ int git_config_set_multivar(const char* key, const char* value,
{ {
int i; int i;
int fd, in_fd; int fd, in_fd;
int ret;
char* config_filename = strdup(git_path("config")); char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock")); char* lock_file = strdup(git_path("config.lock"));
const char* last_dot = strrchr(key, '.'); const char* last_dot = strrchr(key, '.');
@ -429,9 +430,10 @@ int git_config_set_multivar(const char* key, const char* value,
* key name separated by a dot, we have to know where the dot is. * key name separated by a dot, we have to know where the dot is.
*/ */
if (last_dot == NULL) { if (last_dot == NULL) {
fprintf(stderr, "key does not contain a section: %s\n", key); fprintf(stderr, "key does not contain a section: %s\n", key);
return 2; ret = 2;
goto out_free;
} }
store.baselen = last_dot - key; store.baselen = last_dot - key;
@ -447,7 +449,8 @@ int git_config_set_multivar(const char* key, const char* value,
(i == store.baselen+1 && !isalpha(key[i])))) { (i == store.baselen+1 && !isalpha(key[i])))) {
fprintf(stderr, "invalid key: %s\n", key); fprintf(stderr, "invalid key: %s\n", key);
free(store.key); free(store.key);
return 1; ret = 1;
goto out_free;
} else } else
store.key[i] = tolower(key[i]); store.key[i] = tolower(key[i]);
store.key[i] = 0; store.key[i] = 0;
@ -460,7 +463,8 @@ int git_config_set_multivar(const char* key, const char* value,
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "could not lock config file\n"); fprintf(stderr, "could not lock config file\n");
free(store.key); free(store.key);
return -1; ret = -1;
goto out_free;
} }
/* /*
@ -475,13 +479,15 @@ int git_config_set_multivar(const char* key, const char* value,
strerror(errno)); strerror(errno));
close(fd); close(fd);
unlink(lock_file); unlink(lock_file);
return 3; /* same as "invalid config file" */ ret = 3; /* same as "invalid config file" */
goto out_free;
} }
/* if nothing to unset, error out */ /* if nothing to unset, error out */
if (value == NULL) { if (value == NULL) {
close(fd); close(fd);
unlink(lock_file); unlink(lock_file);
return 5; ret = 5;
goto out_free;
} }
store.key = (char*)key; store.key = (char*)key;
@ -507,7 +513,8 @@ int git_config_set_multivar(const char* key, const char* value,
fprintf(stderr, "Invalid pattern: %s\n", fprintf(stderr, "Invalid pattern: %s\n",
value_regex); value_regex);
free(store.value_regex); free(store.value_regex);
return 6; ret = 6;
goto out_free;
} }
} }
@ -528,7 +535,8 @@ int git_config_set_multivar(const char* key, const char* value,
regfree(store.value_regex); regfree(store.value_regex);
free(store.value_regex); free(store.value_regex);
} }
return 3; ret = 3;
goto out_free;
} }
free(store.key); free(store.key);
@ -542,7 +550,8 @@ int git_config_set_multivar(const char* key, const char* value,
(store.seen > 1 && multi_replace == 0)) { (store.seen > 1 && multi_replace == 0)) {
close(fd); close(fd);
unlink(lock_file); unlink(lock_file);
return 5; ret = 5;
goto out_free;
} }
fstat(in_fd, &st); fstat(in_fd, &st);
@ -593,10 +602,18 @@ int git_config_set_multivar(const char* key, const char* value,
if (rename(lock_file, config_filename) < 0) { if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n"); fprintf(stderr, "Could not rename the lock file?\n");
return 4; ret = 4;
goto out_free;
} }
return 0; ret = 0;
out_free:
if (config_filename)
free(config_filename);
if (lock_file)
free(lock_file);
return ret;
} }

View File

@ -74,7 +74,7 @@ int get_ack(int fd, unsigned char *result_sha1)
line[--len] = 0; line[--len] = 0;
if (!strcmp(line, "NAK")) if (!strcmp(line, "NAK"))
return 0; return 0;
if (!strncmp(line, "ACK ", 3)) { if (!strncmp(line, "ACK ", 4)) {
if (!get_sha1_hex(line+4, result_sha1)) { if (!get_sha1_hex(line+4, result_sha1)) {
if (strstr(line+45, "continue")) if (strstr(line+45, "continue"))
return 2; return 2;
@ -567,6 +567,7 @@ int git_connect(int fd[2], char *url, const char *prog)
int pipefd[2][2]; int pipefd[2][2];
pid_t pid; pid_t pid;
enum protocol protocol = PROTO_LOCAL; enum protocol protocol = PROTO_LOCAL;
int free_path = 0;
host = strstr(url, "://"); host = strstr(url, "://");
if(host) { if(host) {
@ -610,16 +611,23 @@ int git_connect(int fd[2], char *url, const char *prog)
char *ptr = path; char *ptr = path;
if (path[1] == '~') if (path[1] == '~')
path++; path++;
else else {
path = strdup(ptr); path = strdup(ptr);
free_path = 1;
}
*ptr = '\0'; *ptr = '\0';
} }
if (protocol == PROTO_GIT) { if (protocol == PROTO_GIT) {
int ret;
if (git_use_proxy(host)) if (git_use_proxy(host))
return git_proxy_connect(fd, prog, host, path); ret = git_proxy_connect(fd, prog, host, path);
return git_tcp_connect(fd, prog, host, path); else
ret = git_tcp_connect(fd, prog, host, path);
if (free_path)
free(path);
return ret;
} }
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0) if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
@ -659,6 +667,8 @@ int git_connect(int fd[2], char *url, const char *prog)
fd[1] = pipefd[1][1]; fd[1] = pipefd[1][1];
close(pipefd[0][1]); close(pipefd[0][1]);
close(pipefd[1][0]); close(pipefd[1][0]);
if (free_path)
free(path);
return pid; return pid;
} }

View File

@ -32,7 +32,7 @@ const char *git_exec_path(void)
int execv_git_cmd(const char **argv) int execv_git_cmd(const char **argv)
{ {
char git_command[PATH_MAX + 1]; char git_command[PATH_MAX + 1];
int len, err, i; int len, i;
const char *paths[] = { current_exec_path, const char *paths[] = { current_exec_path,
getenv("GIT_EXEC_PATH"), getenv("GIT_EXEC_PATH"),
builtin_exec_path }; builtin_exec_path };
@ -85,8 +85,6 @@ int execv_git_cmd(const char **argv)
/* execve() can only ever return if it fails */ /* execve() can only ever return if it fails */
execve(git_command, (char **)argv, environ); execve(git_command, (char **)argv, environ);
err = errno;
argv[0] = tmp; argv[0] = tmp;
} }
return -1; return -1;

View File

@ -144,8 +144,6 @@ static int quote_c_style_counted(const char *name, int namelen,
case '\\': /* fallthru */ case '\\': /* fallthru */
case '"': EMITQ(); break; case '"': EMITQ(); break;
case ' ':
break;
default: default:
/* octal */ /* octal */
EMITQ(); EMITQ();

View File

@ -874,17 +874,19 @@ void packed_object_info_detail(struct pack_entry *e,
unsigned char *base_sha1) unsigned char *base_sha1)
{ {
struct packed_git *p = e->p; struct packed_git *p = e->p;
unsigned long offset, left; unsigned long offset;
unsigned char *pack; unsigned char *pack;
enum object_type kind; enum object_type kind;
offset = unpack_object_header(p, e->offset, &kind, size); offset = unpack_object_header(p, e->offset, &kind, size);
pack = p->pack_base + offset; pack = p->pack_base + offset;
left = p->pack_size - offset;
if (kind != OBJ_DELTA) if (kind != OBJ_DELTA)
*delta_chain_length = 0; *delta_chain_length = 0;
else { else {
unsigned int chain_length = 0; unsigned int chain_length = 0;
if (p->pack_size <= offset + 20)
die("pack file %s records an incomplete delta base",
p->pack_name);
memcpy(base_sha1, pack, 20); memcpy(base_sha1, pack, 20);
do { do {
struct pack_entry base_ent; struct pack_entry base_ent;