зеркало из https://github.com/microsoft/git.git
Merge branch 'jk/war-on-sprintf'
Many allocations that is manually counted (correctly) that are followed by strcpy/sprintf have been replaced with a less error prone constructs such as xstrfmt. Macintosh-specific breakage was noticed and corrected in this reroll. * jk/war-on-sprintf: (70 commits) name-rev: use strip_suffix to avoid magic numbers use strbuf_complete to conditionally append slash fsck: use for_each_loose_file_in_objdir Makefile: drop D_INO_IN_DIRENT build knob fsck: drop inode-sorting code convert strncpy to memcpy notes: document length of fanout path with a constant color: add color_set helper for copying raw colors prefer memcpy to strcpy help: clean up kfmclient munging receive-pack: simplify keep_arg computation avoid sprintf and strcpy with flex arrays use alloc_ref rather than hand-allocating "struct ref" color: add overflow checks for parsing colors drop strcpy in favor of raw sha1_to_hex use sha1_to_hex_r() instead of strcpy daemon: use cld->env_array when re-spawning stat_tracking_info: convert to argv_array http-push: use an argv_array for setup_revisions fetch-pack: use argv_array for index-pack / unpack-objects ...
This commit is contained in:
Коммит
78891795df
5
Makefile
5
Makefile
|
@ -74,8 +74,6 @@ all::
|
||||||
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
|
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
|
||||||
# it specifies.
|
# it specifies.
|
||||||
#
|
#
|
||||||
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
|
|
||||||
#
|
|
||||||
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
|
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
|
||||||
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
|
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
|
||||||
#
|
#
|
||||||
|
@ -1164,9 +1162,6 @@ endif
|
||||||
ifdef NO_D_TYPE_IN_DIRENT
|
ifdef NO_D_TYPE_IN_DIRENT
|
||||||
BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
|
BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
|
||||||
endif
|
endif
|
||||||
ifdef NO_D_INO_IN_DIRENT
|
|
||||||
BASIC_CFLAGS += -DNO_D_INO_IN_DIRENT
|
|
||||||
endif
|
|
||||||
ifdef NO_GECOS_IN_PWENT
|
ifdef NO_GECOS_IN_PWENT
|
||||||
BASIC_CFLAGS += -DNO_GECOS_IN_PWENT
|
BASIC_CFLAGS += -DNO_GECOS_IN_PWENT
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -167,21 +167,21 @@ static void prepare_header(struct archiver_args *args,
|
||||||
struct ustar_header *header,
|
struct ustar_header *header,
|
||||||
unsigned int mode, unsigned long size)
|
unsigned int mode, unsigned long size)
|
||||||
{
|
{
|
||||||
sprintf(header->mode, "%07o", mode & 07777);
|
xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
|
||||||
sprintf(header->size, "%011lo", S_ISREG(mode) ? size : 0);
|
xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
|
||||||
sprintf(header->mtime, "%011lo", (unsigned long) args->time);
|
xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
|
||||||
|
|
||||||
sprintf(header->uid, "%07o", 0);
|
xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);
|
||||||
sprintf(header->gid, "%07o", 0);
|
xsnprintf(header->gid, sizeof(header->gid), "%07o", 0);
|
||||||
strlcpy(header->uname, "root", sizeof(header->uname));
|
strlcpy(header->uname, "root", sizeof(header->uname));
|
||||||
strlcpy(header->gname, "root", sizeof(header->gname));
|
strlcpy(header->gname, "root", sizeof(header->gname));
|
||||||
sprintf(header->devmajor, "%07o", 0);
|
xsnprintf(header->devmajor, sizeof(header->devmajor), "%07o", 0);
|
||||||
sprintf(header->devminor, "%07o", 0);
|
xsnprintf(header->devminor, sizeof(header->devminor), "%07o", 0);
|
||||||
|
|
||||||
memcpy(header->magic, "ustar", 6);
|
memcpy(header->magic, "ustar", 6);
|
||||||
memcpy(header->version, "00", 2);
|
memcpy(header->version, "00", 2);
|
||||||
|
|
||||||
sprintf(header->chksum, "%07o", ustar_header_chksum(header));
|
snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_extended_header(struct archiver_args *args,
|
static int write_extended_header(struct archiver_args *args,
|
||||||
|
@ -193,7 +193,7 @@ static int write_extended_header(struct archiver_args *args,
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
*header.typeflag = TYPEFLAG_EXT_HEADER;
|
*header.typeflag = TYPEFLAG_EXT_HEADER;
|
||||||
mode = 0100666;
|
mode = 0100666;
|
||||||
sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
|
xsnprintf(header.name, sizeof(header.name), "%s.paxheader", sha1_to_hex(sha1));
|
||||||
prepare_header(args, &header, mode, size);
|
prepare_header(args, &header, mode, size);
|
||||||
write_blocked(&header, sizeof(header));
|
write_blocked(&header, sizeof(header));
|
||||||
write_blocked(buffer, size);
|
write_blocked(buffer, size);
|
||||||
|
@ -235,7 +235,7 @@ static int write_tar_entry(struct archiver_args *args,
|
||||||
memcpy(header.prefix, path, plen);
|
memcpy(header.prefix, path, plen);
|
||||||
memcpy(header.name, path + plen + 1, rest);
|
memcpy(header.name, path + plen + 1, rest);
|
||||||
} else {
|
} else {
|
||||||
sprintf(header.name, "%s.data",
|
xsnprintf(header.name, sizeof(header.name), "%s.data",
|
||||||
sha1_to_hex(sha1));
|
sha1_to_hex(sha1));
|
||||||
strbuf_append_ext_header(&ext_header, "path",
|
strbuf_append_ext_header(&ext_header, "path",
|
||||||
path, pathlen);
|
path, pathlen);
|
||||||
|
@ -259,8 +259,8 @@ static int write_tar_entry(struct archiver_args *args,
|
||||||
|
|
||||||
if (S_ISLNK(mode)) {
|
if (S_ISLNK(mode)) {
|
||||||
if (size > sizeof(header.linkname)) {
|
if (size > sizeof(header.linkname)) {
|
||||||
sprintf(header.linkname, "see %s.paxheader",
|
xsnprintf(header.linkname, sizeof(header.linkname),
|
||||||
sha1_to_hex(sha1));
|
"see %s.paxheader", sha1_to_hex(sha1));
|
||||||
strbuf_append_ext_header(&ext_header, "linkpath",
|
strbuf_append_ext_header(&ext_header, "linkpath",
|
||||||
buffer, size);
|
buffer, size);
|
||||||
} else
|
} else
|
||||||
|
@ -301,7 +301,7 @@ static int write_global_extended_header(struct archiver_args *args)
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
*header.typeflag = TYPEFLAG_GLOBAL_HEADER;
|
*header.typeflag = TYPEFLAG_GLOBAL_HEADER;
|
||||||
mode = 0100666;
|
mode = 0100666;
|
||||||
strcpy(header.name, "pax_global_header");
|
xsnprintf(header.name, sizeof(header.name), "pax_global_header");
|
||||||
prepare_header(args, &header, mode, ext_header.len);
|
prepare_header(args, &header, mode, ext_header.len);
|
||||||
write_blocked(&header, sizeof(header));
|
write_blocked(&header, sizeof(header));
|
||||||
write_blocked(ext_header.buf, ext_header.len);
|
write_blocked(ext_header.buf, ext_header.len);
|
||||||
|
|
|
@ -171,13 +171,14 @@ static void queue_directory(const unsigned char *sha1,
|
||||||
unsigned mode, int stage, struct archiver_context *c)
|
unsigned mode, int stage, struct archiver_context *c)
|
||||||
{
|
{
|
||||||
struct directory *d;
|
struct directory *d;
|
||||||
d = xmallocz(sizeof(*d) + base->len + 1 + strlen(filename));
|
size_t len = base->len + 1 + strlen(filename) + 1;
|
||||||
|
d = xmalloc(sizeof(*d) + len);
|
||||||
d->up = c->bottom;
|
d->up = c->bottom;
|
||||||
d->baselen = base->len;
|
d->baselen = base->len;
|
||||||
d->mode = mode;
|
d->mode = mode;
|
||||||
d->stage = stage;
|
d->stage = stage;
|
||||||
c->bottom = d;
|
c->bottom = d;
|
||||||
d->len = sprintf(d->path, "%.*s%s/", (int)base->len, base->buf, filename);
|
d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
|
||||||
hashcpy(d->oid.hash, sha1);
|
hashcpy(d->oid.hash, sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,7 @@ static enum ws_ignore {
|
||||||
|
|
||||||
|
|
||||||
static const char *patch_input_file;
|
static const char *patch_input_file;
|
||||||
static const char *root;
|
static struct strbuf root = STRBUF_INIT;
|
||||||
static int root_len;
|
|
||||||
static int read_stdin = 1;
|
static int read_stdin = 1;
|
||||||
static int options;
|
static int options;
|
||||||
|
|
||||||
|
@ -494,8 +493,8 @@ static char *find_name_gnu(const char *line, const char *def, int p_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_remove(&name, 0, cp - name.buf);
|
strbuf_remove(&name, 0, cp - name.buf);
|
||||||
if (root)
|
if (root.len)
|
||||||
strbuf_insert(&name, 0, root, root_len);
|
strbuf_insert(&name, 0, root.buf, root.len);
|
||||||
return squash_slash(strbuf_detach(&name, NULL));
|
return squash_slash(strbuf_detach(&name, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,11 +696,8 @@ static char *find_name_common(const char *line, const char *def,
|
||||||
return squash_slash(xstrdup(def));
|
return squash_slash(xstrdup(def));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root.len) {
|
||||||
char *ret = xmalloc(root_len + len + 1);
|
char *ret = xstrfmt("%s%.*s", root.buf, len, start);
|
||||||
strcpy(ret, root);
|
|
||||||
memcpy(ret + root_len, start, len);
|
|
||||||
ret[root_len + len] = '\0';
|
|
||||||
return squash_slash(ret);
|
return squash_slash(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1277,8 +1273,8 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
|
||||||
* the default name from the header.
|
* the default name from the header.
|
||||||
*/
|
*/
|
||||||
patch->def_name = git_header_name(line, len);
|
patch->def_name = git_header_name(line, len);
|
||||||
if (patch->def_name && root) {
|
if (patch->def_name && root.len) {
|
||||||
char *s = xstrfmt("%s%s", root, patch->def_name);
|
char *s = xstrfmt("%s%s", root.buf, patch->def_name);
|
||||||
free(patch->def_name);
|
free(patch->def_name);
|
||||||
patch->def_name = s;
|
patch->def_name = s;
|
||||||
}
|
}
|
||||||
|
@ -4501,14 +4497,9 @@ static int option_parse_whitespace(const struct option *opt,
|
||||||
static int option_parse_directory(const struct option *opt,
|
static int option_parse_directory(const struct option *opt,
|
||||||
const char *arg, int unset)
|
const char *arg, int unset)
|
||||||
{
|
{
|
||||||
root_len = strlen(arg);
|
strbuf_reset(&root);
|
||||||
if (root_len && arg[root_len - 1] != '/') {
|
strbuf_addstr(&root, arg);
|
||||||
char *new_root;
|
strbuf_complete(&root, '/');
|
||||||
root = new_root = xmalloc(root_len + 2);
|
|
||||||
strcpy(new_root, arg);
|
|
||||||
strcpy(new_root + root_len++, "/");
|
|
||||||
} else
|
|
||||||
root = arg;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -459,12 +459,13 @@ static void queue_blames(struct scoreboard *sb, struct origin *porigin,
|
||||||
static struct origin *make_origin(struct commit *commit, const char *path)
|
static struct origin *make_origin(struct commit *commit, const char *path)
|
||||||
{
|
{
|
||||||
struct origin *o;
|
struct origin *o;
|
||||||
o = xcalloc(1, sizeof(*o) + strlen(path) + 1);
|
size_t pathlen = strlen(path) + 1;
|
||||||
|
o = xcalloc(1, sizeof(*o) + pathlen);
|
||||||
o->commit = commit;
|
o->commit = commit;
|
||||||
o->refcnt = 1;
|
o->refcnt = 1;
|
||||||
o->next = commit->util;
|
o->next = commit->util;
|
||||||
commit->util = o;
|
commit->util = o;
|
||||||
strcpy(o->path, path);
|
memcpy(o->path, path, pathlen); /* includes NUL */
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1879,9 +1880,9 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
|
||||||
int cnt;
|
int cnt;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
struct origin *suspect = ent->suspect;
|
struct origin *suspect = ent->suspect;
|
||||||
char hex[41];
|
char hex[GIT_SHA1_HEXSZ + 1];
|
||||||
|
|
||||||
strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
|
sha1_to_hex_r(hex, suspect->commit->object.sha1);
|
||||||
printf("%s %d %d %d\n",
|
printf("%s %d %d %d\n",
|
||||||
hex,
|
hex,
|
||||||
ent->s_lno + 1,
|
ent->s_lno + 1,
|
||||||
|
@ -1917,11 +1918,11 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
|
||||||
const char *cp;
|
const char *cp;
|
||||||
struct origin *suspect = ent->suspect;
|
struct origin *suspect = ent->suspect;
|
||||||
struct commit_info ci;
|
struct commit_info ci;
|
||||||
char hex[41];
|
char hex[GIT_SHA1_HEXSZ + 1];
|
||||||
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
|
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
|
||||||
|
|
||||||
get_commit_info(suspect->commit, &ci, 1);
|
get_commit_info(suspect->commit, &ci, 1);
|
||||||
strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
|
sha1_to_hex_r(hex, suspect->commit->object.sha1);
|
||||||
|
|
||||||
cp = nth_line(sb, ent->lno);
|
cp = nth_line(sb, ent->lno);
|
||||||
for (cnt = 0; cnt < ent->num_lines; cnt++) {
|
for (cnt = 0; cnt < ent->num_lines; cnt++) {
|
||||||
|
|
|
@ -159,8 +159,7 @@ static int is_git_repository(struct strbuf *path)
|
||||||
int gitfile_error;
|
int gitfile_error;
|
||||||
size_t orig_path_len = path->len;
|
size_t orig_path_len = path->len;
|
||||||
assert(orig_path_len != 0);
|
assert(orig_path_len != 0);
|
||||||
if (path->buf[orig_path_len - 1] != '/')
|
strbuf_complete(path, '/');
|
||||||
strbuf_addch(path, '/');
|
|
||||||
strbuf_addstr(path, ".git");
|
strbuf_addstr(path, ".git");
|
||||||
if (read_gitfile_gently(path->buf, &gitfile_error) || is_git_directory(path->buf))
|
if (read_gitfile_gently(path->buf, &gitfile_error) || is_git_directory(path->buf))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -206,8 +205,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path->buf[original_len - 1] != '/')
|
strbuf_complete(path, '/');
|
||||||
strbuf_addch(path, '/');
|
|
||||||
|
|
||||||
len = path->len;
|
len = path->len;
|
||||||
while ((e = readdir(dir)) != NULL) {
|
while ((e = readdir(dir)) != NULL) {
|
||||||
|
|
|
@ -246,8 +246,6 @@ free_strings:
|
||||||
|
|
||||||
static char *normalize_value(const char *key, const char *value)
|
static char *normalize_value(const char *key, const char *value)
|
||||||
{
|
{
|
||||||
char *normalized;
|
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -258,27 +256,21 @@ static char *normalize_value(const char *key, const char *value)
|
||||||
* "~/foobar/" in the config file, and to expand the ~
|
* "~/foobar/" in the config file, and to expand the ~
|
||||||
* when retrieving the value.
|
* when retrieving the value.
|
||||||
*/
|
*/
|
||||||
normalized = xstrdup(value);
|
return xstrdup(value);
|
||||||
else {
|
if (types == TYPE_INT)
|
||||||
normalized = xmalloc(64);
|
return xstrfmt("%"PRId64, git_config_int64(key, value));
|
||||||
if (types == TYPE_INT) {
|
if (types == TYPE_BOOL)
|
||||||
int64_t v = git_config_int64(key, value);
|
return xstrdup(git_config_bool(key, value) ? "true" : "false");
|
||||||
sprintf(normalized, "%"PRId64, v);
|
if (types == TYPE_BOOL_OR_INT) {
|
||||||
}
|
|
||||||
else if (types == TYPE_BOOL)
|
|
||||||
sprintf(normalized, "%s",
|
|
||||||
git_config_bool(key, value) ? "true" : "false");
|
|
||||||
else if (types == TYPE_BOOL_OR_INT) {
|
|
||||||
int is_bool, v;
|
int is_bool, v;
|
||||||
v = git_config_bool_or_int(key, value, &is_bool);
|
v = git_config_bool_or_int(key, value, &is_bool);
|
||||||
if (!is_bool)
|
if (!is_bool)
|
||||||
sprintf(normalized, "%d", v);
|
return xstrfmt("%d", v);
|
||||||
else
|
else
|
||||||
sprintf(normalized, "%s", v ? "true" : "false");
|
return xstrdup(v ? "true" : "false");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalized;
|
die("BUG: cannot normalize type %d", types);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_color_found;
|
static int get_color_found;
|
||||||
|
|
|
@ -528,36 +528,38 @@ static int update_local_ref(struct ref *ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_merge_bases(current, updated)) {
|
if (in_merge_bases(current, updated)) {
|
||||||
char quickref[83];
|
struct strbuf quickref = STRBUF_INIT;
|
||||||
int r;
|
int r;
|
||||||
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
|
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
|
||||||
strcat(quickref, "..");
|
strbuf_addstr(&quickref, "..");
|
||||||
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
|
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
|
||||||
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
||||||
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
||||||
check_for_new_submodule_commits(ref->new_sha1);
|
check_for_new_submodule_commits(ref->new_sha1);
|
||||||
r = s_update_ref("fast-forward", ref, 1);
|
r = s_update_ref("fast-forward", ref, 1);
|
||||||
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
|
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
|
||||||
r ? '!' : ' ',
|
r ? '!' : ' ',
|
||||||
TRANSPORT_SUMMARY_WIDTH, quickref,
|
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
|
||||||
REFCOL_WIDTH, remote, pretty_ref,
|
REFCOL_WIDTH, remote, pretty_ref,
|
||||||
r ? _(" (unable to update local ref)") : "");
|
r ? _(" (unable to update local ref)") : "");
|
||||||
|
strbuf_release(&quickref);
|
||||||
return r;
|
return r;
|
||||||
} else if (force || ref->force) {
|
} else if (force || ref->force) {
|
||||||
char quickref[84];
|
struct strbuf quickref = STRBUF_INIT;
|
||||||
int r;
|
int r;
|
||||||
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
|
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
|
||||||
strcat(quickref, "...");
|
strbuf_addstr(&quickref, "...");
|
||||||
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
|
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
|
||||||
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
|
||||||
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
(recurse_submodules != RECURSE_SUBMODULES_ON))
|
||||||
check_for_new_submodule_commits(ref->new_sha1);
|
check_for_new_submodule_commits(ref->new_sha1);
|
||||||
r = s_update_ref("forced-update", ref, 1);
|
r = s_update_ref("forced-update", ref, 1);
|
||||||
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
|
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
|
||||||
r ? '!' : '+',
|
r ? '!' : '+',
|
||||||
TRANSPORT_SUMMARY_WIDTH, quickref,
|
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
|
||||||
REFCOL_WIDTH, remote, pretty_ref,
|
REFCOL_WIDTH, remote, pretty_ref,
|
||||||
r ? _("unable to update local ref") : _("forced update"));
|
r ? _("unable to update local ref") : _("forced update"));
|
||||||
|
strbuf_release(&quickref);
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
strbuf_addf(display, "! %-*s %-*s -> %s %s",
|
strbuf_addf(display, "! %-*s %-*s -> %s %s",
|
||||||
|
@ -637,8 +639,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (rm->peer_ref) {
|
if (rm->peer_ref) {
|
||||||
ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
|
ref = alloc_ref(rm->peer_ref->name);
|
||||||
strcpy(ref->name, rm->peer_ref->name);
|
|
||||||
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
|
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
|
||||||
hashcpy(ref->new_sha1, rm->old_sha1);
|
hashcpy(ref->new_sha1, rm->old_sha1);
|
||||||
ref->force = rm->peer_ref->force;
|
ref->force = rm->peer_ref->force;
|
||||||
|
@ -1156,11 +1157,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
|
||||||
die(_("--depth and --unshallow cannot be used together"));
|
die(_("--depth and --unshallow cannot be used together"));
|
||||||
else if (!is_repository_shallow())
|
else if (!is_repository_shallow())
|
||||||
die(_("--unshallow on a complete repository does not make sense"));
|
die(_("--unshallow on a complete repository does not make sense"));
|
||||||
else {
|
else
|
||||||
static char inf_depth[12];
|
depth = xstrfmt("%d", INFINITE_DEPTH);
|
||||||
sprintf(inf_depth, "%d", INFINITE_DEPTH);
|
|
||||||
depth = inf_depth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no need to be strict, transport_set_option() will validate it again */
|
/* no need to be strict, transport_set_option() will validate it again */
|
||||||
|
|
150
builtin/fsck.c
150
builtin/fsck.c
|
@ -40,14 +40,6 @@ static int show_dangling = 1;
|
||||||
#define ERROR_PACK 04
|
#define ERROR_PACK 04
|
||||||
#define ERROR_REFS 010
|
#define ERROR_REFS 010
|
||||||
|
|
||||||
#ifdef NO_D_INO_IN_DIRENT
|
|
||||||
#define SORT_DIRENT 0
|
|
||||||
#define DIRENT_SORT_HINT(de) 0
|
|
||||||
#else
|
|
||||||
#define SORT_DIRENT 1
|
|
||||||
#define DIRENT_SORT_HINT(de) ((de)->d_ino)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int fsck_config(const char *var, const char *value, void *cb)
|
static int fsck_config(const char *var, const char *value, void *cb)
|
||||||
{
|
{
|
||||||
if (strcmp(var, "fsck.skiplist") == 0) {
|
if (strcmp(var, "fsck.skiplist") == 0) {
|
||||||
|
@ -374,102 +366,6 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
|
||||||
return fsck_obj(obj);
|
return fsck_obj(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This is the sorting chunk size: make it reasonably
|
|
||||||
* big so that we can sort well..
|
|
||||||
*/
|
|
||||||
#define MAX_SHA1_ENTRIES (1024)
|
|
||||||
|
|
||||||
struct sha1_entry {
|
|
||||||
unsigned long ino;
|
|
||||||
unsigned char sha1[20];
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
unsigned long nr;
|
|
||||||
struct sha1_entry *entry[MAX_SHA1_ENTRIES];
|
|
||||||
} sha1_list;
|
|
||||||
|
|
||||||
static int ino_compare(const void *_a, const void *_b)
|
|
||||||
{
|
|
||||||
const struct sha1_entry *a = _a, *b = _b;
|
|
||||||
unsigned long ino1 = a->ino, ino2 = b->ino;
|
|
||||||
return ino1 < ino2 ? -1 : ino1 > ino2 ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fsck_sha1_list(void)
|
|
||||||
{
|
|
||||||
int i, nr = sha1_list.nr;
|
|
||||||
|
|
||||||
if (SORT_DIRENT)
|
|
||||||
qsort(sha1_list.entry, nr,
|
|
||||||
sizeof(struct sha1_entry *), ino_compare);
|
|
||||||
for (i = 0; i < nr; i++) {
|
|
||||||
struct sha1_entry *entry = sha1_list.entry[i];
|
|
||||||
unsigned char *sha1 = entry->sha1;
|
|
||||||
|
|
||||||
sha1_list.entry[i] = NULL;
|
|
||||||
if (fsck_sha1(sha1))
|
|
||||||
errors_found |= ERROR_OBJECT;
|
|
||||||
free(entry);
|
|
||||||
}
|
|
||||||
sha1_list.nr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_sha1_list(unsigned char *sha1, unsigned long ino)
|
|
||||||
{
|
|
||||||
struct sha1_entry *entry = xmalloc(sizeof(*entry));
|
|
||||||
int nr;
|
|
||||||
|
|
||||||
entry->ino = ino;
|
|
||||||
hashcpy(entry->sha1, sha1);
|
|
||||||
nr = sha1_list.nr;
|
|
||||||
if (nr == MAX_SHA1_ENTRIES) {
|
|
||||||
fsck_sha1_list();
|
|
||||||
nr = 0;
|
|
||||||
}
|
|
||||||
sha1_list.entry[nr] = entry;
|
|
||||||
sha1_list.nr = ++nr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int is_loose_object_file(struct dirent *de,
|
|
||||||
char *name, unsigned char *sha1)
|
|
||||||
{
|
|
||||||
if (strlen(de->d_name) != 38)
|
|
||||||
return 0;
|
|
||||||
memcpy(name + 2, de->d_name, 39);
|
|
||||||
return !get_sha1_hex(name, sha1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fsck_dir(int i, char *path)
|
|
||||||
{
|
|
||||||
DIR *dir = opendir(path);
|
|
||||||
struct dirent *de;
|
|
||||||
char name[100];
|
|
||||||
|
|
||||||
if (!dir)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
fprintf(stderr, "Checking directory %s\n", path);
|
|
||||||
|
|
||||||
sprintf(name, "%02x", i);
|
|
||||||
while ((de = readdir(dir)) != NULL) {
|
|
||||||
unsigned char sha1[20];
|
|
||||||
|
|
||||||
if (is_dot_or_dotdot(de->d_name))
|
|
||||||
continue;
|
|
||||||
if (is_loose_object_file(de, name, sha1)) {
|
|
||||||
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (starts_with(de->d_name, "tmp_obj_"))
|
|
||||||
continue;
|
|
||||||
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int default_refs;
|
static int default_refs;
|
||||||
|
|
||||||
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
|
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
|
||||||
|
@ -559,9 +455,28 @@ static void get_default_heads(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fsck_loose(const unsigned char *sha1, const char *path, void *data)
|
||||||
|
{
|
||||||
|
if (fsck_sha1(sha1))
|
||||||
|
errors_found |= ERROR_OBJECT;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsck_cruft(const char *basename, const char *path, void *data)
|
||||||
|
{
|
||||||
|
if (!starts_with(basename, "tmp_obj_"))
|
||||||
|
fprintf(stderr, "bad sha1 file: %s\n", path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsck_subdir(int nr, const char *path, void *progress)
|
||||||
|
{
|
||||||
|
display_progress(progress, nr + 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void fsck_object_dir(const char *path)
|
static void fsck_object_dir(const char *path)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
struct progress *progress = NULL;
|
struct progress *progress = NULL;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
@ -569,14 +484,11 @@ static void fsck_object_dir(const char *path)
|
||||||
|
|
||||||
if (show_progress)
|
if (show_progress)
|
||||||
progress = start_progress(_("Checking object directories"), 256);
|
progress = start_progress(_("Checking object directories"), 256);
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
static char dir[4096];
|
for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
|
||||||
sprintf(dir, "%s/%02x", path, i);
|
progress);
|
||||||
fsck_dir(i, dir);
|
display_progress(progress, 256);
|
||||||
display_progress(progress, i+1);
|
|
||||||
}
|
|
||||||
stop_progress(&progress);
|
stop_progress(&progress);
|
||||||
fsck_sha1_list();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsck_head_link(void)
|
static int fsck_head_link(void)
|
||||||
|
@ -688,16 +600,18 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
||||||
git_config(fsck_config, NULL);
|
git_config(fsck_config, NULL);
|
||||||
|
|
||||||
fsck_head_link();
|
fsck_head_link();
|
||||||
if (!connectivity_only)
|
if (!connectivity_only) {
|
||||||
fsck_object_dir(get_object_directory());
|
fsck_object_dir(get_object_directory());
|
||||||
|
|
||||||
prepare_alt_odb();
|
prepare_alt_odb();
|
||||||
for (alt = alt_odb_list; alt; alt = alt->next) {
|
for (alt = alt_odb_list; alt; alt = alt->next) {
|
||||||
char namebuf[PATH_MAX];
|
/* directory name, minus trailing slash */
|
||||||
int namelen = alt->name - alt->base;
|
size_t namelen = alt->name - alt->base - 1;
|
||||||
memcpy(namebuf, alt->base, namelen);
|
struct strbuf name = STRBUF_INIT;
|
||||||
namebuf[namelen - 1] = 0;
|
strbuf_add(&name, alt->base, namelen);
|
||||||
fsck_object_dir(namebuf);
|
fsck_object_dir(name.buf);
|
||||||
|
strbuf_release(&name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_full) {
|
if (check_full) {
|
||||||
|
|
|
@ -217,7 +217,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (gethostname(my_host, sizeof(my_host)))
|
if (gethostname(my_host, sizeof(my_host)))
|
||||||
strcpy(my_host, "unknown");
|
xsnprintf(my_host, sizeof(my_host), "unknown");
|
||||||
|
|
||||||
pidfile_path = git_pathdup("gc.pid");
|
pidfile_path = git_pathdup("gc.pid");
|
||||||
fd = hold_lock_file_for_update(&lock, pidfile_path,
|
fd = hold_lock_file_for_update(&lock, pidfile_path,
|
||||||
|
|
|
@ -140,17 +140,10 @@ static void exec_man_konqueror(const char *path, const char *page)
|
||||||
|
|
||||||
/* It's simpler to launch konqueror using kfmclient. */
|
/* It's simpler to launch konqueror using kfmclient. */
|
||||||
if (path) {
|
if (path) {
|
||||||
const char *file = strrchr(path, '/');
|
size_t len;
|
||||||
if (file && !strcmp(file + 1, "konqueror")) {
|
if (strip_suffix(path, "/konqueror", &len))
|
||||||
char *new = xstrdup(path);
|
path = xstrfmt("%.*s/kfmclient", (int)len, path);
|
||||||
char *dest = strrchr(new, '/');
|
filename = basename((char *)path);
|
||||||
|
|
||||||
/* strlen("konqueror") == strlen("kfmclient") */
|
|
||||||
strcpy(dest + 1, "kfmclient");
|
|
||||||
path = new;
|
|
||||||
}
|
|
||||||
if (file)
|
|
||||||
filename = file;
|
|
||||||
} else
|
} else
|
||||||
path = "kfmclient";
|
path = "kfmclient";
|
||||||
strbuf_addf(&man_page, "man:%s(1)", page);
|
strbuf_addf(&man_page, "man:%s(1)", page);
|
||||||
|
@ -183,7 +176,7 @@ static void add_man_viewer(const char *name)
|
||||||
while (*p)
|
while (*p)
|
||||||
p = &((*p)->next);
|
p = &((*p)->next);
|
||||||
*p = xcalloc(1, (sizeof(**p) + len + 1));
|
*p = xcalloc(1, (sizeof(**p) + len + 1));
|
||||||
strncpy((*p)->name, name, len);
|
memcpy((*p)->name, name, len); /* NUL-terminated by xcalloc */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int supported_man_viewer(const char *name, size_t len)
|
static int supported_man_viewer(const char *name, size_t len)
|
||||||
|
@ -199,7 +192,7 @@ static void do_add_man_viewer_info(const char *name,
|
||||||
{
|
{
|
||||||
struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
|
struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
|
||||||
|
|
||||||
strncpy(new->name, name, len);
|
memcpy(new->name, name, len); /* NUL-terminated by xcalloc */
|
||||||
new->info = xstrdup(value);
|
new->info = xstrdup(value);
|
||||||
new->next = man_viewer_info_list;
|
new->next = man_viewer_info_list;
|
||||||
man_viewer_info_list = new;
|
man_viewer_info_list = new;
|
||||||
|
@ -295,16 +288,6 @@ static int is_git_command(const char *s)
|
||||||
is_in_cmdlist(&other_cmds, s);
|
is_in_cmdlist(&other_cmds, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *prepend(const char *prefix, const char *cmd)
|
|
||||||
{
|
|
||||||
size_t pre_len = strlen(prefix);
|
|
||||||
size_t cmd_len = strlen(cmd);
|
|
||||||
char *p = xmalloc(pre_len + cmd_len + 1);
|
|
||||||
memcpy(p, prefix, pre_len);
|
|
||||||
strcpy(p + pre_len, cmd);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *cmd_to_page(const char *git_cmd)
|
static const char *cmd_to_page(const char *git_cmd)
|
||||||
{
|
{
|
||||||
if (!git_cmd)
|
if (!git_cmd)
|
||||||
|
@ -312,9 +295,9 @@ static const char *cmd_to_page(const char *git_cmd)
|
||||||
else if (starts_with(git_cmd, "git"))
|
else if (starts_with(git_cmd, "git"))
|
||||||
return git_cmd;
|
return git_cmd;
|
||||||
else if (is_git_command(git_cmd))
|
else if (is_git_command(git_cmd))
|
||||||
return prepend("git-", git_cmd);
|
return xstrfmt("git-%s", git_cmd);
|
||||||
else
|
else
|
||||||
return prepend("git", git_cmd);
|
return xstrfmt("git%s", git_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_man_path(void)
|
static void setup_man_path(void)
|
||||||
|
|
|
@ -441,7 +441,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
if (!is_delta_type(type)) {
|
if (!is_delta_type(type)) {
|
||||||
hdrlen = sprintf(hdr, "%s %lu", typename(type), size) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), size) + 1;
|
||||||
git_SHA1_Init(&c);
|
git_SHA1_Init(&c);
|
||||||
git_SHA1_Update(&c, hdr, hdrlen);
|
git_SHA1_Update(&c, hdr, hdrlen);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -36,10 +36,11 @@ static void safe_create_dir(const char *dir, int share)
|
||||||
die(_("Could not make %s writable by group"), dir);
|
die(_("Could not make %s writable by group"), dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_templates_1(char *path, int baselen,
|
static void copy_templates_1(struct strbuf *path, struct strbuf *template,
|
||||||
char *template, int template_baselen,
|
|
||||||
DIR *dir)
|
DIR *dir)
|
||||||
{
|
{
|
||||||
|
size_t path_baselen = path->len;
|
||||||
|
size_t template_baselen = template->len;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
|
|
||||||
/* Note: if ".git/hooks" file exists in the repository being
|
/* Note: if ".git/hooks" file exists in the repository being
|
||||||
|
@ -49,77 +50,64 @@ static void copy_templates_1(char *path, int baselen,
|
||||||
* with the way the namespace under .git/ is organized, should
|
* with the way the namespace under .git/ is organized, should
|
||||||
* be really carefully chosen.
|
* be really carefully chosen.
|
||||||
*/
|
*/
|
||||||
safe_create_dir(path, 1);
|
safe_create_dir(path->buf, 1);
|
||||||
while ((de = readdir(dir)) != NULL) {
|
while ((de = readdir(dir)) != NULL) {
|
||||||
struct stat st_git, st_template;
|
struct stat st_git, st_template;
|
||||||
int namelen;
|
|
||||||
int exists = 0;
|
int exists = 0;
|
||||||
|
|
||||||
|
strbuf_setlen(path, path_baselen);
|
||||||
|
strbuf_setlen(template, template_baselen);
|
||||||
|
|
||||||
if (de->d_name[0] == '.')
|
if (de->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
namelen = strlen(de->d_name);
|
strbuf_addstr(path, de->d_name);
|
||||||
if ((PATH_MAX <= baselen + namelen) ||
|
strbuf_addstr(template, de->d_name);
|
||||||
(PATH_MAX <= template_baselen + namelen))
|
if (lstat(path->buf, &st_git)) {
|
||||||
die(_("insanely long template name %s"), de->d_name);
|
|
||||||
memcpy(path + baselen, de->d_name, namelen+1);
|
|
||||||
memcpy(template + template_baselen, de->d_name, namelen+1);
|
|
||||||
if (lstat(path, &st_git)) {
|
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
die_errno(_("cannot stat '%s'"), path);
|
die_errno(_("cannot stat '%s'"), path->buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
exists = 1;
|
exists = 1;
|
||||||
|
|
||||||
if (lstat(template, &st_template))
|
if (lstat(template->buf, &st_template))
|
||||||
die_errno(_("cannot stat template '%s'"), template);
|
die_errno(_("cannot stat template '%s'"), template->buf);
|
||||||
|
|
||||||
if (S_ISDIR(st_template.st_mode)) {
|
if (S_ISDIR(st_template.st_mode)) {
|
||||||
DIR *subdir = opendir(template);
|
DIR *subdir = opendir(template->buf);
|
||||||
int baselen_sub = baselen + namelen;
|
|
||||||
int template_baselen_sub = template_baselen + namelen;
|
|
||||||
if (!subdir)
|
if (!subdir)
|
||||||
die_errno(_("cannot opendir '%s'"), template);
|
die_errno(_("cannot opendir '%s'"), template->buf);
|
||||||
path[baselen_sub++] =
|
strbuf_addch(path, '/');
|
||||||
template[template_baselen_sub++] = '/';
|
strbuf_addch(template, '/');
|
||||||
path[baselen_sub] =
|
copy_templates_1(path, template, subdir);
|
||||||
template[template_baselen_sub] = 0;
|
|
||||||
copy_templates_1(path, baselen_sub,
|
|
||||||
template, template_baselen_sub,
|
|
||||||
subdir);
|
|
||||||
closedir(subdir);
|
closedir(subdir);
|
||||||
}
|
}
|
||||||
else if (exists)
|
else if (exists)
|
||||||
continue;
|
continue;
|
||||||
else if (S_ISLNK(st_template.st_mode)) {
|
else if (S_ISLNK(st_template.st_mode)) {
|
||||||
char lnk[256];
|
struct strbuf lnk = STRBUF_INIT;
|
||||||
int len;
|
if (strbuf_readlink(&lnk, template->buf, 0) < 0)
|
||||||
len = readlink(template, lnk, sizeof(lnk));
|
die_errno(_("cannot readlink '%s'"), template->buf);
|
||||||
if (len < 0)
|
if (symlink(lnk.buf, path->buf))
|
||||||
die_errno(_("cannot readlink '%s'"), template);
|
die_errno(_("cannot symlink '%s' '%s'"),
|
||||||
if (sizeof(lnk) <= len)
|
lnk.buf, path->buf);
|
||||||
die(_("insanely long symlink %s"), template);
|
strbuf_release(&lnk);
|
||||||
lnk[len] = 0;
|
|
||||||
if (symlink(lnk, path))
|
|
||||||
die_errno(_("cannot symlink '%s' '%s'"), lnk, path);
|
|
||||||
}
|
}
|
||||||
else if (S_ISREG(st_template.st_mode)) {
|
else if (S_ISREG(st_template.st_mode)) {
|
||||||
if (copy_file(path, template, st_template.st_mode))
|
if (copy_file(path->buf, template->buf, st_template.st_mode))
|
||||||
die_errno(_("cannot copy '%s' to '%s'"), template,
|
die_errno(_("cannot copy '%s' to '%s'"),
|
||||||
path);
|
template->buf, path->buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
error(_("ignoring template %s"), template);
|
error(_("ignoring template %s"), template->buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_templates(const char *template_dir)
|
static void copy_templates(const char *template_dir)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
struct strbuf path = STRBUF_INIT;
|
||||||
char template_path[PATH_MAX];
|
struct strbuf template_path = STRBUF_INIT;
|
||||||
int template_len;
|
size_t template_len;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
const char *git_dir = get_git_dir();
|
|
||||||
int len = strlen(git_dir);
|
|
||||||
char *to_free = NULL;
|
char *to_free = NULL;
|
||||||
|
|
||||||
if (!template_dir)
|
if (!template_dir)
|
||||||
|
@ -132,26 +120,23 @@ static void copy_templates(const char *template_dir)
|
||||||
free(to_free);
|
free(to_free);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
template_len = strlen(template_dir);
|
|
||||||
if (PATH_MAX <= (template_len+strlen("/config")))
|
strbuf_addstr(&template_path, template_dir);
|
||||||
die(_("insanely long template path %s"), template_dir);
|
strbuf_complete(&template_path, '/');
|
||||||
strcpy(template_path, template_dir);
|
template_len = template_path.len;
|
||||||
if (template_path[template_len-1] != '/') {
|
|
||||||
template_path[template_len++] = '/';
|
dir = opendir(template_path.buf);
|
||||||
template_path[template_len] = 0;
|
|
||||||
}
|
|
||||||
dir = opendir(template_path);
|
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
warning(_("templates not found %s"), template_dir);
|
warning(_("templates not found %s"), template_dir);
|
||||||
goto free_return;
|
goto free_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure that template is from the correct vintage */
|
/* Make sure that template is from the correct vintage */
|
||||||
strcpy(template_path + template_len, "config");
|
strbuf_addstr(&template_path, "config");
|
||||||
repository_format_version = 0;
|
repository_format_version = 0;
|
||||||
git_config_from_file(check_repository_format_version,
|
git_config_from_file(check_repository_format_version,
|
||||||
template_path, NULL);
|
template_path.buf, NULL);
|
||||||
template_path[template_len] = 0;
|
strbuf_setlen(&template_path, template_len);
|
||||||
|
|
||||||
if (repository_format_version &&
|
if (repository_format_version &&
|
||||||
repository_format_version != GIT_REPO_VERSION) {
|
repository_format_version != GIT_REPO_VERSION) {
|
||||||
|
@ -162,17 +147,15 @@ static void copy_templates(const char *template_dir)
|
||||||
goto close_free_return;
|
goto close_free_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(path, git_dir, len);
|
strbuf_addstr(&path, get_git_dir());
|
||||||
if (len && path[len - 1] != '/')
|
strbuf_complete(&path, '/');
|
||||||
path[len++] = '/';
|
copy_templates_1(&path, &template_path, dir);
|
||||||
path[len] = 0;
|
|
||||||
copy_templates_1(path, len,
|
|
||||||
template_path, template_len,
|
|
||||||
dir);
|
|
||||||
close_free_return:
|
close_free_return:
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
free_return:
|
free_return:
|
||||||
free(to_free);
|
free(to_free);
|
||||||
|
strbuf_release(&path);
|
||||||
|
strbuf_release(&template_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_init_db_config(const char *k, const char *v, void *cb)
|
static int git_init_db_config(const char *k, const char *v, void *cb)
|
||||||
|
@ -199,28 +182,20 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
|
||||||
|
|
||||||
static int create_default_files(const char *template_path)
|
static int create_default_files(const char *template_path)
|
||||||
{
|
{
|
||||||
const char *git_dir = get_git_dir();
|
|
||||||
unsigned len = strlen(git_dir);
|
|
||||||
static char path[PATH_MAX];
|
|
||||||
struct stat st1;
|
struct stat st1;
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
char *path;
|
||||||
char repo_version_string[10];
|
char repo_version_string[10];
|
||||||
char junk[2];
|
char junk[2];
|
||||||
int reinit;
|
int reinit;
|
||||||
int filemode;
|
int filemode;
|
||||||
|
|
||||||
if (len > sizeof(path)-50)
|
|
||||||
die(_("insane git directory %s"), git_dir);
|
|
||||||
memcpy(path, git_dir, len);
|
|
||||||
|
|
||||||
if (len && path[len-1] != '/')
|
|
||||||
path[len++] = '/';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create .git/refs/{heads,tags}
|
* Create .git/refs/{heads,tags}
|
||||||
*/
|
*/
|
||||||
safe_create_dir(git_path("refs"), 1);
|
safe_create_dir(git_path_buf(&buf, "refs"), 1);
|
||||||
safe_create_dir(git_path("refs/heads"), 1);
|
safe_create_dir(git_path_buf(&buf, "refs/heads"), 1);
|
||||||
safe_create_dir(git_path("refs/tags"), 1);
|
safe_create_dir(git_path_buf(&buf, "refs/tags"), 1);
|
||||||
|
|
||||||
/* Just look for `init.templatedir` */
|
/* Just look for `init.templatedir` */
|
||||||
git_config(git_init_db_config, NULL);
|
git_config(git_init_db_config, NULL);
|
||||||
|
@ -244,16 +219,16 @@ static int create_default_files(const char *template_path)
|
||||||
*/
|
*/
|
||||||
if (shared_repository) {
|
if (shared_repository) {
|
||||||
adjust_shared_perm(get_git_dir());
|
adjust_shared_perm(get_git_dir());
|
||||||
adjust_shared_perm(git_path("refs"));
|
adjust_shared_perm(git_path_buf(&buf, "refs"));
|
||||||
adjust_shared_perm(git_path("refs/heads"));
|
adjust_shared_perm(git_path_buf(&buf, "refs/heads"));
|
||||||
adjust_shared_perm(git_path("refs/tags"));
|
adjust_shared_perm(git_path_buf(&buf, "refs/tags"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the default symlink from ".git/HEAD" to the "master"
|
* Create the default symlink from ".git/HEAD" to the "master"
|
||||||
* branch, if it does not exist yet.
|
* branch, if it does not exist yet.
|
||||||
*/
|
*/
|
||||||
strcpy(path + len, "HEAD");
|
path = git_path_buf(&buf, "HEAD");
|
||||||
reinit = (!access(path, R_OK)
|
reinit = (!access(path, R_OK)
|
||||||
|| readlink(path, junk, sizeof(junk)-1) != -1);
|
|| readlink(path, junk, sizeof(junk)-1) != -1);
|
||||||
if (!reinit) {
|
if (!reinit) {
|
||||||
|
@ -262,13 +237,12 @@ static int create_default_files(const char *template_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This forces creation of new config file */
|
/* This forces creation of new config file */
|
||||||
sprintf(repo_version_string, "%d", GIT_REPO_VERSION);
|
xsnprintf(repo_version_string, sizeof(repo_version_string),
|
||||||
|
"%d", GIT_REPO_VERSION);
|
||||||
git_config_set("core.repositoryformatversion", repo_version_string);
|
git_config_set("core.repositoryformatversion", repo_version_string);
|
||||||
|
|
||||||
path[len] = 0;
|
|
||||||
strcpy(path + len, "config");
|
|
||||||
|
|
||||||
/* Check filemode trustability */
|
/* Check filemode trustability */
|
||||||
|
path = git_path_buf(&buf, "config");
|
||||||
filemode = TEST_FILEMODE;
|
filemode = TEST_FILEMODE;
|
||||||
if (TEST_FILEMODE && !lstat(path, &st1)) {
|
if (TEST_FILEMODE && !lstat(path, &st1)) {
|
||||||
struct stat st2;
|
struct stat st2;
|
||||||
|
@ -289,14 +263,13 @@ static int create_default_files(const char *template_path)
|
||||||
/* allow template config file to override the default */
|
/* allow template config file to override the default */
|
||||||
if (log_all_ref_updates == -1)
|
if (log_all_ref_updates == -1)
|
||||||
git_config_set("core.logallrefupdates", "true");
|
git_config_set("core.logallrefupdates", "true");
|
||||||
if (needs_work_tree_config(git_dir, work_tree))
|
if (needs_work_tree_config(get_git_dir(), work_tree))
|
||||||
git_config_set("core.worktree", work_tree);
|
git_config_set("core.worktree", work_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reinit) {
|
if (!reinit) {
|
||||||
/* Check if symlink is supported in the work tree */
|
/* Check if symlink is supported in the work tree */
|
||||||
path[len] = 0;
|
path = git_path_buf(&buf, "tXXXXXX");
|
||||||
strcpy(path + len, "tXXXXXX");
|
|
||||||
if (!close(xmkstemp(path)) &&
|
if (!close(xmkstemp(path)) &&
|
||||||
!unlink(path) &&
|
!unlink(path) &&
|
||||||
!symlink("testing", path) &&
|
!symlink("testing", path) &&
|
||||||
|
@ -307,31 +280,35 @@ static int create_default_files(const char *template_path)
|
||||||
git_config_set("core.symlinks", "false");
|
git_config_set("core.symlinks", "false");
|
||||||
|
|
||||||
/* Check if the filesystem is case-insensitive */
|
/* Check if the filesystem is case-insensitive */
|
||||||
path[len] = 0;
|
path = git_path_buf(&buf, "CoNfIg");
|
||||||
strcpy(path + len, "CoNfIg");
|
|
||||||
if (!access(path, F_OK))
|
if (!access(path, F_OK))
|
||||||
git_config_set("core.ignorecase", "true");
|
git_config_set("core.ignorecase", "true");
|
||||||
probe_utf8_pathname_composition(path, len);
|
probe_utf8_pathname_composition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strbuf_release(&buf);
|
||||||
return reinit;
|
return reinit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_object_directory(void)
|
static void create_object_directory(void)
|
||||||
{
|
{
|
||||||
const char *object_directory = get_object_directory();
|
struct strbuf path = STRBUF_INIT;
|
||||||
int len = strlen(object_directory);
|
size_t baselen;
|
||||||
char *path = xmalloc(len + 40);
|
|
||||||
|
|
||||||
memcpy(path, object_directory, len);
|
strbuf_addstr(&path, get_object_directory());
|
||||||
|
baselen = path.len;
|
||||||
|
|
||||||
safe_create_dir(object_directory, 1);
|
safe_create_dir(path.buf, 1);
|
||||||
strcpy(path+len, "/pack");
|
|
||||||
safe_create_dir(path, 1);
|
|
||||||
strcpy(path+len, "/info");
|
|
||||||
safe_create_dir(path, 1);
|
|
||||||
|
|
||||||
free(path);
|
strbuf_setlen(&path, baselen);
|
||||||
|
strbuf_addstr(&path, "/pack");
|
||||||
|
safe_create_dir(path.buf, 1);
|
||||||
|
|
||||||
|
strbuf_setlen(&path, baselen);
|
||||||
|
strbuf_addstr(&path, "/info");
|
||||||
|
safe_create_dir(path.buf, 1);
|
||||||
|
|
||||||
|
strbuf_release(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_git_dir_init(const char *git_dir, const char *real_git_dir,
|
int set_git_dir_init(const char *git_dir, const char *real_git_dir,
|
||||||
|
@ -414,13 +391,13 @@ int init_db(const char *template_dir, unsigned int flags)
|
||||||
*/
|
*/
|
||||||
if (shared_repository < 0)
|
if (shared_repository < 0)
|
||||||
/* force to the mode value */
|
/* force to the mode value */
|
||||||
sprintf(buf, "0%o", -shared_repository);
|
xsnprintf(buf, sizeof(buf), "0%o", -shared_repository);
|
||||||
else if (shared_repository == PERM_GROUP)
|
else if (shared_repository == PERM_GROUP)
|
||||||
sprintf(buf, "%d", OLD_PERM_GROUP);
|
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
|
||||||
else if (shared_repository == PERM_EVERYBODY)
|
else if (shared_repository == PERM_EVERYBODY)
|
||||||
sprintf(buf, "%d", OLD_PERM_EVERYBODY);
|
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
|
||||||
else
|
else
|
||||||
die("oops");
|
die("BUG: invalid value for shared_repository");
|
||||||
git_config_set("core.sharedrepository", buf);
|
git_config_set("core.sharedrepository", buf);
|
||||||
git_config_set("receive.denyNonFastforwards", "true");
|
git_config_set("receive.denyNonFastforwards", "true");
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,8 +796,7 @@ static int reopen_stdout(struct commit *commit, const char *subject,
|
||||||
if (filename.len >=
|
if (filename.len >=
|
||||||
PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
|
PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
|
||||||
return error(_("name of output directory is too long"));
|
return error(_("name of output directory is too long"));
|
||||||
if (filename.buf[filename.len - 1] != '/')
|
strbuf_complete(&filename, '/');
|
||||||
strbuf_addch(&filename, '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rev->numbered_files)
|
if (rev->numbered_files)
|
||||||
|
|
|
@ -93,12 +93,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
||||||
if (argv[i]) {
|
if (argv[i]) {
|
||||||
int j;
|
int j;
|
||||||
pattern = xcalloc(argc - i + 1, sizeof(const char *));
|
pattern = xcalloc(argc - i + 1, sizeof(const char *));
|
||||||
for (j = i; j < argc; j++) {
|
for (j = i; j < argc; j++)
|
||||||
int len = strlen(argv[j]);
|
pattern[j - i] = xstrfmt("*/%s", argv[j]);
|
||||||
char *p = xmalloc(len + 3);
|
|
||||||
sprintf(p, "*/%s", argv[j]);
|
|
||||||
pattern[j - i] = p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
remote = remote_get(dest);
|
remote = remote_get(dest);
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
|
|
|
@ -96,12 +96,13 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
|
||||||
if (!strcmp(type, blob_type)) {
|
if (!strcmp(type, blob_type)) {
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
if (sha1_object_info(sha1, &size) == OBJ_BAD)
|
if (sha1_object_info(sha1, &size) == OBJ_BAD)
|
||||||
strcpy(size_text, "BAD");
|
xsnprintf(size_text, sizeof(size_text),
|
||||||
|
"BAD");
|
||||||
else
|
else
|
||||||
snprintf(size_text, sizeof(size_text),
|
xsnprintf(size_text, sizeof(size_text),
|
||||||
"%lu", size);
|
"%lu", size);
|
||||||
} else
|
} else
|
||||||
strcpy(size_text, "-");
|
xsnprintf(size_text, sizeof(size_text), "-");
|
||||||
printf("%06o %s %s %7s\t", mode, type,
|
printf("%06o %s %s %7s\t", mode, type,
|
||||||
find_unique_abbrev(sha1, abbrev),
|
find_unique_abbrev(sha1, abbrev),
|
||||||
size_text);
|
size_text);
|
||||||
|
|
|
@ -98,30 +98,37 @@ static int populate_maildir_list(struct string_list *list, const char *path)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
char name[PATH_MAX];
|
char *name = NULL;
|
||||||
char *subs[] = { "cur", "new", NULL };
|
char *subs[] = { "cur", "new", NULL };
|
||||||
char **sub;
|
char **sub;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
for (sub = subs; *sub; ++sub) {
|
for (sub = subs; *sub; ++sub) {
|
||||||
snprintf(name, sizeof(name), "%s/%s", path, *sub);
|
free(name);
|
||||||
|
name = xstrfmt("%s/%s", path, *sub);
|
||||||
if ((dir = opendir(name)) == NULL) {
|
if ((dir = opendir(name)) == NULL) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
continue;
|
continue;
|
||||||
error("cannot opendir %s (%s)", name, strerror(errno));
|
error("cannot opendir %s (%s)", name, strerror(errno));
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dent = readdir(dir)) != NULL) {
|
while ((dent = readdir(dir)) != NULL) {
|
||||||
if (dent->d_name[0] == '.')
|
if (dent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
snprintf(name, sizeof(name), "%s/%s", *sub, dent->d_name);
|
free(name);
|
||||||
|
name = xstrfmt("%s/%s", *sub, dent->d_name);
|
||||||
string_list_insert(list, name);
|
string_list_insert(list, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(name);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int maildir_filename_cmp(const char *a, const char *b)
|
static int maildir_filename_cmp(const char *a, const char *b)
|
||||||
|
@ -148,8 +155,8 @@ static int maildir_filename_cmp(const char *a, const char *b)
|
||||||
static int split_maildir(const char *maildir, const char *dir,
|
static int split_maildir(const char *maildir, const char *dir,
|
||||||
int nr_prec, int skip)
|
int nr_prec, int skip)
|
||||||
{
|
{
|
||||||
char file[PATH_MAX];
|
char *file = NULL;
|
||||||
char name[PATH_MAX];
|
FILE *f = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
struct string_list list = STRING_LIST_INIT_DUP;
|
struct string_list list = STRING_LIST_INIT_DUP;
|
||||||
|
@ -160,8 +167,11 @@ static int split_maildir(const char *maildir, const char *dir,
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < list.nr; i++) {
|
for (i = 0; i < list.nr; i++) {
|
||||||
FILE *f;
|
char *name;
|
||||||
snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].string);
|
|
||||||
|
free(file);
|
||||||
|
file = xstrfmt("%s/%s", maildir, list.items[i].string);
|
||||||
|
|
||||||
f = fopen(file, "r");
|
f = fopen(file, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
error("cannot open mail %s (%s)", file, strerror(errno));
|
error("cannot open mail %s (%s)", file, strerror(errno));
|
||||||
|
@ -173,14 +183,19 @@ static int split_maildir(const char *maildir, const char *dir,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(name, "%s/%0*d", dir, nr_prec, ++skip);
|
name = xstrfmt("%s/%0*d", dir, nr_prec, ++skip);
|
||||||
split_one(f, name, 1);
|
split_one(f, name, 1);
|
||||||
|
free(name);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = skip;
|
ret = skip;
|
||||||
out:
|
out:
|
||||||
|
if (f)
|
||||||
|
fclose(f);
|
||||||
|
free(file);
|
||||||
string_list_clear(&list, 1);
|
string_list_clear(&list, 1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +203,6 @@ out:
|
||||||
static int split_mbox(const char *file, const char *dir, int allow_bare,
|
static int split_mbox(const char *file, const char *dir, int allow_bare,
|
||||||
int nr_prec, int skip)
|
int nr_prec, int skip)
|
||||||
{
|
{
|
||||||
char name[PATH_MAX];
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int peek;
|
int peek;
|
||||||
|
|
||||||
|
@ -215,8 +229,9 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!file_done) {
|
while (!file_done) {
|
||||||
sprintf(name, "%s/%0*d", dir, nr_prec, ++skip);
|
char *name = xstrfmt("%s/%0*d", dir, nr_prec, ++skip);
|
||||||
file_done = split_one(f, name, allow_bare);
|
file_done = split_one(f, name, allow_bare);
|
||||||
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f != stdin)
|
if (f != stdin)
|
||||||
|
|
|
@ -9,7 +9,7 @@ static int merge_entry(int pos, const char *path)
|
||||||
{
|
{
|
||||||
int found;
|
int found;
|
||||||
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
|
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
|
||||||
char hexbuf[4][60];
|
char hexbuf[4][GIT_SHA1_HEXSZ + 1];
|
||||||
char ownbuf[4][60];
|
char ownbuf[4][60];
|
||||||
|
|
||||||
if (pos >= active_nr)
|
if (pos >= active_nr)
|
||||||
|
@ -22,8 +22,8 @@ static int merge_entry(int pos, const char *path)
|
||||||
if (strcmp(ce->name, path))
|
if (strcmp(ce->name, path))
|
||||||
break;
|
break;
|
||||||
found++;
|
found++;
|
||||||
strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
|
sha1_to_hex_r(hexbuf[stage], ce->sha1);
|
||||||
sprintf(ownbuf[stage], "%o", ce->ce_mode);
|
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
|
||||||
arguments[stage] = hexbuf[stage];
|
arguments[stage] = hexbuf[stage];
|
||||||
arguments[stage + 4] = ownbuf[stage];
|
arguments[stage + 4] = ownbuf[stage];
|
||||||
} while (++pos < active_nr);
|
} while (++pos < active_nr);
|
||||||
|
|
|
@ -14,7 +14,7 @@ static const char *better_branch_name(const char *branch)
|
||||||
|
|
||||||
if (strlen(branch) != 40)
|
if (strlen(branch) != 40)
|
||||||
return branch;
|
return branch;
|
||||||
sprintf(githead_env, "GITHEAD_%s", branch);
|
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
|
||||||
name = getenv(githead_env);
|
name = getenv(githead_env);
|
||||||
return name ? name : branch;
|
return name ? name : branch;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1319,13 +1319,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
||||||
if (verify_signatures) {
|
if (verify_signatures) {
|
||||||
for (p = remoteheads; p; p = p->next) {
|
for (p = remoteheads; p; p = p->next) {
|
||||||
struct commit *commit = p->item;
|
struct commit *commit = p->item;
|
||||||
char hex[41];
|
char hex[GIT_SHA1_HEXSZ + 1];
|
||||||
struct signature_check signature_check;
|
struct signature_check signature_check;
|
||||||
memset(&signature_check, 0, sizeof(signature_check));
|
memset(&signature_check, 0, sizeof(signature_check));
|
||||||
|
|
||||||
check_commit_signature(commit, &signature_check);
|
check_commit_signature(commit, &signature_check);
|
||||||
|
|
||||||
strcpy(hex, find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
|
find_unique_abbrev_r(hex, commit->object.sha1, DEFAULT_ABBREV);
|
||||||
switch (signature_check.result) {
|
switch (signature_check.result) {
|
||||||
case 'G':
|
case 'G':
|
||||||
break;
|
break;
|
||||||
|
@ -1415,15 +1415,15 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
||||||
/* Again the most common case of merging one remote. */
|
/* Again the most common case of merging one remote. */
|
||||||
struct strbuf msg = STRBUF_INIT;
|
struct strbuf msg = STRBUF_INIT;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
char hex[41];
|
|
||||||
|
|
||||||
strcpy(hex, find_unique_abbrev(head_commit->object.sha1, DEFAULT_ABBREV));
|
if (verbosity >= 0) {
|
||||||
|
char from[GIT_SHA1_HEXSZ + 1], to[GIT_SHA1_HEXSZ + 1];
|
||||||
if (verbosity >= 0)
|
find_unique_abbrev_r(from, head_commit->object.sha1,
|
||||||
printf(_("Updating %s..%s\n"),
|
DEFAULT_ABBREV);
|
||||||
hex,
|
find_unique_abbrev_r(to, remoteheads->item->object.sha1,
|
||||||
find_unique_abbrev(remoteheads->item->object.sha1,
|
DEFAULT_ABBREV);
|
||||||
DEFAULT_ABBREV));
|
printf(_("Updating %s..%s\n"), from, to);
|
||||||
|
}
|
||||||
strbuf_addstr(&msg, "Fast-forward");
|
strbuf_addstr(&msg, "Fast-forward");
|
||||||
if (have_message)
|
if (have_message)
|
||||||
strbuf_addstr(&msg,
|
strbuf_addstr(&msg,
|
||||||
|
|
|
@ -55,19 +55,15 @@ copy_data:
|
||||||
parents;
|
parents;
|
||||||
parents = parents->next, parent_number++) {
|
parents = parents->next, parent_number++) {
|
||||||
if (parent_number > 1) {
|
if (parent_number > 1) {
|
||||||
int len = strlen(tip_name);
|
size_t len;
|
||||||
char *new_name = xmalloc(len +
|
char *new_name;
|
||||||
1 + decimal_length(generation) + /* ~<n> */
|
|
||||||
1 + 2 + /* ^NN */
|
|
||||||
1);
|
|
||||||
|
|
||||||
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
|
strip_suffix(tip_name, "^0", &len);
|
||||||
len -= 2;
|
|
||||||
if (generation > 0)
|
if (generation > 0)
|
||||||
sprintf(new_name, "%.*s~%d^%d", len, tip_name,
|
new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
|
||||||
generation, parent_number);
|
generation, parent_number);
|
||||||
else
|
else
|
||||||
sprintf(new_name, "%.*s^%d", len, tip_name,
|
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
||||||
parent_number);
|
parent_number);
|
||||||
|
|
||||||
name_rev(parents->item, new_name, 0,
|
name_rev(parents->item, new_name, 0,
|
||||||
|
|
|
@ -90,7 +90,7 @@ static int debug_merge(const struct cache_entry * const *stages,
|
||||||
debug_stage("index", stages[0], o);
|
debug_stage("index", stages[0], o);
|
||||||
for (i = 1; i <= o->merge_size; i++) {
|
for (i = 1; i <= o->merge_size; i++) {
|
||||||
char buf[24];
|
char buf[24];
|
||||||
sprintf(buf, "ent#%d", i);
|
xsnprintf(buf, sizeof(buf), "ent#%d", i);
|
||||||
debug_stage(buf, stages[i], o);
|
debug_stage(buf, stages[i], o);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -280,10 +280,10 @@ static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2
|
||||||
|
|
||||||
static void report_message(const char *prefix, const char *err, va_list params)
|
static void report_message(const char *prefix, const char *err, va_list params)
|
||||||
{
|
{
|
||||||
int sz = strlen(prefix);
|
int sz;
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
|
|
||||||
strncpy(msg, prefix, sz);
|
sz = xsnprintf(msg, sizeof(msg), "%s", prefix);
|
||||||
sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
|
sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
|
||||||
if (sz > (sizeof(msg) - 1))
|
if (sz > (sizeof(msg) - 1))
|
||||||
sz = sizeof(msg) - 1;
|
sz = sizeof(msg) - 1;
|
||||||
|
@ -1071,8 +1071,11 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
|
||||||
const char *dst_name;
|
const char *dst_name;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
struct command *dst_cmd;
|
struct command *dst_cmd;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[GIT_SHA1_RAWSZ];
|
||||||
char cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];
|
char cmd_oldh[GIT_SHA1_HEXSZ + 1],
|
||||||
|
cmd_newh[GIT_SHA1_HEXSZ + 1],
|
||||||
|
dst_oldh[GIT_SHA1_HEXSZ + 1],
|
||||||
|
dst_newh[GIT_SHA1_HEXSZ + 1];
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
|
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
|
||||||
|
@ -1103,10 +1106,10 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
|
||||||
|
|
||||||
dst_cmd->skip_update = 1;
|
dst_cmd->skip_update = 1;
|
||||||
|
|
||||||
strcpy(cmd_oldh, find_unique_abbrev(cmd->old_sha1, DEFAULT_ABBREV));
|
find_unique_abbrev_r(cmd_oldh, cmd->old_sha1, DEFAULT_ABBREV);
|
||||||
strcpy(cmd_newh, find_unique_abbrev(cmd->new_sha1, DEFAULT_ABBREV));
|
find_unique_abbrev_r(cmd_newh, cmd->new_sha1, DEFAULT_ABBREV);
|
||||||
strcpy(dst_oldh, find_unique_abbrev(dst_cmd->old_sha1, DEFAULT_ABBREV));
|
find_unique_abbrev_r(dst_oldh, dst_cmd->old_sha1, DEFAULT_ABBREV);
|
||||||
strcpy(dst_newh, find_unique_abbrev(dst_cmd->new_sha1, DEFAULT_ABBREV));
|
find_unique_abbrev_r(dst_newh, dst_cmd->new_sha1, DEFAULT_ABBREV);
|
||||||
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
|
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
|
||||||
" its target '%s' (%s..%s)",
|
" its target '%s' (%s..%s)",
|
||||||
cmd->ref_name, cmd_oldh, cmd_newh,
|
cmd->ref_name, cmd_oldh, cmd_newh,
|
||||||
|
@ -1521,15 +1524,18 @@ static const char *unpack(int err_fd, struct shallow_info *si)
|
||||||
if (status)
|
if (status)
|
||||||
return "unpack-objects abnormal exit";
|
return "unpack-objects abnormal exit";
|
||||||
} else {
|
} else {
|
||||||
int s;
|
char hostname[256];
|
||||||
char keep_arg[256];
|
|
||||||
|
|
||||||
s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
|
|
||||||
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
|
|
||||||
strcpy(keep_arg + s, "localhost");
|
|
||||||
|
|
||||||
argv_array_pushl(&child.args, "index-pack",
|
argv_array_pushl(&child.args, "index-pack",
|
||||||
"--stdin", hdr_arg, keep_arg, NULL);
|
"--stdin", hdr_arg, NULL);
|
||||||
|
|
||||||
|
if (gethostname(hostname, sizeof(hostname)))
|
||||||
|
xsnprintf(hostname, sizeof(hostname), "localhost");
|
||||||
|
argv_array_pushf(&child.args,
|
||||||
|
"--keep=receive-pack %"PRIuMAX" on %s",
|
||||||
|
(uintmax_t)getpid(),
|
||||||
|
hostname);
|
||||||
|
|
||||||
if (fsck_objects)
|
if (fsck_objects)
|
||||||
argv_array_pushf(&child.args, "--strict%s",
|
argv_array_pushf(&child.args, "--strict%s",
|
||||||
fsck_msg_types.buf);
|
fsck_msg_types.buf);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
|
#include "pkt-line.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* URL syntax:
|
* URL syntax:
|
||||||
|
@ -142,36 +143,11 @@ static const char **parse_argv(const char *arg, const char *service)
|
||||||
static void send_git_request(int stdin_fd, const char *serv, const char *repo,
|
static void send_git_request(int stdin_fd, const char *serv, const char *repo,
|
||||||
const char *vhost)
|
const char *vhost)
|
||||||
{
|
{
|
||||||
size_t bufferspace;
|
if (!vhost)
|
||||||
size_t wpos = 0;
|
packet_write(stdin_fd, "%s %s%c", serv, repo, 0);
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Request needs 12 bytes extra if there is vhost (xxxx \0host=\0) and
|
|
||||||
* 6 bytes extra (xxxx \0) if there is no vhost.
|
|
||||||
*/
|
|
||||||
if (vhost)
|
|
||||||
bufferspace = strlen(serv) + strlen(repo) + strlen(vhost) + 12;
|
|
||||||
else
|
else
|
||||||
bufferspace = strlen(serv) + strlen(repo) + 6;
|
packet_write(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
|
||||||
|
vhost, 0);
|
||||||
if (bufferspace > 0xFFFF)
|
|
||||||
die("Request too large to send");
|
|
||||||
buffer = xmalloc(bufferspace);
|
|
||||||
|
|
||||||
/* Make the packet. */
|
|
||||||
wpos = sprintf(buffer, "%04x%s %s%c", (unsigned)bufferspace,
|
|
||||||
serv, repo, 0);
|
|
||||||
|
|
||||||
/* Add vhost if any. */
|
|
||||||
if (vhost)
|
|
||||||
sprintf(buffer + wpos, "host=%s%c", vhost, 0);
|
|
||||||
|
|
||||||
/* Send the request */
|
|
||||||
if (write_in_full(stdin_fd, buffer, bufferspace) < 0)
|
|
||||||
die_errno("Failed to send request");
|
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_child(const char *arg, const char *service)
|
static int run_child(const char *arg, const char *service)
|
||||||
|
|
|
@ -217,7 +217,7 @@ static void print_var_int(const char *var, int val)
|
||||||
static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
|
static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
|
||||||
{
|
{
|
||||||
int cnt, flags = info->flags;
|
int cnt, flags = info->flags;
|
||||||
char hex[41] = "";
|
char hex[GIT_SHA1_HEXSZ + 1] = "";
|
||||||
struct commit_list *tried;
|
struct commit_list *tried;
|
||||||
struct rev_info *revs = info->revs;
|
struct rev_info *revs = info->revs;
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
|
||||||
cnt = reaches;
|
cnt = reaches;
|
||||||
|
|
||||||
if (revs->commits)
|
if (revs->commits)
|
||||||
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
|
sha1_to_hex_r(hex, revs->commits->item->object.sha1);
|
||||||
|
|
||||||
if (flags & BISECT_SHOW_ALL) {
|
if (flags & BISECT_SHOW_ALL) {
|
||||||
traverse_commit_list(revs, show_commit, show_object, info);
|
traverse_commit_list(revs, show_commit, show_object, info);
|
||||||
|
|
|
@ -743,6 +743,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
||||||
fake_av[1] = NULL;
|
fake_av[1] = NULL;
|
||||||
av = fake_av;
|
av = fake_av;
|
||||||
ac = 1;
|
ac = 1;
|
||||||
|
if (!*av)
|
||||||
|
die("no branches given, and HEAD is not valid");
|
||||||
}
|
}
|
||||||
if (ac != 1)
|
if (ac != 1)
|
||||||
die("--reflog option needs one branch name");
|
die("--reflog option needs one branch name");
|
||||||
|
|
|
@ -12,7 +12,7 @@ static char *create_temp_file(unsigned char *sha1)
|
||||||
if (!buf || type != OBJ_BLOB)
|
if (!buf || type != OBJ_BLOB)
|
||||||
die("unable to read blob object %s", sha1_to_hex(sha1));
|
die("unable to read blob object %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
strcpy(path, ".merge_file_XXXXXX");
|
xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
|
||||||
fd = xmkstemp(path);
|
fd = xmkstemp(path);
|
||||||
if (write_in_full(fd, buf, size) != size)
|
if (write_in_full(fd, buf, size) != size)
|
||||||
die_errno("unable to write temp-file");
|
die_errno("unable to write temp-file");
|
||||||
|
|
|
@ -49,15 +49,14 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
|
||||||
__attribute__((format (printf, 1, 2)))
|
__attribute__((format (printf, 1, 2)))
|
||||||
static void error_clnt(const char *fmt, ...)
|
static void error_clnt(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
struct strbuf buf = STRBUF_INIT;
|
||||||
va_list params;
|
va_list params;
|
||||||
int len;
|
|
||||||
|
|
||||||
va_start(params, fmt);
|
va_start(params, fmt);
|
||||||
len = vsprintf(buf, fmt, params);
|
strbuf_vaddf(&buf, fmt, params);
|
||||||
va_end(params);
|
va_end(params);
|
||||||
send_sideband(1, 3, buf, len, LARGE_PACKET_MAX);
|
send_sideband(1, 3, buf.buf, buf.len, LARGE_PACKET_MAX);
|
||||||
die("sent error to the client: %s", buf);
|
die("sent error to the client: %s", buf.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t process_input(int child_fd, int band)
|
static ssize_t process_input(int child_fd, int band)
|
||||||
|
|
|
@ -200,7 +200,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
|
||||||
if (seekback == (off_t) -1)
|
if (seekback == (off_t) -1)
|
||||||
return error("cannot find the current offset");
|
return error("cannot find the current offset");
|
||||||
|
|
||||||
header_len = sprintf((char *)obuf, "%s %" PRIuMAX,
|
header_len = xsnprintf((char *)obuf, sizeof(obuf), "%s %" PRIuMAX,
|
||||||
typename(type), (uintmax_t)size) + 1;
|
typename(type), (uintmax_t)size) + 1;
|
||||||
git_SHA1_Init(&ctx);
|
git_SHA1_Init(&ctx);
|
||||||
git_SHA1_Update(&ctx, obuf, header_len);
|
git_SHA1_Update(&ctx, obuf, header_len);
|
||||||
|
|
35
cache.h
35
cache.h
|
@ -724,6 +724,8 @@ extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
||||||
__attribute__((format (printf, 3, 4)));
|
__attribute__((format (printf, 3, 4)));
|
||||||
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
||||||
__attribute__((format (printf, 2, 3)));
|
__attribute__((format (printf, 2, 3)));
|
||||||
|
extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
|
||||||
|
__attribute__((format (printf, 2, 3)));
|
||||||
extern void strbuf_git_path_submodule(struct strbuf *sb, const char *path,
|
extern void strbuf_git_path_submodule(struct strbuf *sb, const char *path,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
__attribute__((format (printf, 3, 4)));
|
__attribute__((format (printf, 3, 4)));
|
||||||
|
@ -784,7 +786,24 @@ extern char *sha1_pack_name(const unsigned char *sha1);
|
||||||
*/
|
*/
|
||||||
extern char *sha1_pack_index_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);
|
/*
|
||||||
|
* Return an abbreviated sha1 unique within this repository's object database.
|
||||||
|
* The result will be at least `len` characters long, and will be NUL
|
||||||
|
* terminated.
|
||||||
|
*
|
||||||
|
* The non-`_r` version returns a static buffer which will be overwritten by
|
||||||
|
* subsequent calls.
|
||||||
|
*
|
||||||
|
* The `_r` variant writes to a buffer supplied by the caller, which must be at
|
||||||
|
* least `GIT_SHA1_HEXSZ + 1` bytes. The return value is the number of bytes
|
||||||
|
* written (excluding the NUL terminator).
|
||||||
|
*
|
||||||
|
* Note that while this version avoids the static buffer, it is not fully
|
||||||
|
* reentrant, as it calls into other non-reentrant git code.
|
||||||
|
*/
|
||||||
|
extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
|
||||||
|
extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
|
||||||
|
|
||||||
extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
|
extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
|
||||||
|
|
||||||
static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
|
static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
|
||||||
|
@ -1066,6 +1085,18 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
|
||||||
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
|
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
|
||||||
extern int get_oid_hex(const char *hex, struct object_id *sha1);
|
extern int get_oid_hex(const char *hex, struct object_id *sha1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a binary sha1 to its hex equivalent. The `_r` variant is reentrant,
|
||||||
|
* and writes the NUL-terminated output to the buffer `out`, which must be at
|
||||||
|
* least `GIT_SHA1_HEXSZ + 1` bytes, and returns a pointer to out for
|
||||||
|
* convenience.
|
||||||
|
*
|
||||||
|
* The non-`_r` variant returns a static buffer, but uses a ring of 4
|
||||||
|
* buffers, making it safe to make multiple calls for a single statement, like:
|
||||||
|
*
|
||||||
|
* printf("%s -> %s", sha1_to_hex(one), sha1_to_hex(two));
|
||||||
|
*/
|
||||||
|
extern char *sha1_to_hex_r(char *out, const unsigned char *sha1);
|
||||||
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
||||||
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
|
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
|
||||||
|
|
||||||
|
@ -1280,7 +1311,7 @@ extern void close_all_packs(void);
|
||||||
extern void unuse_pack(struct pack_window **);
|
extern void unuse_pack(struct pack_window **);
|
||||||
extern void free_pack_by_name(const char *);
|
extern void free_pack_by_name(const char *);
|
||||||
extern void clear_delta_base_cache(void);
|
extern void clear_delta_base_cache(void);
|
||||||
extern struct packed_git *add_packed_git(const char *, int, int);
|
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the SHA-1 of the nth object within the specified packfile.
|
* Return the SHA-1 of the nth object within the specified packfile.
|
||||||
|
|
44
color.c
44
color.c
|
@ -145,26 +145,33 @@ int color_parse(const char *value, char *dst)
|
||||||
return color_parse_mem(value, strlen(value), dst);
|
return color_parse_mem(value, strlen(value), dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void color_set(char *dst, const char *color_bytes)
|
||||||
|
{
|
||||||
|
xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the ANSI color codes for "c" to "out"; the string should
|
* Write the ANSI color codes for "c" to "out"; the string should
|
||||||
* already have the ANSI escape code in it. "out" should have enough
|
* already have the ANSI escape code in it. "out" should have enough
|
||||||
* space in it to fit any color.
|
* space in it to fit any color.
|
||||||
*/
|
*/
|
||||||
static char *color_output(char *out, const struct color *c, char type)
|
static char *color_output(char *out, int len, const struct color *c, char type)
|
||||||
{
|
{
|
||||||
switch (c->type) {
|
switch (c->type) {
|
||||||
case COLOR_UNSPECIFIED:
|
case COLOR_UNSPECIFIED:
|
||||||
case COLOR_NORMAL:
|
case COLOR_NORMAL:
|
||||||
break;
|
break;
|
||||||
case COLOR_ANSI:
|
case COLOR_ANSI:
|
||||||
|
if (len < 2)
|
||||||
|
die("BUG: color parsing ran out of space");
|
||||||
*out++ = type;
|
*out++ = type;
|
||||||
*out++ = '0' + c->value;
|
*out++ = '0' + c->value;
|
||||||
break;
|
break;
|
||||||
case COLOR_256:
|
case COLOR_256:
|
||||||
out += sprintf(out, "%c8;5;%d", type, c->value);
|
out += xsnprintf(out, len, "%c8;5;%d", type, c->value);
|
||||||
break;
|
break;
|
||||||
case COLOR_RGB:
|
case COLOR_RGB:
|
||||||
out += sprintf(out, "%c8;2;%d;%d;%d", type,
|
out += xsnprintf(out, len, "%c8;2;%d;%d;%d", type,
|
||||||
c->red, c->green, c->blue);
|
c->red, c->green, c->blue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -180,12 +187,13 @@ int color_parse_mem(const char *value, int value_len, char *dst)
|
||||||
{
|
{
|
||||||
const char *ptr = value;
|
const char *ptr = value;
|
||||||
int len = value_len;
|
int len = value_len;
|
||||||
|
char *end = dst + COLOR_MAXLEN;
|
||||||
unsigned int attr = 0;
|
unsigned int attr = 0;
|
||||||
struct color fg = { COLOR_UNSPECIFIED };
|
struct color fg = { COLOR_UNSPECIFIED };
|
||||||
struct color bg = { COLOR_UNSPECIFIED };
|
struct color bg = { COLOR_UNSPECIFIED };
|
||||||
|
|
||||||
if (!strncasecmp(value, "reset", len)) {
|
if (!strncasecmp(value, "reset", len)) {
|
||||||
strcpy(dst, GIT_COLOR_RESET);
|
xsnprintf(dst, end - dst, GIT_COLOR_RESET);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,12 +232,19 @@ int color_parse_mem(const char *value, int value_len, char *dst)
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef OUT
|
||||||
|
#define OUT(x) do { \
|
||||||
|
if (dst == end) \
|
||||||
|
die("BUG: color parsing ran out of space"); \
|
||||||
|
*dst++ = (x); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
if (attr || !color_empty(&fg) || !color_empty(&bg)) {
|
if (attr || !color_empty(&fg) || !color_empty(&bg)) {
|
||||||
int sep = 0;
|
int sep = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
*dst++ = '\033';
|
OUT('\033');
|
||||||
*dst++ = '[';
|
OUT('[');
|
||||||
|
|
||||||
for (i = 0; attr; i++) {
|
for (i = 0; attr; i++) {
|
||||||
unsigned bit = (1 << i);
|
unsigned bit = (1 << i);
|
||||||
|
@ -237,27 +252,28 @@ int color_parse_mem(const char *value, int value_len, char *dst)
|
||||||
continue;
|
continue;
|
||||||
attr &= ~bit;
|
attr &= ~bit;
|
||||||
if (sep++)
|
if (sep++)
|
||||||
*dst++ = ';';
|
OUT(';');
|
||||||
dst += sprintf(dst, "%d", i);
|
dst += xsnprintf(dst, end - dst, "%d", i);
|
||||||
}
|
}
|
||||||
if (!color_empty(&fg)) {
|
if (!color_empty(&fg)) {
|
||||||
if (sep++)
|
if (sep++)
|
||||||
*dst++ = ';';
|
OUT(';');
|
||||||
/* foreground colors are all in the 3x range */
|
/* foreground colors are all in the 3x range */
|
||||||
dst = color_output(dst, &fg, '3');
|
dst = color_output(dst, end - dst, &fg, '3');
|
||||||
}
|
}
|
||||||
if (!color_empty(&bg)) {
|
if (!color_empty(&bg)) {
|
||||||
if (sep++)
|
if (sep++)
|
||||||
*dst++ = ';';
|
OUT(';');
|
||||||
/* background colors are all in the 4x range */
|
/* background colors are all in the 4x range */
|
||||||
dst = color_output(dst, &bg, '4');
|
dst = color_output(dst, end - dst, &bg, '4');
|
||||||
}
|
}
|
||||||
*dst++ = 'm';
|
OUT('m');
|
||||||
}
|
}
|
||||||
*dst = 0;
|
OUT(0);
|
||||||
return 0;
|
return 0;
|
||||||
bad:
|
bad:
|
||||||
return error(_("invalid color value: %.*s"), value_len, value);
|
return error(_("invalid color value: %.*s"), value_len, value);
|
||||||
|
#undef OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_config_colorbool(const char *var, const char *value)
|
int git_config_colorbool(const char *var, const char *value)
|
||||||
|
|
7
color.h
7
color.h
|
@ -75,6 +75,13 @@ extern int color_stdout_is_tty;
|
||||||
int git_color_config(const char *var, const char *value, void *cb);
|
int git_color_config(const char *var, const char *value, void *cb);
|
||||||
int git_color_default_config(const char *var, const char *value, void *cb);
|
int git_color_default_config(const char *var, const char *value, void *cb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the color buffer (which must be COLOR_MAXLEN bytes)
|
||||||
|
* to the raw color bytes; this is useful for initializing
|
||||||
|
* default color variables.
|
||||||
|
*/
|
||||||
|
void color_set(char *dst, const char *color_bytes);
|
||||||
|
|
||||||
int git_config_colorbool(const char *var, const char *value);
|
int git_config_colorbool(const char *var, const char *value);
|
||||||
int want_color(int var);
|
int want_color(int var);
|
||||||
int color_parse(const char *value, char *dst);
|
int color_parse(const char *value, char *dst);
|
||||||
|
|
|
@ -16,6 +16,6 @@ const char *githstrerror(int err)
|
||||||
case TRY_AGAIN:
|
case TRY_AGAIN:
|
||||||
return "Non-authoritative \"host not found\", or SERVERFAIL";
|
return "Non-authoritative \"host not found\", or SERVERFAIL";
|
||||||
}
|
}
|
||||||
sprintf(buffer, "Name resolution error %d", err);
|
snprintf(buffer, sizeof(buffer), "Name resolution error %d", err);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,11 +53,11 @@ inet_ntop4(const u_char *src, char *dst, size_t size)
|
||||||
nprinted = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
|
nprinted = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
|
||||||
if (nprinted < 0)
|
if (nprinted < 0)
|
||||||
return (NULL); /* we assume "errno" was set by "snprintf()" */
|
return (NULL); /* we assume "errno" was set by "snprintf()" */
|
||||||
if ((size_t)nprinted > size) {
|
if ((size_t)nprinted >= size) {
|
||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
strcpy(dst, tmp);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return (dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
|
||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
strcpy(dst, tmp);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return (dst);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2133,9 +2133,11 @@ int uname(struct utsname *buf)
|
||||||
{
|
{
|
||||||
DWORD v = GetVersion();
|
DWORD v = GetVersion();
|
||||||
memset(buf, 0, sizeof(*buf));
|
memset(buf, 0, sizeof(*buf));
|
||||||
strcpy(buf->sysname, "Windows");
|
xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows");
|
||||||
sprintf(buf->release, "%u.%u", v & 0xff, (v >> 8) & 0xff);
|
xsnprintf(buf->release, sizeof(buf->release),
|
||||||
|
"%u.%u", v & 0xff, (v >> 8) & 0xff);
|
||||||
/* assuming NT variants only.. */
|
/* assuming NT variants only.. */
|
||||||
sprintf(buf->version, "%u", (v >> 16) & 0x7fff);
|
xsnprintf(buf->version, sizeof(buf->version),
|
||||||
|
"%u", (v >> 16) & 0x7fff);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -957,8 +957,9 @@ char *strdup(const char *s1)
|
||||||
{
|
{
|
||||||
char *s2 = 0;
|
char *s2 = 0;
|
||||||
if (s1) {
|
if (s1) {
|
||||||
s2 = malloc(strlen(s1) + 1);
|
size_t len = strlen(s1) + 1;
|
||||||
strcpy(s2, s1);
|
s2 = malloc(len);
|
||||||
|
memcpy(s2, s1, len);
|
||||||
}
|
}
|
||||||
return s2;
|
return s2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,24 +36,26 @@ static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void probe_utf8_pathname_composition(char *path, int len)
|
void probe_utf8_pathname_composition(void)
|
||||||
{
|
{
|
||||||
|
struct strbuf path = STRBUF_INIT;
|
||||||
static const char *auml_nfc = "\xc3\xa4";
|
static const char *auml_nfc = "\xc3\xa4";
|
||||||
static const char *auml_nfd = "\x61\xcc\x88";
|
static const char *auml_nfd = "\x61\xcc\x88";
|
||||||
int output_fd;
|
int output_fd;
|
||||||
if (precomposed_unicode != -1)
|
if (precomposed_unicode != -1)
|
||||||
return; /* We found it defined in the global config, respect it */
|
return; /* We found it defined in the global config, respect it */
|
||||||
strcpy(path + len, auml_nfc);
|
git_path_buf(&path, "%s", auml_nfc);
|
||||||
output_fd = open(path, O_CREAT|O_EXCL|O_RDWR, 0600);
|
output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
|
||||||
if (output_fd >= 0) {
|
if (output_fd >= 0) {
|
||||||
close(output_fd);
|
close(output_fd);
|
||||||
strcpy(path + len, auml_nfd);
|
git_path_buf(&path, "%s", auml_nfd);
|
||||||
precomposed_unicode = access(path, R_OK) ? 0 : 1;
|
precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
|
||||||
git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
|
git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
|
||||||
strcpy(path + len, auml_nfc);
|
git_path_buf(&path, "%s", auml_nfc);
|
||||||
if (unlink(path))
|
if (unlink(path.buf))
|
||||||
die_errno(_("failed to unlink '%s'"), path);
|
die_errno(_("failed to unlink '%s'"), path.buf);
|
||||||
}
|
}
|
||||||
|
strbuf_release(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,9 +141,8 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
|
||||||
size_t inleft = namelenz;
|
size_t inleft = namelenz;
|
||||||
char *outpos = &prec_dir->dirent_nfc->d_name[0];
|
char *outpos = &prec_dir->dirent_nfc->d_name[0];
|
||||||
size_t outsz = prec_dir->dirent_nfc->max_name_len;
|
size_t outsz = prec_dir->dirent_nfc->max_name_len;
|
||||||
size_t cnt;
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
cnt = iconv(prec_dir->ic_precompose, &cp, &inleft, &outpos, &outsz);
|
iconv(prec_dir->ic_precompose, &cp, &inleft, &outpos, &outsz);
|
||||||
if (errno || inleft) {
|
if (errno || inleft) {
|
||||||
/*
|
/*
|
||||||
* iconv() failed and errno could be E2BIG, EILSEQ, EINVAL, EBADF
|
* iconv() failed and errno could be E2BIG, EILSEQ, EINVAL, EBADF
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef struct {
|
||||||
} PREC_DIR;
|
} PREC_DIR;
|
||||||
|
|
||||||
void precompose_argv(int argc, const char **argv);
|
void precompose_argv(int argc, const char **argv);
|
||||||
void probe_utf8_pathname_composition(char *, int);
|
void probe_utf8_pathname_composition(void);
|
||||||
|
|
||||||
PREC_DIR *precompose_utf8_opendir(const char *dirname);
|
PREC_DIR *precompose_utf8_opendir(const char *dirname);
|
||||||
struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *dirp);
|
struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *dirp);
|
||||||
|
|
|
@ -539,7 +539,7 @@ void winansi_init(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* create a named pipe to communicate with the console thread */
|
/* create a named pipe to communicate with the console thread */
|
||||||
sprintf(name, "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
|
xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
|
||||||
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
|
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
|
||||||
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
|
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
|
||||||
if (hwrite == INVALID_HANDLE_VALUE)
|
if (hwrite == INVALID_HANDLE_VALUE)
|
||||||
|
|
|
@ -166,7 +166,6 @@ endif
|
||||||
ifeq ($(uname_O),Cygwin)
|
ifeq ($(uname_O),Cygwin)
|
||||||
ifeq ($(shell expr "$(uname_R)" : '1\.[1-6]\.'),4)
|
ifeq ($(shell expr "$(uname_R)" : '1\.[1-6]\.'),4)
|
||||||
NO_D_TYPE_IN_DIRENT = YesPlease
|
NO_D_TYPE_IN_DIRENT = YesPlease
|
||||||
NO_D_INO_IN_DIRENT = YesPlease
|
|
||||||
NO_STRCASESTR = YesPlease
|
NO_STRCASESTR = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
NO_MKSTEMPS = YesPlease
|
NO_MKSTEMPS = YesPlease
|
||||||
|
@ -370,7 +369,6 @@ ifeq ($(uname_S),Windows)
|
||||||
NO_POSIX_GOODIES = UnfortunatelyYes
|
NO_POSIX_GOODIES = UnfortunatelyYes
|
||||||
NATIVE_CRLF = YesPlease
|
NATIVE_CRLF = YesPlease
|
||||||
DEFAULT_HELP_FORMAT = html
|
DEFAULT_HELP_FORMAT = html
|
||||||
NO_D_INO_IN_DIRENT = YesPlease
|
|
||||||
|
|
||||||
CC = compat/vcbuild/scripts/clink.pl
|
CC = compat/vcbuild/scripts/clink.pl
|
||||||
AR = compat/vcbuild/scripts/lib.pl
|
AR = compat/vcbuild/scripts/lib.pl
|
||||||
|
@ -520,7 +518,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
|
||||||
NO_INET_NTOP = YesPlease
|
NO_INET_NTOP = YesPlease
|
||||||
NO_POSIX_GOODIES = UnfortunatelyYes
|
NO_POSIX_GOODIES = UnfortunatelyYes
|
||||||
DEFAULT_HELP_FORMAT = html
|
DEFAULT_HELP_FORMAT = html
|
||||||
NO_D_INO_IN_DIRENT = YesPlease
|
|
||||||
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
|
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
|
||||||
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
|
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
|
||||||
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
|
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
|
||||||
|
|
|
@ -767,13 +767,6 @@ elif test x$ac_cv_member_struct_stat_st_mtim_tv_nsec != xyes; then
|
||||||
GIT_CONF_SUBST([NO_NSEC])
|
GIT_CONF_SUBST([NO_NSEC])
|
||||||
fi
|
fi
|
||||||
#
|
#
|
||||||
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
|
|
||||||
AC_CHECK_MEMBER(struct dirent.d_ino,
|
|
||||||
[NO_D_INO_IN_DIRENT=],
|
|
||||||
[NO_D_INO_IN_DIRENT=YesPlease],
|
|
||||||
[#include <dirent.h>])
|
|
||||||
GIT_CONF_SUBST([NO_D_INO_IN_DIRENT])
|
|
||||||
#
|
|
||||||
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
|
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
|
||||||
# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
|
# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
|
||||||
AC_CHECK_MEMBER(struct dirent.d_type,
|
AC_CHECK_MEMBER(struct dirent.d_type,
|
||||||
|
|
|
@ -333,7 +333,7 @@ static const char *ai_name(const struct addrinfo *ai)
|
||||||
static char addr[NI_MAXHOST];
|
static char addr[NI_MAXHOST];
|
||||||
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, sizeof(addr), NULL, 0,
|
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, sizeof(addr), NULL, 0,
|
||||||
NI_NUMERICHOST) != 0)
|
NI_NUMERICHOST) != 0)
|
||||||
strcpy(addr, "(unknown)");
|
xsnprintf(addr, sizeof(addr), "(unknown)");
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1289,7 +1289,8 @@ static struct stream_filter *ident_filter(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct ident_filter *ident = xmalloc(sizeof(*ident));
|
struct ident_filter *ident = xmalloc(sizeof(*ident));
|
||||||
|
|
||||||
sprintf(ident->ident, ": %s $", sha1_to_hex(sha1));
|
xsnprintf(ident->ident, sizeof(ident->ident),
|
||||||
|
": %s $", sha1_to_hex(sha1));
|
||||||
strbuf_init(&ident->left, 0);
|
strbuf_init(&ident->left, 0);
|
||||||
ident->filter.vtbl = &ident_vtbl;
|
ident->filter.vtbl = &ident_vtbl;
|
||||||
ident->state = 0;
|
ident->state = 0;
|
||||||
|
|
26
daemon.c
26
daemon.c
|
@ -811,8 +811,6 @@ static char **cld_argv;
|
||||||
static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
|
static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
struct child_process cld = CHILD_PROCESS_INIT;
|
struct child_process cld = CHILD_PROCESS_INIT;
|
||||||
char addrbuf[300] = "REMOTE_ADDR=", portbuf[300];
|
|
||||||
char *env[] = { addrbuf, portbuf, NULL };
|
|
||||||
|
|
||||||
if (max_connections && live_children >= max_connections) {
|
if (max_connections && live_children >= max_connections) {
|
||||||
kill_some_child();
|
kill_some_child();
|
||||||
|
@ -826,27 +824,23 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr->sa_family == AF_INET) {
|
if (addr->sa_family == AF_INET) {
|
||||||
|
char buf[128] = "";
|
||||||
struct sockaddr_in *sin_addr = (void *) addr;
|
struct sockaddr_in *sin_addr = (void *) addr;
|
||||||
inet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf + 12,
|
inet_ntop(addr->sa_family, &sin_addr->sin_addr, buf, sizeof(buf));
|
||||||
sizeof(addrbuf) - 12);
|
argv_array_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf);
|
||||||
snprintf(portbuf, sizeof(portbuf), "REMOTE_PORT=%d",
|
argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d",
|
||||||
ntohs(sin_addr->sin_port));
|
ntohs(sin_addr->sin_port));
|
||||||
#ifndef NO_IPV6
|
#ifndef NO_IPV6
|
||||||
} else if (addr->sa_family == AF_INET6) {
|
} else if (addr->sa_family == AF_INET6) {
|
||||||
|
char buf[128] = "";
|
||||||
struct sockaddr_in6 *sin6_addr = (void *) addr;
|
struct sockaddr_in6 *sin6_addr = (void *) addr;
|
||||||
|
inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(buf));
|
||||||
char *buf = addrbuf + 12;
|
argv_array_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf);
|
||||||
*buf++ = '['; *buf = '\0'; /* stpcpy() is cool */
|
argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d",
|
||||||
inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf,
|
|
||||||
sizeof(addrbuf) - 13);
|
|
||||||
strcat(buf, "]");
|
|
||||||
|
|
||||||
snprintf(portbuf, sizeof(portbuf), "REMOTE_PORT=%d",
|
|
||||||
ntohs(sin6_addr->sin6_port));
|
ntohs(sin6_addr->sin6_port));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
cld.env = (const char **)env;
|
|
||||||
cld.argv = (const char **)cld_argv;
|
cld.argv = (const char **)cld_argv;
|
||||||
cld.in = incoming;
|
cld.in = incoming;
|
||||||
cld.out = dup(incoming);
|
cld.out = dup(incoming);
|
||||||
|
@ -901,7 +895,7 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
|
||||||
inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, len);
|
inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strcpy(ip, "<unknown>");
|
xsnprintf(ip, sizeof(ip), "<unknown>");
|
||||||
}
|
}
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
@ -916,7 +910,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
|
||||||
int gai;
|
int gai;
|
||||||
long flags;
|
long flags;
|
||||||
|
|
||||||
sprintf(pbuf, "%d", listen_port);
|
xsnprintf(pbuf, sizeof(pbuf), "%d", listen_port);
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
|
@ -136,15 +136,13 @@ static int queue_diff(struct diff_options *o,
|
||||||
|
|
||||||
if (name1) {
|
if (name1) {
|
||||||
strbuf_addstr(&buffer1, name1);
|
strbuf_addstr(&buffer1, name1);
|
||||||
if (buffer1.len && buffer1.buf[buffer1.len - 1] != '/')
|
strbuf_complete(&buffer1, '/');
|
||||||
strbuf_addch(&buffer1, '/');
|
|
||||||
len1 = buffer1.len;
|
len1 = buffer1.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name2) {
|
if (name2) {
|
||||||
strbuf_addstr(&buffer2, name2);
|
strbuf_addstr(&buffer2, name2);
|
||||||
if (buffer2.len && buffer2.buf[buffer2.len - 1] != '/')
|
strbuf_complete(&buffer2, '/');
|
||||||
strbuf_addch(&buffer2, '/');
|
|
||||||
len2 = buffer2.len;
|
len2 = buffer2.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
diff.c
21
diff.c
|
@ -322,7 +322,7 @@ static struct diff_tempfile {
|
||||||
*/
|
*/
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
char hex[41];
|
char hex[GIT_SHA1_HEXSZ + 1];
|
||||||
char mode[10];
|
char mode[10];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2882,9 +2882,8 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
|
||||||
die_errno("unable to write temp-file");
|
die_errno("unable to write temp-file");
|
||||||
close_tempfile(&temp->tempfile);
|
close_tempfile(&temp->tempfile);
|
||||||
temp->name = get_tempfile_path(&temp->tempfile);
|
temp->name = get_tempfile_path(&temp->tempfile);
|
||||||
strcpy(temp->hex, sha1_to_hex(sha1));
|
sha1_to_hex_r(temp->hex, sha1);
|
||||||
temp->hex[40] = 0;
|
xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);
|
||||||
sprintf(temp->mode, "%06o", mode);
|
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
strbuf_release(&template);
|
strbuf_release(&template);
|
||||||
free(path_dup);
|
free(path_dup);
|
||||||
|
@ -2901,8 +2900,8 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
|
||||||
* a '+' entry produces this for file-1.
|
* a '+' entry produces this for file-1.
|
||||||
*/
|
*/
|
||||||
temp->name = "/dev/null";
|
temp->name = "/dev/null";
|
||||||
strcpy(temp->hex, ".");
|
xsnprintf(temp->hex, sizeof(temp->hex), ".");
|
||||||
strcpy(temp->mode, ".");
|
xsnprintf(temp->mode, sizeof(temp->mode), ".");
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2930,16 +2929,16 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
|
||||||
/* we can borrow from the file in the work tree */
|
/* we can borrow from the file in the work tree */
|
||||||
temp->name = name;
|
temp->name = name;
|
||||||
if (!one->sha1_valid)
|
if (!one->sha1_valid)
|
||||||
strcpy(temp->hex, sha1_to_hex(null_sha1));
|
sha1_to_hex_r(temp->hex, null_sha1);
|
||||||
else
|
else
|
||||||
strcpy(temp->hex, sha1_to_hex(one->sha1));
|
sha1_to_hex_r(temp->hex, one->sha1);
|
||||||
/* Even though we may sometimes borrow the
|
/* Even though we may sometimes borrow the
|
||||||
* contents from the work tree, we always want
|
* contents from the work tree, we always want
|
||||||
* one->mode. mode is trustworthy even when
|
* one->mode. mode is trustworthy even when
|
||||||
* !(one->sha1_valid), as long as
|
* !(one->sha1_valid), as long as
|
||||||
* DIFF_FILE_VALID(one).
|
* DIFF_FILE_VALID(one).
|
||||||
*/
|
*/
|
||||||
sprintf(temp->mode, "%06o", one->mode);
|
xsnprintf(temp->mode, sizeof(temp->mode), "%06o", one->mode);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -4085,9 +4084,9 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
if (abblen < 37) {
|
if (abblen < 37) {
|
||||||
static char hex[41];
|
static char hex[41];
|
||||||
if (len < abblen && abblen <= len + 2)
|
if (len < abblen && abblen <= len + 2)
|
||||||
sprintf(hex, "%s%.*s", abbrev, len+3-abblen, "..");
|
xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
|
||||||
else
|
else
|
||||||
sprintf(hex, "%s...", abbrev);
|
xsnprintf(hex, sizeof(hex), "%s...", abbrev);
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
return sha1_to_hex(sha1);
|
return sha1_to_hex(sha1);
|
||||||
|
|
6
dir.c
6
dir.c
|
@ -1596,8 +1596,7 @@ static enum path_treatment treat_path_fast(struct dir_struct *dir,
|
||||||
}
|
}
|
||||||
strbuf_addstr(path, cdir->ucd->name);
|
strbuf_addstr(path, cdir->ucd->name);
|
||||||
/* treat_one_path() does this before it calls treat_directory() */
|
/* treat_one_path() does this before it calls treat_directory() */
|
||||||
if (path->buf[path->len - 1] != '/')
|
strbuf_complete(path, '/');
|
||||||
strbuf_addch(path, '/');
|
|
||||||
if (cdir->ucd->check_only)
|
if (cdir->ucd->check_only)
|
||||||
/*
|
/*
|
||||||
* check_only is set as a result of treat_directory() getting
|
* check_only is set as a result of treat_directory() getting
|
||||||
|
@ -2212,8 +2211,7 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (path->buf[original_len - 1] != '/')
|
strbuf_complete(path, '/');
|
||||||
strbuf_addch(path, '/');
|
|
||||||
|
|
||||||
len = path->len;
|
len = path->len;
|
||||||
while ((e = readdir(dir)) != NULL) {
|
while ((e = readdir(dir)) != NULL) {
|
||||||
|
|
4
entry.c
4
entry.c
|
@ -96,8 +96,8 @@ static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempf
|
||||||
{
|
{
|
||||||
int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
|
int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
|
||||||
if (to_tempfile) {
|
if (to_tempfile) {
|
||||||
strcpy(path, symlink
|
xsnprintf(path, TEMPORARY_FILENAME_LENGTH, "%s",
|
||||||
? ".merge_link_XXXXXX" : ".merge_file_XXXXXX");
|
symlink ? ".merge_link_XXXXXX" : ".merge_file_XXXXXX");
|
||||||
return mkstemp(path);
|
return mkstemp(path);
|
||||||
} else {
|
} else {
|
||||||
return create_file(path, !symlink ? ce->ce_mode : 0666);
|
return create_file(path, !symlink ? ce->ce_mode : 0666);
|
||||||
|
|
|
@ -143,11 +143,8 @@ static char *git_path_from_env(const char *envvar, const char *git_dir,
|
||||||
const char *path, int *fromenv)
|
const char *path, int *fromenv)
|
||||||
{
|
{
|
||||||
const char *value = getenv(envvar);
|
const char *value = getenv(envvar);
|
||||||
if (!value) {
|
if (!value)
|
||||||
char *buf = xmalloc(strlen(git_dir) + strlen(path) + 2);
|
return xstrfmt("%s/%s", git_dir, path);
|
||||||
sprintf(buf, "%s/%s", git_dir, path);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
if (fromenv)
|
if (fromenv)
|
||||||
*fromenv = 1;
|
*fromenv = 1;
|
||||||
return xstrdup(value);
|
return xstrdup(value);
|
||||||
|
|
|
@ -644,8 +644,9 @@ static void *pool_calloc(size_t count, size_t size)
|
||||||
|
|
||||||
static char *pool_strdup(const char *s)
|
static char *pool_strdup(const char *s)
|
||||||
{
|
{
|
||||||
char *r = pool_alloc(strlen(s) + 1);
|
size_t len = strlen(s) + 1;
|
||||||
strcpy(r, s);
|
char *r = pool_alloc(len);
|
||||||
|
memcpy(r, s, len);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,7 +703,7 @@ static struct atom_str *to_atom(const char *s, unsigned short len)
|
||||||
|
|
||||||
c = pool_alloc(sizeof(struct atom_str) + len + 1);
|
c = pool_alloc(sizeof(struct atom_str) + len + 1);
|
||||||
c->str_len = len;
|
c->str_len = len;
|
||||||
strncpy(c->str_dat, s, len);
|
memcpy(c->str_dat, s, len);
|
||||||
c->str_dat[len] = 0;
|
c->str_dat[len] = 0;
|
||||||
c->next_atom = atom_table[hc];
|
c->next_atom = atom_table[hc];
|
||||||
atom_table[hc] = c;
|
atom_table[hc] = c;
|
||||||
|
@ -863,13 +864,15 @@ static void start_packfile(void)
|
||||||
{
|
{
|
||||||
static char tmp_file[PATH_MAX];
|
static char tmp_file[PATH_MAX];
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
int namelen;
|
||||||
struct pack_header hdr;
|
struct pack_header hdr;
|
||||||
int pack_fd;
|
int pack_fd;
|
||||||
|
|
||||||
pack_fd = odb_mkstemp(tmp_file, sizeof(tmp_file),
|
pack_fd = odb_mkstemp(tmp_file, sizeof(tmp_file),
|
||||||
"pack/tmp_pack_XXXXXX");
|
"pack/tmp_pack_XXXXXX");
|
||||||
p = xcalloc(1, sizeof(*p) + strlen(tmp_file) + 2);
|
namelen = strlen(tmp_file) + 2;
|
||||||
strcpy(p->pack_name, tmp_file);
|
p = xcalloc(1, sizeof(*p) + namelen);
|
||||||
|
xsnprintf(p->pack_name, namelen, "%s", tmp_file);
|
||||||
p->pack_fd = pack_fd;
|
p->pack_fd = pack_fd;
|
||||||
p->do_not_close = 1;
|
p->do_not_close = 1;
|
||||||
pack_file = sha1fd(pack_fd, p->pack_name);
|
pack_file = sha1fd(pack_fd, p->pack_name);
|
||||||
|
@ -1035,8 +1038,8 @@ static int store_object(
|
||||||
git_SHA_CTX c;
|
git_SHA_CTX c;
|
||||||
git_zstream s;
|
git_zstream s;
|
||||||
|
|
||||||
hdrlen = sprintf((char *)hdr,"%s %lu", typename(type),
|
hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu",
|
||||||
(unsigned long)dat->len) + 1;
|
typename(type), (unsigned long)dat->len) + 1;
|
||||||
git_SHA1_Init(&c);
|
git_SHA1_Init(&c);
|
||||||
git_SHA1_Update(&c, hdr, hdrlen);
|
git_SHA1_Update(&c, hdr, hdrlen);
|
||||||
git_SHA1_Update(&c, dat->buf, dat->len);
|
git_SHA1_Update(&c, dat->buf, dat->len);
|
||||||
|
|
56
fetch-pack.c
56
fetch-pack.c
|
@ -681,11 +681,10 @@ static int get_pack(struct fetch_pack_args *args,
|
||||||
int xd[2], char **pack_lockfile)
|
int xd[2], char **pack_lockfile)
|
||||||
{
|
{
|
||||||
struct async demux;
|
struct async demux;
|
||||||
const char *argv[22];
|
|
||||||
char keep_arg[256];
|
|
||||||
char hdr_arg[256];
|
|
||||||
const char **av, *cmd_name;
|
|
||||||
int do_keep = args->keep_pack;
|
int do_keep = args->keep_pack;
|
||||||
|
const char *cmd_name;
|
||||||
|
struct pack_header header;
|
||||||
|
int pass_header = 0;
|
||||||
struct child_process cmd = CHILD_PROCESS_INIT;
|
struct child_process cmd = CHILD_PROCESS_INIT;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -705,17 +704,11 @@ static int get_pack(struct fetch_pack_args *args,
|
||||||
else
|
else
|
||||||
demux.out = xd[0];
|
demux.out = xd[0];
|
||||||
|
|
||||||
cmd.argv = argv;
|
|
||||||
av = argv;
|
|
||||||
*hdr_arg = 0;
|
|
||||||
if (!args->keep_pack && unpack_limit) {
|
if (!args->keep_pack && unpack_limit) {
|
||||||
struct pack_header header;
|
|
||||||
|
|
||||||
if (read_pack_header(demux.out, &header))
|
if (read_pack_header(demux.out, &header))
|
||||||
die("protocol error: bad pack header");
|
die("protocol error: bad pack header");
|
||||||
snprintf(hdr_arg, sizeof(hdr_arg),
|
pass_header = 1;
|
||||||
"--pack_header=%"PRIu32",%"PRIu32,
|
|
||||||
ntohl(header.hdr_version), ntohl(header.hdr_entries));
|
|
||||||
if (ntohl(header.hdr_entries) < unpack_limit)
|
if (ntohl(header.hdr_entries) < unpack_limit)
|
||||||
do_keep = 0;
|
do_keep = 0;
|
||||||
else
|
else
|
||||||
|
@ -723,44 +716,49 @@ static int get_pack(struct fetch_pack_args *args,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alternate_shallow_file) {
|
if (alternate_shallow_file) {
|
||||||
*av++ = "--shallow-file";
|
argv_array_push(&cmd.args, "--shallow-file");
|
||||||
*av++ = alternate_shallow_file;
|
argv_array_push(&cmd.args, alternate_shallow_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_keep) {
|
if (do_keep) {
|
||||||
if (pack_lockfile)
|
if (pack_lockfile)
|
||||||
cmd.out = -1;
|
cmd.out = -1;
|
||||||
*av++ = cmd_name = "index-pack";
|
cmd_name = "index-pack";
|
||||||
*av++ = "--stdin";
|
argv_array_push(&cmd.args, cmd_name);
|
||||||
|
argv_array_push(&cmd.args, "--stdin");
|
||||||
if (!args->quiet && !args->no_progress)
|
if (!args->quiet && !args->no_progress)
|
||||||
*av++ = "-v";
|
argv_array_push(&cmd.args, "-v");
|
||||||
if (args->use_thin_pack)
|
if (args->use_thin_pack)
|
||||||
*av++ = "--fix-thin";
|
argv_array_push(&cmd.args, "--fix-thin");
|
||||||
if (args->lock_pack || unpack_limit) {
|
if (args->lock_pack || unpack_limit) {
|
||||||
int s = sprintf(keep_arg,
|
char hostname[256];
|
||||||
"--keep=fetch-pack %"PRIuMAX " on ", (uintmax_t) getpid());
|
if (gethostname(hostname, sizeof(hostname)))
|
||||||
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
|
xsnprintf(hostname, sizeof(hostname), "localhost");
|
||||||
strcpy(keep_arg + s, "localhost");
|
argv_array_pushf(&cmd.args,
|
||||||
*av++ = keep_arg;
|
"--keep=fetch-pack %"PRIuMAX " on %s",
|
||||||
|
(uintmax_t)getpid(), hostname);
|
||||||
}
|
}
|
||||||
if (args->check_self_contained_and_connected)
|
if (args->check_self_contained_and_connected)
|
||||||
*av++ = "--check-self-contained-and-connected";
|
argv_array_push(&cmd.args, "--check-self-contained-and-connected");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*av++ = cmd_name = "unpack-objects";
|
cmd_name = "unpack-objects";
|
||||||
|
argv_array_push(&cmd.args, cmd_name);
|
||||||
if (args->quiet || args->no_progress)
|
if (args->quiet || args->no_progress)
|
||||||
*av++ = "-q";
|
argv_array_push(&cmd.args, "-q");
|
||||||
args->check_self_contained_and_connected = 0;
|
args->check_self_contained_and_connected = 0;
|
||||||
}
|
}
|
||||||
if (*hdr_arg)
|
|
||||||
*av++ = hdr_arg;
|
if (pass_header)
|
||||||
|
argv_array_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32,
|
||||||
|
ntohl(header.hdr_version),
|
||||||
|
ntohl(header.hdr_entries));
|
||||||
if (fetch_fsck_objects >= 0
|
if (fetch_fsck_objects >= 0
|
||||||
? fetch_fsck_objects
|
? fetch_fsck_objects
|
||||||
: transfer_fsck_objects >= 0
|
: transfer_fsck_objects >= 0
|
||||||
? transfer_fsck_objects
|
? transfer_fsck_objects
|
||||||
: 0)
|
: 0)
|
||||||
*av++ = "--strict";
|
argv_array_push(&cmd.args, "--strict");
|
||||||
*av++ = NULL;
|
|
||||||
|
|
||||||
cmd.in = demux.out;
|
cmd.in = demux.out;
|
||||||
cmd.git_cmd = 1;
|
cmd.git_cmd = 1;
|
||||||
|
|
|
@ -229,7 +229,7 @@ typedef unsigned long uintptr_t;
|
||||||
#else
|
#else
|
||||||
#define precompose_str(in,i_nfd2nfc)
|
#define precompose_str(in,i_nfd2nfc)
|
||||||
#define precompose_argv(c,v)
|
#define precompose_argv(c,v)
|
||||||
#define probe_utf8_pathname_composition(a,b)
|
#define probe_utf8_pathname_composition()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MKDIR_WO_TRAILING_SLASH
|
#ifdef MKDIR_WO_TRAILING_SLASH
|
||||||
|
@ -744,6 +744,9 @@ static inline size_t xsize_t(off_t len)
|
||||||
return (size_t)len;
|
return (size_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((format (printf, 3, 4)))
|
||||||
|
extern int xsnprintf(char *dst, size_t max, const char *fmt, ...);
|
||||||
|
|
||||||
/* in ctype.c, for kwset users */
|
/* in ctype.c, for kwset users */
|
||||||
extern const unsigned char tolower_trans_tbl[256];
|
extern const unsigned char tolower_trans_tbl[256];
|
||||||
|
|
||||||
|
|
36
grep.c
36
grep.c
|
@ -31,14 +31,14 @@ void init_grep_defaults(void)
|
||||||
opt->max_depth = -1;
|
opt->max_depth = -1;
|
||||||
opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED;
|
opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED;
|
||||||
opt->extended_regexp_option = 0;
|
opt->extended_regexp_option = 0;
|
||||||
strcpy(opt->color_context, "");
|
color_set(opt->color_context, "");
|
||||||
strcpy(opt->color_filename, "");
|
color_set(opt->color_filename, "");
|
||||||
strcpy(opt->color_function, "");
|
color_set(opt->color_function, "");
|
||||||
strcpy(opt->color_lineno, "");
|
color_set(opt->color_lineno, "");
|
||||||
strcpy(opt->color_match_context, GIT_COLOR_BOLD_RED);
|
color_set(opt->color_match_context, GIT_COLOR_BOLD_RED);
|
||||||
strcpy(opt->color_match_selected, GIT_COLOR_BOLD_RED);
|
color_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);
|
||||||
strcpy(opt->color_selected, "");
|
color_set(opt->color_selected, "");
|
||||||
strcpy(opt->color_sep, GIT_COLOR_CYAN);
|
color_set(opt->color_sep, GIT_COLOR_CYAN);
|
||||||
opt->color = -1;
|
opt->color = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,14 +151,14 @@ void grep_init(struct grep_opt *opt, const char *prefix)
|
||||||
opt->regflags = def->regflags;
|
opt->regflags = def->regflags;
|
||||||
opt->relative = def->relative;
|
opt->relative = def->relative;
|
||||||
|
|
||||||
strcpy(opt->color_context, def->color_context);
|
color_set(opt->color_context, def->color_context);
|
||||||
strcpy(opt->color_filename, def->color_filename);
|
color_set(opt->color_filename, def->color_filename);
|
||||||
strcpy(opt->color_function, def->color_function);
|
color_set(opt->color_function, def->color_function);
|
||||||
strcpy(opt->color_lineno, def->color_lineno);
|
color_set(opt->color_lineno, def->color_lineno);
|
||||||
strcpy(opt->color_match_context, def->color_match_context);
|
color_set(opt->color_match_context, def->color_match_context);
|
||||||
strcpy(opt->color_match_selected, def->color_match_selected);
|
color_set(opt->color_match_selected, def->color_match_selected);
|
||||||
strcpy(opt->color_selected, def->color_selected);
|
color_set(opt->color_selected, def->color_selected);
|
||||||
strcpy(opt->color_sep, def->color_sep);
|
color_set(opt->color_sep, def->color_sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt)
|
void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt)
|
||||||
|
@ -306,9 +306,9 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
|
||||||
char where[1024];
|
char where[1024];
|
||||||
|
|
||||||
if (p->no)
|
if (p->no)
|
||||||
sprintf(where, "In '%s' at %d, ", p->origin, p->no);
|
xsnprintf(where, sizeof(where), "In '%s' at %d, ", p->origin, p->no);
|
||||||
else if (p->origin)
|
else if (p->origin)
|
||||||
sprintf(where, "%s, ", p->origin);
|
xsnprintf(where, sizeof(where), "%s, ", p->origin);
|
||||||
else
|
else
|
||||||
where[0] = 0;
|
where[0] = 0;
|
||||||
|
|
||||||
|
|
13
hex.c
13
hex.c
|
@ -61,12 +61,10 @@ int get_oid_hex(const char *hex, struct object_id *oid)
|
||||||
return get_sha1_hex(hex, oid->hash);
|
return get_sha1_hex(hex, oid->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *sha1_to_hex(const unsigned char *sha1)
|
char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
static int bufno;
|
|
||||||
static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
|
|
||||||
static const char hex[] = "0123456789abcdef";
|
static const char hex[] = "0123456789abcdef";
|
||||||
char *buffer = hexbuffer[3 & ++bufno], *buf = buffer;
|
char *buf = buffer;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
|
for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
|
||||||
|
@ -79,6 +77,13 @@ char *sha1_to_hex(const unsigned char *sha1)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *sha1_to_hex(const unsigned char *sha1)
|
||||||
|
{
|
||||||
|
static int bufno;
|
||||||
|
static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
|
||||||
|
return sha1_to_hex_r(hexbuffer[3 & ++bufno], sha1);
|
||||||
|
}
|
||||||
|
|
||||||
char *oid_to_hex(const struct object_id *oid)
|
char *oid_to_hex(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
return sha1_to_hex(oid->hash);
|
return sha1_to_hex(oid->hash);
|
||||||
|
|
65
http-push.c
65
http-push.c
|
@ -10,6 +10,7 @@
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "list-objects.h"
|
#include "list-objects.h"
|
||||||
#include "sigchain.h"
|
#include "sigchain.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
#ifdef EXPAT_NEEDS_XMLPARSE_H
|
#ifdef EXPAT_NEEDS_XMLPARSE_H
|
||||||
#include <xmlparse.h>
|
#include <xmlparse.h>
|
||||||
|
@ -361,7 +362,7 @@ static void start_put(struct transfer_request *request)
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
|
|
||||||
unpacked = read_sha1_file(request->obj->sha1, &type, &len);
|
unpacked = read_sha1_file(request->obj->sha1, &type, &len);
|
||||||
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
||||||
|
|
||||||
/* Set it up */
|
/* Set it up */
|
||||||
git_deflate_init(&stream, zlib_compression_level);
|
git_deflate_init(&stream, zlib_compression_level);
|
||||||
|
@ -786,21 +787,21 @@ xml_start_tag(void *userData, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
struct xml_ctx *ctx = (struct xml_ctx *)userData;
|
struct xml_ctx *ctx = (struct xml_ctx *)userData;
|
||||||
const char *c = strchr(name, ':');
|
const char *c = strchr(name, ':');
|
||||||
int new_len;
|
int old_namelen, new_len;
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
c = name;
|
c = name;
|
||||||
else
|
else
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
new_len = strlen(ctx->name) + strlen(c) + 2;
|
old_namelen = strlen(ctx->name);
|
||||||
|
new_len = old_namelen + strlen(c) + 2;
|
||||||
|
|
||||||
if (new_len > ctx->len) {
|
if (new_len > ctx->len) {
|
||||||
ctx->name = xrealloc(ctx->name, new_len);
|
ctx->name = xrealloc(ctx->name, new_len);
|
||||||
ctx->len = new_len;
|
ctx->len = new_len;
|
||||||
}
|
}
|
||||||
strcat(ctx->name, ".");
|
xsnprintf(ctx->name + old_namelen, ctx->len - old_namelen, ".%s", c);
|
||||||
strcat(ctx->name, c);
|
|
||||||
|
|
||||||
free(ctx->cdata);
|
free(ctx->cdata);
|
||||||
ctx->cdata = NULL;
|
ctx->cdata = NULL;
|
||||||
|
@ -881,7 +882,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
|
||||||
strbuf_addf(&out_buffer.buf, LOCK_REQUEST, escaped);
|
strbuf_addf(&out_buffer.buf, LOCK_REQUEST, escaped);
|
||||||
free(escaped);
|
free(escaped);
|
||||||
|
|
||||||
sprintf(timeout_header, "Timeout: Second-%ld", timeout);
|
xsnprintf(timeout_header, sizeof(timeout_header), "Timeout: Second-%ld", timeout);
|
||||||
dav_headers = curl_slist_append(dav_headers, timeout_header);
|
dav_headers = curl_slist_append(dav_headers, timeout_header);
|
||||||
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
|
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
|
||||||
|
|
||||||
|
@ -1459,8 +1460,6 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
|
||||||
{
|
{
|
||||||
struct strbuf *buf = (struct strbuf *)ls->userData;
|
struct strbuf *buf = (struct strbuf *)ls->userData;
|
||||||
struct object *o;
|
struct object *o;
|
||||||
int len;
|
|
||||||
char *ref_info;
|
|
||||||
struct ref *ref;
|
struct ref *ref;
|
||||||
|
|
||||||
ref = alloc_ref(ls->dentry_name);
|
ref = alloc_ref(ls->dentry_name);
|
||||||
|
@ -1484,23 +1483,14 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(ls->dentry_name) + 42;
|
strbuf_addf(buf, "%s\t%s\n",
|
||||||
ref_info = xcalloc(len + 1, 1);
|
|
||||||
sprintf(ref_info, "%s %s\n",
|
|
||||||
sha1_to_hex(ref->old_sha1), ls->dentry_name);
|
sha1_to_hex(ref->old_sha1), ls->dentry_name);
|
||||||
fwrite_buffer(ref_info, 1, len, buf);
|
|
||||||
free(ref_info);
|
|
||||||
|
|
||||||
if (o->type == OBJ_TAG) {
|
if (o->type == OBJ_TAG) {
|
||||||
o = deref_tag(o, ls->dentry_name, 0);
|
o = deref_tag(o, ls->dentry_name, 0);
|
||||||
if (o) {
|
if (o)
|
||||||
len = strlen(ls->dentry_name) + 45;
|
strbuf_addf(buf, "%s\t%s^{}\n",
|
||||||
ref_info = xcalloc(len + 1, 1);
|
|
||||||
sprintf(ref_info, "%s %s^{}\n",
|
|
||||||
sha1_to_hex(o->sha1), ls->dentry_name);
|
sha1_to_hex(o->sha1), ls->dentry_name);
|
||||||
fwrite_buffer(ref_info, 1, len, buf);
|
|
||||||
free(ref_info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
|
@ -1866,10 +1856,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
new_refs = 0;
|
new_refs = 0;
|
||||||
for (ref = remote_refs; ref; ref = ref->next) {
|
for (ref = remote_refs; ref; ref = ref->next) {
|
||||||
char old_hex[60], *new_hex;
|
struct argv_array commit_argv = ARGV_ARRAY_INIT;
|
||||||
const char *commit_argv[5];
|
|
||||||
int commit_argc;
|
|
||||||
char *new_sha1_hex, *old_sha1_hex;
|
|
||||||
|
|
||||||
if (!ref->peer_ref)
|
if (!ref->peer_ref)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1923,13 +1910,12 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
|
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
|
||||||
new_refs++;
|
new_refs++;
|
||||||
strcpy(old_hex, sha1_to_hex(ref->old_sha1));
|
|
||||||
new_hex = sha1_to_hex(ref->new_sha1);
|
|
||||||
|
|
||||||
fprintf(stderr, "updating '%s'", ref->name);
|
fprintf(stderr, "updating '%s'", ref->name);
|
||||||
if (strcmp(ref->name, ref->peer_ref->name))
|
if (strcmp(ref->name, ref->peer_ref->name))
|
||||||
fprintf(stderr, " using '%s'", ref->peer_ref->name);
|
fprintf(stderr, " using '%s'", ref->peer_ref->name);
|
||||||
fprintf(stderr, "\n from %s\n to %s\n", old_hex, new_hex);
|
fprintf(stderr, "\n from %s\n to %s\n",
|
||||||
|
sha1_to_hex(ref->old_sha1), sha1_to_hex(ref->new_sha1));
|
||||||
if (dry_run) {
|
if (dry_run) {
|
||||||
if (helper_status)
|
if (helper_status)
|
||||||
printf("ok %s\n", ref->name);
|
printf("ok %s\n", ref->name);
|
||||||
|
@ -1948,27 +1934,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up revision info for this refspec */
|
/* Set up revision info for this refspec */
|
||||||
commit_argc = 3;
|
argv_array_push(&commit_argv, ""); /* ignored */
|
||||||
new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));
|
argv_array_push(&commit_argv, "--objects");
|
||||||
old_sha1_hex = NULL;
|
argv_array_push(&commit_argv, sha1_to_hex(ref->new_sha1));
|
||||||
commit_argv[1] = "--objects";
|
if (!push_all && !is_null_sha1(ref->old_sha1))
|
||||||
commit_argv[2] = new_sha1_hex;
|
argv_array_pushf(&commit_argv, "^%s",
|
||||||
if (!push_all && !is_null_sha1(ref->old_sha1)) {
|
|
||||||
old_sha1_hex = xmalloc(42);
|
|
||||||
sprintf(old_sha1_hex, "^%s",
|
|
||||||
sha1_to_hex(ref->old_sha1));
|
sha1_to_hex(ref->old_sha1));
|
||||||
commit_argv[3] = old_sha1_hex;
|
|
||||||
commit_argc++;
|
|
||||||
}
|
|
||||||
commit_argv[commit_argc] = NULL;
|
|
||||||
init_revisions(&revs, setup_git_directory());
|
init_revisions(&revs, setup_git_directory());
|
||||||
setup_revisions(commit_argc, commit_argv, &revs, NULL);
|
setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL);
|
||||||
revs.edge_hint = 0; /* just in case */
|
revs.edge_hint = 0; /* just in case */
|
||||||
free(new_sha1_hex);
|
|
||||||
if (old_sha1_hex) {
|
|
||||||
free(old_sha1_hex);
|
|
||||||
commit_argv[1] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generate a list of objects that need to be pushed */
|
/* Generate a list of objects that need to be pushed */
|
||||||
pushing = 0;
|
pushing = 0;
|
||||||
|
@ -1997,6 +1971,7 @@ int main(int argc, char **argv)
|
||||||
printf("%s %s\n", !rc ? "ok" : "error", ref->name);
|
printf("%s %s\n", !rc ? "ok" : "error", ref->name);
|
||||||
unlock_remote(ref_lock);
|
unlock_remote(ref_lock);
|
||||||
check_locks();
|
check_locks();
|
||||||
|
argv_array_clear(&commit_argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update remote server info if appropriate */
|
/* Update remote server info if appropriate */
|
||||||
|
|
|
@ -29,7 +29,7 @@ struct object_request {
|
||||||
struct alternates_request {
|
struct alternates_request {
|
||||||
struct walker *walker;
|
struct walker *walker;
|
||||||
const char *base;
|
const char *base;
|
||||||
char *url;
|
struct strbuf *url;
|
||||||
struct strbuf *buffer;
|
struct strbuf *buffer;
|
||||||
struct active_request_slot *slot;
|
struct active_request_slot *slot;
|
||||||
int http_specific;
|
int http_specific;
|
||||||
|
@ -195,10 +195,11 @@ static void process_alternates_response(void *callback_data)
|
||||||
|
|
||||||
/* Try reusing the slot to get non-http alternates */
|
/* Try reusing the slot to get non-http alternates */
|
||||||
alt_req->http_specific = 0;
|
alt_req->http_specific = 0;
|
||||||
sprintf(alt_req->url, "%s/objects/info/alternates",
|
strbuf_reset(alt_req->url);
|
||||||
|
strbuf_addf(alt_req->url, "%s/objects/info/alternates",
|
||||||
base);
|
base);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_URL,
|
curl_easy_setopt(slot->curl, CURLOPT_URL,
|
||||||
alt_req->url);
|
alt_req->url->buf);
|
||||||
active_requests++;
|
active_requests++;
|
||||||
slot->in_use = 1;
|
slot->in_use = 1;
|
||||||
if (slot->finished != NULL)
|
if (slot->finished != NULL)
|
||||||
|
@ -312,7 +313,7 @@ static void process_alternates_response(void *callback_data)
|
||||||
static void fetch_alternates(struct walker *walker, const char *base)
|
static void fetch_alternates(struct walker *walker, const char *base)
|
||||||
{
|
{
|
||||||
struct strbuf buffer = STRBUF_INIT;
|
struct strbuf buffer = STRBUF_INIT;
|
||||||
char *url;
|
struct strbuf url = STRBUF_INIT;
|
||||||
struct active_request_slot *slot;
|
struct active_request_slot *slot;
|
||||||
struct alternates_request alt_req;
|
struct alternates_request alt_req;
|
||||||
struct walker_data *cdata = walker->data;
|
struct walker_data *cdata = walker->data;
|
||||||
|
@ -338,7 +339,7 @@ static void fetch_alternates(struct walker *walker, const char *base)
|
||||||
if (walker->get_verbosely)
|
if (walker->get_verbosely)
|
||||||
fprintf(stderr, "Getting alternates list for %s\n", base);
|
fprintf(stderr, "Getting alternates list for %s\n", base);
|
||||||
|
|
||||||
url = xstrfmt("%s/objects/info/http-alternates", base);
|
strbuf_addf(&url, "%s/objects/info/http-alternates", base);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use a callback to process the result, since another request
|
* Use a callback to process the result, since another request
|
||||||
|
@ -351,10 +352,10 @@ static void fetch_alternates(struct walker *walker, const char *base)
|
||||||
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
|
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
|
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
|
curl_easy_setopt(slot->curl, CURLOPT_URL, url.buf);
|
||||||
|
|
||||||
alt_req.base = base;
|
alt_req.base = base;
|
||||||
alt_req.url = url;
|
alt_req.url = &url;
|
||||||
alt_req.buffer = &buffer;
|
alt_req.buffer = &buffer;
|
||||||
alt_req.http_specific = 1;
|
alt_req.http_specific = 1;
|
||||||
alt_req.slot = slot;
|
alt_req.slot = slot;
|
||||||
|
@ -365,7 +366,7 @@ static void fetch_alternates(struct walker *walker, const char *base)
|
||||||
cdata->got_alternates = -1;
|
cdata->got_alternates = -1;
|
||||||
|
|
||||||
strbuf_release(&buffer);
|
strbuf_release(&buffer);
|
||||||
free(url);
|
strbuf_release(&url);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fetch_indices(struct walker *walker, struct alt_base *repo)
|
static int fetch_indices(struct walker *walker, struct alt_base *repo)
|
||||||
|
|
13
http.c
13
http.c
|
@ -1122,7 +1122,7 @@ static void write_accept_language(struct strbuf *buf)
|
||||||
decimal_places++, max_q *= 10)
|
decimal_places++, max_q *= 10)
|
||||||
;
|
;
|
||||||
|
|
||||||
sprintf(q_format, ";q=0.%%0%dd", decimal_places);
|
xsnprintf(q_format, sizeof(q_format), ";q=0.%%0%dd", decimal_places);
|
||||||
|
|
||||||
strbuf_addstr(buf, "Accept-Language: ");
|
strbuf_addstr(buf, "Accept-Language: ");
|
||||||
|
|
||||||
|
@ -1529,6 +1529,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
|
||||||
struct packed_git **lst;
|
struct packed_git **lst;
|
||||||
struct packed_git *p = preq->target;
|
struct packed_git *p = preq->target;
|
||||||
char *tmp_idx;
|
char *tmp_idx;
|
||||||
|
size_t len;
|
||||||
struct child_process ip = CHILD_PROCESS_INIT;
|
struct child_process ip = CHILD_PROCESS_INIT;
|
||||||
const char *ip_argv[8];
|
const char *ip_argv[8];
|
||||||
|
|
||||||
|
@ -1542,9 +1543,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
|
||||||
lst = &((*lst)->next);
|
lst = &((*lst)->next);
|
||||||
*lst = (*lst)->next;
|
*lst = (*lst)->next;
|
||||||
|
|
||||||
tmp_idx = xstrdup(preq->tmpfile);
|
if (!strip_suffix(preq->tmpfile, ".pack.temp", &len))
|
||||||
strcpy(tmp_idx + strlen(tmp_idx) - strlen(".pack.temp"),
|
die("BUG: pack tmpfile does not end in .pack.temp?");
|
||||||
".idx.temp");
|
tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile);
|
||||||
|
|
||||||
ip_argv[0] = "index-pack";
|
ip_argv[0] = "index-pack";
|
||||||
ip_argv[1] = "-o";
|
ip_argv[1] = "-o";
|
||||||
|
@ -1619,7 +1620,7 @@ struct http_pack_request *new_http_pack_request(
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Resuming fetch of pack %s at byte %ld\n",
|
"Resuming fetch of pack %s at byte %ld\n",
|
||||||
sha1_to_hex(target->sha1), prev_posn);
|
sha1_to_hex(target->sha1), prev_posn);
|
||||||
sprintf(range, "Range: bytes=%ld-", prev_posn);
|
xsnprintf(range, sizeof(range), "Range: bytes=%ld-", prev_posn);
|
||||||
preq->range_header = curl_slist_append(NULL, range);
|
preq->range_header = curl_slist_append(NULL, range);
|
||||||
curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER,
|
curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER,
|
||||||
preq->range_header);
|
preq->range_header);
|
||||||
|
@ -1779,7 +1780,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Resuming fetch of object %s at byte %ld\n",
|
"Resuming fetch of object %s at byte %ld\n",
|
||||||
hex, prev_posn);
|
hex, prev_posn);
|
||||||
sprintf(range, "Range: bytes=%ld-", prev_posn);
|
xsnprintf(range, sizeof(range), "Range: bytes=%ld-", prev_posn);
|
||||||
range_header = curl_slist_append(range_header, range);
|
range_header = curl_slist_append(range_header, range);
|
||||||
curl_easy_setopt(freq->slot->curl,
|
curl_easy_setopt(freq->slot->curl,
|
||||||
CURLOPT_HTTPHEADER, range_header);
|
CURLOPT_HTTPHEADER, range_header);
|
||||||
|
|
|
@ -889,9 +889,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* response: "<user> <digest in hex>" */
|
/* response: "<user> <digest in hex>" */
|
||||||
resp_len = strlen(user) + 1 + strlen(hex) + 1;
|
response = xstrfmt("%s %s", user, hex);
|
||||||
response = xmalloc(resp_len);
|
resp_len = strlen(response) + 1;
|
||||||
sprintf(response, "%s %s", user, hex);
|
|
||||||
|
|
||||||
response_64 = xmalloc(ENCODED_SIZE(resp_len) + 1);
|
response_64 = xmalloc(ENCODED_SIZE(resp_len) + 1);
|
||||||
encoded_len = EVP_EncodeBlock((unsigned char *)response_64,
|
encoded_len = EVP_EncodeBlock((unsigned char *)response_64,
|
||||||
|
|
12
ll-merge.c
12
ll-merge.c
|
@ -145,11 +145,11 @@ static struct ll_merge_driver ll_merge_drv[] = {
|
||||||
{ "union", "built-in union merge", ll_union_merge },
|
{ "union", "built-in union merge", ll_union_merge },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void create_temp(mmfile_t *src, char *path)
|
static void create_temp(mmfile_t *src, char *path, size_t len)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
strcpy(path, ".merge_file_XXXXXX");
|
xsnprintf(path, len, ".merge_file_XXXXXX");
|
||||||
fd = xmkstemp(path);
|
fd = xmkstemp(path);
|
||||||
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
||||||
die_errno("unable to write temp-file");
|
die_errno("unable to write temp-file");
|
||||||
|
@ -190,10 +190,10 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
|
||||||
|
|
||||||
result->ptr = NULL;
|
result->ptr = NULL;
|
||||||
result->size = 0;
|
result->size = 0;
|
||||||
create_temp(orig, temp[0]);
|
create_temp(orig, temp[0], sizeof(temp[0]));
|
||||||
create_temp(src1, temp[1]);
|
create_temp(src1, temp[1], sizeof(temp[1]));
|
||||||
create_temp(src2, temp[2]);
|
create_temp(src2, temp[2], sizeof(temp[2]));
|
||||||
sprintf(temp[3], "%d", marker_size);
|
xsnprintf(temp[3], sizeof(temp[3]), "%d", marker_size);
|
||||||
|
|
||||||
strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
|
strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
|
||||||
|
|
||||||
|
|
|
@ -162,11 +162,10 @@ static void read_mailmap_line(struct string_list *map, char *buffer,
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
free(*repo_abbrev);
|
free(*repo_abbrev);
|
||||||
*repo_abbrev = xmalloc(len);
|
|
||||||
|
|
||||||
for (cp = buffer + abblen; isspace(*cp); cp++)
|
for (cp = buffer + abblen; isspace(*cp); cp++)
|
||||||
; /* nothing */
|
; /* nothing */
|
||||||
strcpy(*repo_abbrev, cp);
|
*repo_abbrev = xstrdup(cp);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -630,25 +630,24 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
|
||||||
|
|
||||||
static int dir_in_way(const char *path, int check_working_copy)
|
static int dir_in_way(const char *path, int check_working_copy)
|
||||||
{
|
{
|
||||||
int pos, pathlen = strlen(path);
|
int pos;
|
||||||
char *dirpath = xmalloc(pathlen + 2);
|
struct strbuf dirpath = STRBUF_INIT;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
strcpy(dirpath, path);
|
strbuf_addstr(&dirpath, path);
|
||||||
dirpath[pathlen] = '/';
|
strbuf_addch(&dirpath, '/');
|
||||||
dirpath[pathlen+1] = '\0';
|
|
||||||
|
|
||||||
pos = cache_name_pos(dirpath, pathlen+1);
|
pos = cache_name_pos(dirpath.buf, dirpath.len);
|
||||||
|
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = -1 - pos;
|
pos = -1 - pos;
|
||||||
if (pos < active_nr &&
|
if (pos < active_nr &&
|
||||||
!strncmp(dirpath, active_cache[pos]->name, pathlen+1)) {
|
!strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {
|
||||||
free(dirpath);
|
strbuf_release(&dirpath);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(dirpath);
|
strbuf_release(&dirpath);
|
||||||
return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
|
return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
notes.c
9
notes.c
|
@ -539,6 +539,9 @@ static unsigned char determine_fanout(struct int_node *tree, unsigned char n,
|
||||||
return fanout + 1;
|
return fanout + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* hex SHA1 + 19 * '/' + NUL */
|
||||||
|
#define FANOUT_PATH_MAX 40 + 19 + 1
|
||||||
|
|
||||||
static void construct_path_with_fanout(const unsigned char *sha1,
|
static void construct_path_with_fanout(const unsigned char *sha1,
|
||||||
unsigned char fanout, char *path)
|
unsigned char fanout, char *path)
|
||||||
{
|
{
|
||||||
|
@ -551,7 +554,7 @@ static void construct_path_with_fanout(const unsigned char *sha1,
|
||||||
path[i++] = '/';
|
path[i++] = '/';
|
||||||
fanout--;
|
fanout--;
|
||||||
}
|
}
|
||||||
strcpy(path + i, hex_sha1 + j);
|
xsnprintf(path + i, FANOUT_PATH_MAX - i, "%s", hex_sha1 + j);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int for_each_note_helper(struct notes_tree *t, struct int_node *tree,
|
static int for_each_note_helper(struct notes_tree *t, struct int_node *tree,
|
||||||
|
@ -562,7 +565,7 @@ static int for_each_note_helper(struct notes_tree *t, struct int_node *tree,
|
||||||
void *p;
|
void *p;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct leaf_node *l;
|
struct leaf_node *l;
|
||||||
static char path[40 + 19 + 1]; /* hex SHA1 + 19 * '/' + NUL */
|
static char path[FANOUT_PATH_MAX];
|
||||||
|
|
||||||
fanout = determine_fanout(tree, n, fanout);
|
fanout = determine_fanout(tree, n, fanout);
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
|
@ -595,7 +598,7 @@ redo:
|
||||||
/* invoke callback with subtree */
|
/* invoke callback with subtree */
|
||||||
unsigned int path_len =
|
unsigned int path_len =
|
||||||
l->key_sha1[19] * 2 + fanout;
|
l->key_sha1[19] * 2 + fanout;
|
||||||
assert(path_len < 40 + 19);
|
assert(path_len < FANOUT_PATH_MAX - 1);
|
||||||
construct_path_with_fanout(l->key_sha1, fanout,
|
construct_path_with_fanout(l->key_sha1, fanout,
|
||||||
path);
|
path);
|
||||||
/* Create trailing slash, if needed */
|
/* Create trailing slash, if needed */
|
||||||
|
|
|
@ -252,16 +252,11 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
|
||||||
|
|
||||||
static char *pack_bitmap_filename(struct packed_git *p)
|
static char *pack_bitmap_filename(struct packed_git *p)
|
||||||
{
|
{
|
||||||
char *idx_name;
|
size_t len;
|
||||||
int len;
|
|
||||||
|
|
||||||
len = strlen(p->pack_name) - strlen(".pack");
|
if (!strip_suffix(p->pack_name, ".pack", &len))
|
||||||
idx_name = xmalloc(len + strlen(".bitmap") + 1);
|
die("BUG: pack_name does not end in .pack");
|
||||||
|
return xstrfmt("%.*s.bitmap", (int)len, p->pack_name);
|
||||||
memcpy(idx_name, p->pack_name, len);
|
|
||||||
memcpy(idx_name + len, ".bitmap", strlen(".bitmap") + 1);
|
|
||||||
|
|
||||||
return idx_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_pack_bitmap_1(struct packed_git *packfile)
|
static int open_pack_bitmap_1(struct packed_git *packfile)
|
||||||
|
|
80
path.c
80
path.c
|
@ -395,6 +395,16 @@ static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)
|
||||||
strbuf_cleanup_path(buf);
|
strbuf_cleanup_path(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
strbuf_reset(buf);
|
||||||
|
va_start(args, fmt);
|
||||||
|
do_git_path(buf, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return buf->buf;
|
||||||
|
}
|
||||||
|
|
||||||
void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -452,8 +462,7 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
|
||||||
struct strbuf git_submodule_dir = STRBUF_INIT;
|
struct strbuf git_submodule_dir = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_addstr(buf, path);
|
strbuf_addstr(buf, path);
|
||||||
if (buf->len && buf->buf[buf->len - 1] != '/')
|
strbuf_complete(buf, '/');
|
||||||
strbuf_addch(buf, '/');
|
|
||||||
strbuf_addstr(buf, ".git");
|
strbuf_addstr(buf, ".git");
|
||||||
|
|
||||||
git_dir = read_gitfile(buf->buf);
|
git_dir = read_gitfile(buf->buf);
|
||||||
|
@ -611,8 +620,8 @@ return_null:
|
||||||
*/
|
*/
|
||||||
const char *enter_repo(const char *path, int strict)
|
const char *enter_repo(const char *path, int strict)
|
||||||
{
|
{
|
||||||
static char used_path[PATH_MAX];
|
static struct strbuf validated_path = STRBUF_INIT;
|
||||||
static char validated_path[PATH_MAX];
|
static struct strbuf used_path = STRBUF_INIT;
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -627,46 +636,47 @@ const char *enter_repo(const char *path, int strict)
|
||||||
while ((1 < len) && (path[len-1] == '/'))
|
while ((1 < len) && (path[len-1] == '/'))
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can handle arbitrary-sized buffers, but this remains as a
|
||||||
|
* sanity check on untrusted input.
|
||||||
|
*/
|
||||||
if (PATH_MAX <= len)
|
if (PATH_MAX <= len)
|
||||||
return NULL;
|
return NULL;
|
||||||
strncpy(used_path, path, len); used_path[len] = 0 ;
|
|
||||||
strcpy(validated_path, used_path);
|
|
||||||
|
|
||||||
if (used_path[0] == '~') {
|
strbuf_reset(&used_path);
|
||||||
char *newpath = expand_user_path(used_path);
|
strbuf_reset(&validated_path);
|
||||||
if (!newpath || (PATH_MAX - 10 < strlen(newpath))) {
|
strbuf_add(&used_path, path, len);
|
||||||
free(newpath);
|
strbuf_add(&validated_path, path, len);
|
||||||
|
|
||||||
|
if (used_path.buf[0] == '~') {
|
||||||
|
char *newpath = expand_user_path(used_path.buf);
|
||||||
|
if (!newpath)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
strbuf_attach(&used_path, newpath, strlen(newpath),
|
||||||
|
strlen(newpath));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Copy back into the static buffer. A pity
|
|
||||||
* since newpath was not bounded, but other
|
|
||||||
* branches of the if are limited by PATH_MAX
|
|
||||||
* anyway.
|
|
||||||
*/
|
|
||||||
strcpy(used_path, newpath); free(newpath);
|
|
||||||
}
|
|
||||||
else if (PATH_MAX - 10 < len)
|
|
||||||
return NULL;
|
|
||||||
len = strlen(used_path);
|
|
||||||
for (i = 0; suffix[i]; i++) {
|
for (i = 0; suffix[i]; i++) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
strcpy(used_path + len, suffix[i]);
|
size_t baselen = used_path.len;
|
||||||
if (!stat(used_path, &st) &&
|
strbuf_addstr(&used_path, suffix[i]);
|
||||||
|
if (!stat(used_path.buf, &st) &&
|
||||||
(S_ISREG(st.st_mode) ||
|
(S_ISREG(st.st_mode) ||
|
||||||
(S_ISDIR(st.st_mode) && is_git_directory(used_path)))) {
|
(S_ISDIR(st.st_mode) && is_git_directory(used_path.buf)))) {
|
||||||
strcat(validated_path, suffix[i]);
|
strbuf_addstr(&validated_path, suffix[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
strbuf_setlen(&used_path, baselen);
|
||||||
}
|
}
|
||||||
if (!suffix[i])
|
if (!suffix[i])
|
||||||
return NULL;
|
return NULL;
|
||||||
gitfile = read_gitfile(used_path);
|
gitfile = read_gitfile(used_path.buf);
|
||||||
if (gitfile)
|
if (gitfile) {
|
||||||
strcpy(used_path, gitfile);
|
strbuf_reset(&used_path);
|
||||||
if (chdir(used_path))
|
strbuf_addstr(&used_path, gitfile);
|
||||||
|
}
|
||||||
|
if (chdir(used_path.buf))
|
||||||
return NULL;
|
return NULL;
|
||||||
path = validated_path;
|
path = validated_path.buf;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const char *gitfile = read_gitfile(path);
|
const char *gitfile = read_gitfile(path);
|
||||||
|
@ -855,7 +865,7 @@ const char *relative_path(const char *in, const char *prefix,
|
||||||
*/
|
*/
|
||||||
const char *remove_leading_path(const char *in, const char *prefix)
|
const char *remove_leading_path(const char *in, const char *prefix)
|
||||||
{
|
{
|
||||||
static char buf[PATH_MAX + 1];
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
if (!prefix || !prefix[0])
|
if (!prefix || !prefix[0])
|
||||||
|
@ -884,11 +894,13 @@ const char *remove_leading_path(const char *in, const char *prefix)
|
||||||
return in;
|
return in;
|
||||||
while (is_dir_sep(in[j]))
|
while (is_dir_sep(in[j]))
|
||||||
j++;
|
j++;
|
||||||
|
|
||||||
|
strbuf_reset(&buf);
|
||||||
if (!in[j])
|
if (!in[j])
|
||||||
strcpy(buf, ".");
|
strbuf_addstr(&buf, ".");
|
||||||
else
|
else
|
||||||
strcpy(buf, in + j);
|
strbuf_addstr(&buf, in + j);
|
||||||
return buf;
|
return buf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
20
progress.c
20
progress.c
|
@ -25,7 +25,7 @@ struct throughput {
|
||||||
unsigned int last_bytes[TP_IDX_MAX];
|
unsigned int last_bytes[TP_IDX_MAX];
|
||||||
unsigned int last_misecs[TP_IDX_MAX];
|
unsigned int last_misecs[TP_IDX_MAX];
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
char display[32];
|
struct strbuf display;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct progress {
|
struct progress {
|
||||||
|
@ -98,7 +98,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress->last_value = n;
|
progress->last_value = n;
|
||||||
tp = (progress->throughput) ? progress->throughput->display : "";
|
tp = (progress->throughput) ? progress->throughput->display.buf : "";
|
||||||
eol = done ? done : " \r";
|
eol = done ? done : " \r";
|
||||||
if (progress->total) {
|
if (progress->total) {
|
||||||
unsigned percent = n * 100 / progress->total;
|
unsigned percent = n * 100 / progress->total;
|
||||||
|
@ -129,6 +129,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
|
||||||
static void throughput_string(struct strbuf *buf, off_t total,
|
static void throughput_string(struct strbuf *buf, off_t total,
|
||||||
unsigned int rate)
|
unsigned int rate)
|
||||||
{
|
{
|
||||||
|
strbuf_reset(buf);
|
||||||
strbuf_addstr(buf, ", ");
|
strbuf_addstr(buf, ", ");
|
||||||
strbuf_humanise_bytes(buf, total);
|
strbuf_humanise_bytes(buf, total);
|
||||||
strbuf_addstr(buf, " | ");
|
strbuf_addstr(buf, " | ");
|
||||||
|
@ -141,7 +142,6 @@ void display_throughput(struct progress *progress, off_t total)
|
||||||
struct throughput *tp;
|
struct throughput *tp;
|
||||||
uint64_t now_ns;
|
uint64_t now_ns;
|
||||||
unsigned int misecs, count, rate;
|
unsigned int misecs, count, rate;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
|
|
||||||
if (!progress)
|
if (!progress)
|
||||||
return;
|
return;
|
||||||
|
@ -154,6 +154,7 @@ void display_throughput(struct progress *progress, off_t total)
|
||||||
if (tp) {
|
if (tp) {
|
||||||
tp->prev_total = tp->curr_total = total;
|
tp->prev_total = tp->curr_total = total;
|
||||||
tp->prev_ns = now_ns;
|
tp->prev_ns = now_ns;
|
||||||
|
strbuf_init(&tp->display, 0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -193,9 +194,7 @@ void display_throughput(struct progress *progress, off_t total)
|
||||||
tp->last_misecs[tp->idx] = misecs;
|
tp->last_misecs[tp->idx] = misecs;
|
||||||
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
|
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
|
||||||
|
|
||||||
throughput_string(&buf, total, rate);
|
throughput_string(&tp->display, total, rate);
|
||||||
strncpy(tp->display, buf.buf, sizeof(tp->display));
|
|
||||||
strbuf_release(&buf);
|
|
||||||
if (progress->last_value != -1 && progress_update)
|
if (progress->last_value != -1 && progress_update)
|
||||||
display(progress, progress->last_value, NULL);
|
display(progress, progress->last_value, NULL);
|
||||||
}
|
}
|
||||||
|
@ -250,20 +249,19 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
|
||||||
|
|
||||||
bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
|
bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
|
||||||
if (tp) {
|
if (tp) {
|
||||||
struct strbuf strbuf = STRBUF_INIT;
|
|
||||||
unsigned int rate = !tp->avg_misecs ? 0 :
|
unsigned int rate = !tp->avg_misecs ? 0 :
|
||||||
tp->avg_bytes / tp->avg_misecs;
|
tp->avg_bytes / tp->avg_misecs;
|
||||||
throughput_string(&strbuf, tp->curr_total, rate);
|
throughput_string(&tp->display, tp->curr_total, rate);
|
||||||
strncpy(tp->display, strbuf.buf, sizeof(tp->display));
|
|
||||||
strbuf_release(&strbuf);
|
|
||||||
}
|
}
|
||||||
progress_update = 1;
|
progress_update = 1;
|
||||||
sprintf(bufp, ", %s.\n", msg);
|
xsnprintf(bufp, len + 1, ", %s.\n", msg);
|
||||||
display(progress, progress->last_value, bufp);
|
display(progress, progress->last_value, bufp);
|
||||||
if (buf != bufp)
|
if (buf != bufp)
|
||||||
free(bufp);
|
free(bufp);
|
||||||
}
|
}
|
||||||
clear_progress_signal();
|
clear_progress_signal();
|
||||||
|
if (progress->throughput)
|
||||||
|
strbuf_release(&progress->throughput->display);
|
||||||
free(progress->throughput);
|
free(progress->throughput);
|
||||||
free(progress);
|
free(progress);
|
||||||
}
|
}
|
||||||
|
|
68
ref-filter.c
68
ref-filter.c
|
@ -343,9 +343,7 @@ static int grab_objectname(const char *name, const unsigned char *sha1,
|
||||||
struct atom_value *v)
|
struct atom_value *v)
|
||||||
{
|
{
|
||||||
if (!strcmp(name, "objectname")) {
|
if (!strcmp(name, "objectname")) {
|
||||||
char *s = xmalloc(41);
|
v->s = xstrdup(sha1_to_hex(sha1));
|
||||||
strcpy(s, sha1_to_hex(sha1));
|
|
||||||
v->s = s;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!strcmp(name, "objectname:short")) {
|
if (!strcmp(name, "objectname:short")) {
|
||||||
|
@ -370,10 +368,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
|
||||||
if (!strcmp(name, "objecttype"))
|
if (!strcmp(name, "objecttype"))
|
||||||
v->s = typename(obj->type);
|
v->s = typename(obj->type);
|
||||||
else if (!strcmp(name, "objectsize")) {
|
else if (!strcmp(name, "objectsize")) {
|
||||||
char *s = xmalloc(40);
|
|
||||||
sprintf(s, "%lu", sz);
|
|
||||||
v->ul = sz;
|
v->ul = sz;
|
||||||
v->s = s;
|
v->s = xstrfmt("%lu", sz);
|
||||||
}
|
}
|
||||||
else if (deref)
|
else if (deref)
|
||||||
grab_objectname(name, obj->sha1, v);
|
grab_objectname(name, obj->sha1, v);
|
||||||
|
@ -397,11 +393,8 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
|
||||||
v->s = tag->tag;
|
v->s = tag->tag;
|
||||||
else if (!strcmp(name, "type") && tag->tagged)
|
else if (!strcmp(name, "type") && tag->tagged)
|
||||||
v->s = typename(tag->tagged->type);
|
v->s = typename(tag->tagged->type);
|
||||||
else if (!strcmp(name, "object") && tag->tagged) {
|
else if (!strcmp(name, "object") && tag->tagged)
|
||||||
char *s = xmalloc(41);
|
v->s = xstrdup(sha1_to_hex(tag->tagged->sha1));
|
||||||
strcpy(s, sha1_to_hex(tag->tagged->sha1));
|
|
||||||
v->s = s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,32 +412,22 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
|
||||||
if (deref)
|
if (deref)
|
||||||
name++;
|
name++;
|
||||||
if (!strcmp(name, "tree")) {
|
if (!strcmp(name, "tree")) {
|
||||||
char *s = xmalloc(41);
|
v->s = xstrdup(sha1_to_hex(commit->tree->object.sha1));
|
||||||
strcpy(s, sha1_to_hex(commit->tree->object.sha1));
|
|
||||||
v->s = s;
|
|
||||||
}
|
}
|
||||||
if (!strcmp(name, "numparent")) {
|
else if (!strcmp(name, "numparent")) {
|
||||||
char *s = xmalloc(40);
|
|
||||||
v->ul = commit_list_count(commit->parents);
|
v->ul = commit_list_count(commit->parents);
|
||||||
sprintf(s, "%lu", v->ul);
|
v->s = xstrfmt("%lu", v->ul);
|
||||||
v->s = s;
|
|
||||||
}
|
}
|
||||||
else if (!strcmp(name, "parent")) {
|
else if (!strcmp(name, "parent")) {
|
||||||
int num = commit_list_count(commit->parents);
|
|
||||||
int i;
|
|
||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
char *s = xmalloc(41 * num + 1);
|
struct strbuf s = STRBUF_INIT;
|
||||||
v->s = s;
|
for (parents = commit->parents; parents; parents = parents->next) {
|
||||||
for (i = 0, parents = commit->parents;
|
|
||||||
parents;
|
|
||||||
parents = parents->next, i = i + 41) {
|
|
||||||
struct commit *parent = parents->item;
|
struct commit *parent = parents->item;
|
||||||
strcpy(s+i, sha1_to_hex(parent->object.sha1));
|
if (parents != commit->parents)
|
||||||
if (parents->next)
|
strbuf_addch(&s, ' ');
|
||||||
s[i+40] = ' ';
|
strbuf_addstr(&s, sha1_to_hex(parent->object.sha1));
|
||||||
}
|
}
|
||||||
if (!i)
|
v->s = strbuf_detach(&s, NULL);
|
||||||
*s = '\0';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -934,7 +917,6 @@ static void populate_value(struct ref_array_item *ref)
|
||||||
else if (!strcmp(formatp, "track") &&
|
else if (!strcmp(formatp, "track") &&
|
||||||
(starts_with(name, "upstream") ||
|
(starts_with(name, "upstream") ||
|
||||||
starts_with(name, "push"))) {
|
starts_with(name, "push"))) {
|
||||||
char buf[40];
|
|
||||||
|
|
||||||
if (stat_tracking_info(branch, &num_ours,
|
if (stat_tracking_info(branch, &num_ours,
|
||||||
&num_theirs, NULL))
|
&num_theirs, NULL))
|
||||||
|
@ -942,17 +924,13 @@ static void populate_value(struct ref_array_item *ref)
|
||||||
|
|
||||||
if (!num_ours && !num_theirs)
|
if (!num_ours && !num_theirs)
|
||||||
v->s = "";
|
v->s = "";
|
||||||
else if (!num_ours) {
|
else if (!num_ours)
|
||||||
sprintf(buf, "[behind %d]", num_theirs);
|
v->s = xstrfmt("[behind %d]", num_theirs);
|
||||||
v->s = xstrdup(buf);
|
else if (!num_theirs)
|
||||||
} else if (!num_theirs) {
|
v->s = xstrfmt("[ahead %d]", num_ours);
|
||||||
sprintf(buf, "[ahead %d]", num_ours);
|
else
|
||||||
v->s = xstrdup(buf);
|
v->s = xstrfmt("[ahead %d, behind %d]",
|
||||||
} else {
|
|
||||||
sprintf(buf, "[ahead %d, behind %d]",
|
|
||||||
num_ours, num_theirs);
|
num_ours, num_theirs);
|
||||||
v->s = xstrdup(buf);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
} else if (!strcmp(formatp, "trackshort") &&
|
} else if (!strcmp(formatp, "trackshort") &&
|
||||||
(starts_with(name, "upstream") ||
|
(starts_with(name, "upstream") ||
|
||||||
|
@ -979,12 +957,8 @@ static void populate_value(struct ref_array_item *ref)
|
||||||
|
|
||||||
if (!deref)
|
if (!deref)
|
||||||
v->s = refname;
|
v->s = refname;
|
||||||
else {
|
else
|
||||||
int len = strlen(refname);
|
v->s = xstrfmt("%s^{}", refname);
|
||||||
char *s = xmalloc(len + 4);
|
|
||||||
sprintf(s, "%s^{}", refname);
|
|
||||||
v->s = s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < used_atom_cnt; i++) {
|
for (i = 0; i < used_atom_cnt; i++) {
|
||||||
|
|
|
@ -56,12 +56,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reflogs->nr == 0) {
|
if (reflogs->nr == 0) {
|
||||||
int len = strlen(ref);
|
char *refname = xstrfmt("refs/%s", ref);
|
||||||
char *refname = xmalloc(len + 12);
|
|
||||||
sprintf(refname, "refs/%s", ref);
|
|
||||||
for_each_reflog_ent(refname, read_one_reflog, reflogs);
|
for_each_reflog_ent(refname, read_one_reflog, reflogs);
|
||||||
if (reflogs->nr == 0) {
|
if (reflogs->nr == 0) {
|
||||||
sprintf(refname, "refs/heads/%s", ref);
|
free(refname);
|
||||||
|
refname = xstrfmt("refs/heads/%s", ref);
|
||||||
for_each_reflog_ent(refname, read_one_reflog, reflogs);
|
for_each_reflog_ent(refname, read_one_reflog, reflogs);
|
||||||
}
|
}
|
||||||
free(refname);
|
free(refname);
|
||||||
|
|
64
refs.c
64
refs.c
|
@ -1602,16 +1602,15 @@ static int resolve_missing_loose_ref(const char *refname,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function needs to return a meaningful errno on failure */
|
/* This function needs to return a meaningful errno on failure */
|
||||||
static const char *resolve_ref_unsafe_1(const char *refname,
|
static const char *resolve_ref_1(const char *refname,
|
||||||
int resolve_flags,
|
int resolve_flags,
|
||||||
unsigned char *sha1,
|
unsigned char *sha1,
|
||||||
int *flags,
|
int *flags,
|
||||||
struct strbuf *sb_path)
|
struct strbuf *sb_refname,
|
||||||
|
struct strbuf *sb_path,
|
||||||
|
struct strbuf *sb_contents)
|
||||||
{
|
{
|
||||||
int depth = MAXDEPTH;
|
int depth = MAXDEPTH;
|
||||||
ssize_t len;
|
|
||||||
char buffer[256];
|
|
||||||
static char refname_buffer[256];
|
|
||||||
int bad_name = 0;
|
int bad_name = 0;
|
||||||
|
|
||||||
if (flags)
|
if (flags)
|
||||||
|
@ -1677,19 +1676,18 @@ static const char *resolve_ref_unsafe_1(const char *refname,
|
||||||
|
|
||||||
/* Follow "normalized" - ie "refs/.." symlinks by hand */
|
/* Follow "normalized" - ie "refs/.." symlinks by hand */
|
||||||
if (S_ISLNK(st.st_mode)) {
|
if (S_ISLNK(st.st_mode)) {
|
||||||
len = readlink(path, buffer, sizeof(buffer)-1);
|
strbuf_reset(sb_contents);
|
||||||
if (len < 0) {
|
if (strbuf_readlink(sb_contents, path, 0) < 0) {
|
||||||
if (errno == ENOENT || errno == EINVAL)
|
if (errno == ENOENT || errno == EINVAL)
|
||||||
/* inconsistent with lstat; retry */
|
/* inconsistent with lstat; retry */
|
||||||
goto stat_ref;
|
goto stat_ref;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
buffer[len] = 0;
|
if (starts_with(sb_contents->buf, "refs/") &&
|
||||||
if (starts_with(buffer, "refs/") &&
|
!check_refname_format(sb_contents->buf, 0)) {
|
||||||
!check_refname_format(buffer, 0)) {
|
strbuf_swap(sb_refname, sb_contents);
|
||||||
strcpy(refname_buffer, buffer);
|
refname = sb_refname->buf;
|
||||||
refname = refname_buffer;
|
|
||||||
if (flags)
|
if (flags)
|
||||||
*flags |= REF_ISSYMREF;
|
*flags |= REF_ISSYMREF;
|
||||||
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
||||||
|
@ -1718,28 +1716,26 @@ static const char *resolve_ref_unsafe_1(const char *refname,
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
len = read_in_full(fd, buffer, sizeof(buffer)-1);
|
strbuf_reset(sb_contents);
|
||||||
if (len < 0) {
|
if (strbuf_read(sb_contents, fd, 256) < 0) {
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
while (len && isspace(buffer[len-1]))
|
strbuf_rtrim(sb_contents);
|
||||||
len--;
|
|
||||||
buffer[len] = '\0';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is it a symbolic ref?
|
* Is it a symbolic ref?
|
||||||
*/
|
*/
|
||||||
if (!starts_with(buffer, "ref:")) {
|
if (!starts_with(sb_contents->buf, "ref:")) {
|
||||||
/*
|
/*
|
||||||
* Please note that FETCH_HEAD has a second
|
* Please note that FETCH_HEAD has a second
|
||||||
* line containing other data.
|
* line containing other data.
|
||||||
*/
|
*/
|
||||||
if (get_sha1_hex(buffer, sha1) ||
|
if (get_sha1_hex(sb_contents->buf, sha1) ||
|
||||||
(buffer[40] != '\0' && !isspace(buffer[40]))) {
|
(sb_contents->buf[40] != '\0' && !isspace(sb_contents->buf[40]))) {
|
||||||
if (flags)
|
if (flags)
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
@ -1754,10 +1750,12 @@ static const char *resolve_ref_unsafe_1(const char *refname,
|
||||||
}
|
}
|
||||||
if (flags)
|
if (flags)
|
||||||
*flags |= REF_ISSYMREF;
|
*flags |= REF_ISSYMREF;
|
||||||
buf = buffer + 4;
|
buf = sb_contents->buf + 4;
|
||||||
while (isspace(*buf))
|
while (isspace(*buf))
|
||||||
buf++;
|
buf++;
|
||||||
refname = strcpy(refname_buffer, buf);
|
strbuf_reset(sb_refname);
|
||||||
|
strbuf_addstr(sb_refname, buf);
|
||||||
|
refname = sb_refname->buf;
|
||||||
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
return refname;
|
return refname;
|
||||||
|
@ -1779,10 +1777,15 @@ static const char *resolve_ref_unsafe_1(const char *refname,
|
||||||
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
||||||
unsigned char *sha1, int *flags)
|
unsigned char *sha1, int *flags)
|
||||||
{
|
{
|
||||||
|
static struct strbuf sb_refname = STRBUF_INIT;
|
||||||
|
struct strbuf sb_contents = STRBUF_INIT;
|
||||||
struct strbuf sb_path = STRBUF_INIT;
|
struct strbuf sb_path = STRBUF_INIT;
|
||||||
const char *ret = resolve_ref_unsafe_1(refname, resolve_flags,
|
const char *ret;
|
||||||
sha1, flags, &sb_path);
|
|
||||||
|
ret = resolve_ref_1(refname, resolve_flags, sha1, flags,
|
||||||
|
&sb_refname, &sb_path, &sb_contents);
|
||||||
strbuf_release(&sb_path);
|
strbuf_release(&sb_path);
|
||||||
|
strbuf_release(&sb_contents);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2222,8 +2225,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
|
||||||
|
|
||||||
if (!has_glob_specials(pattern)) {
|
if (!has_glob_specials(pattern)) {
|
||||||
/* Append implied '/' '*' if not present. */
|
/* Append implied '/' '*' if not present. */
|
||||||
if (real_pattern.buf[real_pattern.len - 1] != '/')
|
strbuf_complete(&real_pattern, '/');
|
||||||
strbuf_addch(&real_pattern, '/');
|
|
||||||
/* No need to check for '*', there is none. */
|
/* No need to check for '*', there is none. */
|
||||||
strbuf_addch(&real_pattern, '*');
|
strbuf_addch(&real_pattern, '*');
|
||||||
}
|
}
|
||||||
|
@ -2730,7 +2732,7 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)
|
||||||
int namelen = strlen(entry->name) + 1;
|
int namelen = strlen(entry->name) + 1;
|
||||||
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
|
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
|
||||||
hashcpy(n->sha1, entry->u.value.oid.hash);
|
hashcpy(n->sha1, entry->u.value.oid.hash);
|
||||||
strcpy(n->name, entry->name);
|
memcpy(n->name, entry->name, namelen); /* includes NUL */
|
||||||
n->next = cb->ref_to_prune;
|
n->next = cb->ref_to_prune;
|
||||||
cb->ref_to_prune = n;
|
cb->ref_to_prune = n;
|
||||||
}
|
}
|
||||||
|
@ -3365,7 +3367,7 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
|
||||||
msglen = msg ? strlen(msg) : 0;
|
msglen = msg ? strlen(msg) : 0;
|
||||||
maxlen = strlen(committer) + msglen + 100;
|
maxlen = strlen(committer) + msglen + 100;
|
||||||
logrec = xmalloc(maxlen);
|
logrec = xmalloc(maxlen);
|
||||||
len = sprintf(logrec, "%s %s %s\n",
|
len = xsnprintf(logrec, maxlen, "%s %s %s\n",
|
||||||
sha1_to_hex(old_sha1),
|
sha1_to_hex(old_sha1),
|
||||||
sha1_to_hex(new_sha1),
|
sha1_to_hex(new_sha1),
|
||||||
committer);
|
committer);
|
||||||
|
@ -4020,10 +4022,10 @@ void ref_transaction_free(struct ref_transaction *transaction)
|
||||||
static struct ref_update *add_update(struct ref_transaction *transaction,
|
static struct ref_update *add_update(struct ref_transaction *transaction,
|
||||||
const char *refname)
|
const char *refname)
|
||||||
{
|
{
|
||||||
size_t len = strlen(refname);
|
size_t len = strlen(refname) + 1;
|
||||||
struct ref_update *update = xcalloc(1, sizeof(*update) + len + 1);
|
struct ref_update *update = xcalloc(1, sizeof(*update) + len);
|
||||||
|
|
||||||
strcpy((char *)update->refname, refname);
|
memcpy((char *)update->refname, refname, len); /* includes NUL */
|
||||||
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
|
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
|
||||||
transaction->updates[transaction->nr++] = update;
|
transaction->updates[transaction->nr++] = update;
|
||||||
return update;
|
return update;
|
||||||
|
|
|
@ -168,10 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
|
||||||
url.buf);
|
url.buf);
|
||||||
data[i] = 0;
|
data[i] = 0;
|
||||||
ref_name = mid + 1;
|
ref_name = mid + 1;
|
||||||
ref = xmalloc(sizeof(struct ref) +
|
ref = alloc_ref(ref_name);
|
||||||
strlen(ref_name) + 1);
|
|
||||||
memset(ref, 0, sizeof(struct ref));
|
|
||||||
strcpy(ref->name, ref_name);
|
|
||||||
get_sha1_hex(start, ref->old_sha1);
|
get_sha1_hex(start, ref->old_sha1);
|
||||||
if (!refs)
|
if (!refs)
|
||||||
refs = ref;
|
refs = ref;
|
||||||
|
|
142
remote.c
142
remote.c
|
@ -8,6 +8,7 @@
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "mergesort.h"
|
#include "mergesort.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
enum map_direction { FROM_SRC, FROM_DST };
|
enum map_direction { FROM_SRC, FROM_DST };
|
||||||
|
|
||||||
|
@ -54,9 +55,6 @@ static const char *pushremote_name;
|
||||||
static struct rewrites rewrites;
|
static struct rewrites rewrites;
|
||||||
static struct rewrites rewrites_push;
|
static struct rewrites rewrites_push;
|
||||||
|
|
||||||
#define BUF_SIZE (2048)
|
|
||||||
static char buffer[BUF_SIZE];
|
|
||||||
|
|
||||||
static int valid_remote(const struct remote *remote)
|
static int valid_remote(const struct remote *remote)
|
||||||
{
|
{
|
||||||
return (!!remote->url) || (!!remote->foreign_vcs);
|
return (!!remote->url) || (!!remote->foreign_vcs);
|
||||||
|
@ -65,7 +63,6 @@ static int valid_remote(const struct remote *remote)
|
||||||
static const char *alias_url(const char *url, struct rewrites *r)
|
static const char *alias_url(const char *url, struct rewrites *r)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
char *ret;
|
|
||||||
struct counted_string *longest;
|
struct counted_string *longest;
|
||||||
int longest_i;
|
int longest_i;
|
||||||
|
|
||||||
|
@ -86,11 +83,7 @@ static const char *alias_url(const char *url, struct rewrites *r)
|
||||||
if (!longest)
|
if (!longest)
|
||||||
return url;
|
return url;
|
||||||
|
|
||||||
ret = xmalloc(r->rewrite[longest_i]->baselen +
|
return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
|
||||||
(strlen(url) - longest->len) + 1);
|
|
||||||
strcpy(ret, r->rewrite[longest_i]->base);
|
|
||||||
strcpy(ret + r->rewrite[longest_i]->baselen, url + longest->len);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_push_refspec(struct remote *remote, const char *ref)
|
static void add_push_refspec(struct remote *remote, const char *ref)
|
||||||
|
@ -248,106 +241,76 @@ static void add_instead_of(struct rewrite *rewrite, const char *instead_of)
|
||||||
rewrite->instead_of_nr++;
|
rewrite->instead_of_nr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *skip_spaces(const char *s)
|
||||||
|
{
|
||||||
|
while (isspace(*s))
|
||||||
|
s++;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
static void read_remotes_file(struct remote *remote)
|
static void read_remotes_file(struct remote *remote)
|
||||||
{
|
{
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
FILE *f = fopen(git_path("remotes/%s", remote->name), "r");
|
FILE *f = fopen(git_path("remotes/%s", remote->name), "r");
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
remote->origin = REMOTE_REMOTES;
|
remote->origin = REMOTE_REMOTES;
|
||||||
while (fgets(buffer, BUF_SIZE, f)) {
|
while (strbuf_getline(&buf, f, '\n') != EOF) {
|
||||||
int value_list;
|
const char *v;
|
||||||
char *s, *p;
|
|
||||||
|
|
||||||
if (starts_with(buffer, "URL:")) {
|
strbuf_rtrim(&buf);
|
||||||
value_list = 0;
|
|
||||||
s = buffer + 4;
|
|
||||||
} else if (starts_with(buffer, "Push:")) {
|
|
||||||
value_list = 1;
|
|
||||||
s = buffer + 5;
|
|
||||||
} else if (starts_with(buffer, "Pull:")) {
|
|
||||||
value_list = 2;
|
|
||||||
s = buffer + 5;
|
|
||||||
} else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (isspace(*s))
|
if (skip_prefix(buf.buf, "URL:", &v))
|
||||||
s++;
|
add_url_alias(remote, xstrdup(skip_spaces(v)));
|
||||||
if (!*s)
|
else if (skip_prefix(buf.buf, "Push:", &v))
|
||||||
continue;
|
add_push_refspec(remote, xstrdup(skip_spaces(v)));
|
||||||
|
else if (skip_prefix(buf.buf, "Pull:", &v))
|
||||||
p = s + strlen(s);
|
add_fetch_refspec(remote, xstrdup(skip_spaces(v)));
|
||||||
while (isspace(p[-1]))
|
|
||||||
*--p = 0;
|
|
||||||
|
|
||||||
switch (value_list) {
|
|
||||||
case 0:
|
|
||||||
add_url_alias(remote, xstrdup(s));
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
add_push_refspec(remote, xstrdup(s));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
add_fetch_refspec(remote, xstrdup(s));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
strbuf_release(&buf);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_branches_file(struct remote *remote)
|
static void read_branches_file(struct remote *remote)
|
||||||
{
|
{
|
||||||
char *frag;
|
char *frag;
|
||||||
struct strbuf branch = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int n = 1000;
|
FILE *f = fopen(git_path("branches/%s", remote->name), "r");
|
||||||
FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
|
|
||||||
char *s, *p;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
s = fgets(buffer, BUF_SIZE, f);
|
|
||||||
fclose(f);
|
strbuf_getline(&buf, f, '\n');
|
||||||
if (!s)
|
strbuf_trim(&buf);
|
||||||
return;
|
if (!buf.len) {
|
||||||
while (isspace(*s))
|
strbuf_release(&buf);
|
||||||
s++;
|
|
||||||
if (!*s)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
remote->origin = REMOTE_BRANCHES;
|
remote->origin = REMOTE_BRANCHES;
|
||||||
p = s + strlen(s);
|
|
||||||
while (isspace(p[-1]))
|
|
||||||
*--p = 0;
|
|
||||||
len = p - s;
|
|
||||||
p = xmalloc(len + 1);
|
|
||||||
strcpy(p, s);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The branches file would have URL and optionally
|
* The branches file would have URL and optionally
|
||||||
* #branch specified. The "master" (or specified) branch is
|
* #branch specified. The "master" (or specified) branch is
|
||||||
* fetched and stored in the local branch of the same name.
|
* fetched and stored in the local branch matching the
|
||||||
|
* remote name.
|
||||||
*/
|
*/
|
||||||
frag = strchr(p, '#');
|
frag = strchr(buf.buf, '#');
|
||||||
if (frag) {
|
if (frag)
|
||||||
*(frag++) = '\0';
|
*(frag++) = '\0';
|
||||||
strbuf_addf(&branch, "refs/heads/%s", frag);
|
else
|
||||||
} else
|
frag = "master";
|
||||||
strbuf_addstr(&branch, "refs/heads/master");
|
|
||||||
|
add_url_alias(remote, strbuf_detach(&buf, NULL));
|
||||||
|
add_fetch_refspec(remote, xstrfmt("refs/heads/%s:refs/heads/%s",
|
||||||
|
frag, remote->name));
|
||||||
|
|
||||||
strbuf_addf(&branch, ":refs/heads/%s", remote->name);
|
|
||||||
add_url_alias(remote, p);
|
|
||||||
add_fetch_refspec(remote, strbuf_detach(&branch, NULL));
|
|
||||||
/*
|
/*
|
||||||
* Cogito compatible push: push current HEAD to remote #branch
|
* Cogito compatible push: push current HEAD to remote #branch
|
||||||
* (master if missing)
|
* (master if missing)
|
||||||
*/
|
*/
|
||||||
strbuf_init(&branch, 0);
|
add_push_refspec(remote, xstrfmt("HEAD:refs/heads/%s", frag));
|
||||||
strbuf_addstr(&branch, "HEAD");
|
|
||||||
if (frag)
|
|
||||||
strbuf_addf(&branch, ":refs/heads/%s", frag);
|
|
||||||
else
|
|
||||||
strbuf_addstr(&branch, ":refs/heads/master");
|
|
||||||
add_push_refspec(remote, strbuf_detach(&branch, NULL));
|
|
||||||
remote->fetch_tags = 1; /* always auto-follow */
|
remote->fetch_tags = 1; /* always auto-follow */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2035,10 +1998,9 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
struct commit *ours, *theirs;
|
struct commit *ours, *theirs;
|
||||||
char symmetric[84];
|
|
||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
const char *rev_argv[10], *base;
|
const char *base;
|
||||||
int rev_argc;
|
struct argv_array argv = ARGV_ARRAY_INIT;
|
||||||
|
|
||||||
/* Cannot stat unless we are marked to build on top of somebody else. */
|
/* Cannot stat unless we are marked to build on top of somebody else. */
|
||||||
base = branch_get_upstream(branch, NULL);
|
base = branch_get_upstream(branch, NULL);
|
||||||
|
@ -2067,19 +2029,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run "rev-list --left-right ours...theirs" internally... */
|
/* Run "rev-list --left-right ours...theirs" internally... */
|
||||||
rev_argc = 0;
|
argv_array_push(&argv, ""); /* ignored */
|
||||||
rev_argv[rev_argc++] = NULL;
|
argv_array_push(&argv, "--left-right");
|
||||||
rev_argv[rev_argc++] = "--left-right";
|
argv_array_pushf(&argv, "%s...%s",
|
||||||
rev_argv[rev_argc++] = symmetric;
|
sha1_to_hex(ours->object.sha1),
|
||||||
rev_argv[rev_argc++] = "--";
|
sha1_to_hex(theirs->object.sha1));
|
||||||
rev_argv[rev_argc] = NULL;
|
argv_array_push(&argv, "--");
|
||||||
|
|
||||||
strcpy(symmetric, sha1_to_hex(ours->object.sha1));
|
|
||||||
strcpy(symmetric + 40, "...");
|
|
||||||
strcpy(symmetric + 43, sha1_to_hex(theirs->object.sha1));
|
|
||||||
|
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
setup_revisions(rev_argc, rev_argv, &revs, NULL);
|
setup_revisions(argv.argc, argv.argv, &revs, NULL);
|
||||||
if (prepare_revision_walk(&revs))
|
if (prepare_revision_walk(&revs))
|
||||||
die("revision walk setup failed");
|
die("revision walk setup failed");
|
||||||
|
|
||||||
|
@ -2099,6 +2057,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
/* clear object flags smudged by the above traversal */
|
/* clear object flags smudged by the above traversal */
|
||||||
clear_commit_marks(ours, ALL_REV_FLAGS);
|
clear_commit_marks(ours, ALL_REV_FLAGS);
|
||||||
clear_commit_marks(theirs, ALL_REV_FLAGS);
|
clear_commit_marks(theirs, ALL_REV_FLAGS);
|
||||||
|
|
||||||
|
argv_array_clear(&argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ char *path_name(const struct name_path *path, const char *name)
|
||||||
}
|
}
|
||||||
n = xmalloc(len);
|
n = xmalloc(len);
|
||||||
m = n + len - (nlen + 1);
|
m = n + len - (nlen + 1);
|
||||||
strcpy(m, name);
|
memcpy(m, name, nlen + 1);
|
||||||
for (p = path; p; p = p->up) {
|
for (p = path; p; p = p->up) {
|
||||||
if (p->elem_len) {
|
if (p->elem_len) {
|
||||||
m -= p->elem_len + 1;
|
m -= p->elem_len + 1;
|
||||||
|
|
12
setup.c
12
setup.c
|
@ -99,10 +99,7 @@ char *prefix_path_gently(const char *prefix, int len,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sanitized = xmalloc(len + strlen(path) + 1);
|
sanitized = xstrfmt("%.*s%s", len, prefix, path);
|
||||||
if (len)
|
|
||||||
memcpy(sanitized, prefix, len);
|
|
||||||
strcpy(sanitized + len, path);
|
|
||||||
if (remaining_prefix)
|
if (remaining_prefix)
|
||||||
*remaining_prefix = len;
|
*remaining_prefix = len;
|
||||||
if (normalize_path_copy_len(sanitized, sanitized, remaining_prefix)) {
|
if (normalize_path_copy_len(sanitized, sanitized, remaining_prefix)) {
|
||||||
|
@ -475,11 +472,8 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
|
||||||
|
|
||||||
if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) {
|
if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) {
|
||||||
size_t pathlen = slash+1 - path;
|
size_t pathlen = slash+1 - path;
|
||||||
size_t dirlen = pathlen + len - 8;
|
dir = xstrfmt("%.*s%.*s", (int)pathlen, path,
|
||||||
dir = xmalloc(dirlen + 1);
|
(int)(len - 8), buf + 8);
|
||||||
strncpy(dir, path, pathlen);
|
|
||||||
strncpy(dir + pathlen, buf + 8, len - 8);
|
|
||||||
dir[dirlen] = '\0';
|
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = dir;
|
buf = dir;
|
||||||
}
|
}
|
||||||
|
|
126
sha1_file.c
126
sha1_file.c
|
@ -208,44 +208,25 @@ const char *sha1_file_name(const unsigned char *sha1)
|
||||||
* provided by the caller. which should be "pack" or "idx".
|
* provided by the caller. which should be "pack" or "idx".
|
||||||
*/
|
*/
|
||||||
static char *sha1_get_pack_name(const unsigned char *sha1,
|
static char *sha1_get_pack_name(const unsigned char *sha1,
|
||||||
char **name, char **base, const char *which)
|
struct strbuf *buf,
|
||||||
|
const char *which)
|
||||||
{
|
{
|
||||||
static const char hex[] = "0123456789abcdef";
|
strbuf_reset(buf);
|
||||||
char *buf;
|
strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
|
||||||
int i;
|
sha1_to_hex(sha1), which);
|
||||||
|
return buf->buf;
|
||||||
if (!*base) {
|
|
||||||
const char *sha1_file_directory = get_object_directory();
|
|
||||||
int len = strlen(sha1_file_directory);
|
|
||||||
*base = xmalloc(len + 60);
|
|
||||||
sprintf(*base, "%s/pack/pack-1234567890123456789012345678901234567890.%s",
|
|
||||||
sha1_file_directory, which);
|
|
||||||
*name = *base + len + 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = *name;
|
|
||||||
|
|
||||||
for (i = 0; i < 20; i++) {
|
|
||||||
unsigned int val = *sha1++;
|
|
||||||
*buf++ = hex[val >> 4];
|
|
||||||
*buf++ = hex[val & 0xf];
|
|
||||||
}
|
|
||||||
|
|
||||||
return *base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *sha1_pack_name(const unsigned char *sha1)
|
char *sha1_pack_name(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
static char *name, *base;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
return sha1_get_pack_name(sha1, &buf, "pack");
|
||||||
return sha1_get_pack_name(sha1, &name, &base, "pack");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *sha1_pack_index_name(const unsigned char *sha1)
|
char *sha1_pack_index_name(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
static char *name, *base;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
return sha1_get_pack_name(sha1, &buf, "idx");
|
||||||
return sha1_get_pack_name(sha1, &name, &base, "idx");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct alternate_object_database *alt_odb_list;
|
struct alternate_object_database *alt_odb_list;
|
||||||
|
@ -671,13 +652,15 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)
|
||||||
int open_pack_index(struct packed_git *p)
|
int open_pack_index(struct packed_git *p)
|
||||||
{
|
{
|
||||||
char *idx_name;
|
char *idx_name;
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (p->index_data)
|
if (p->index_data)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
idx_name = xstrdup(p->pack_name);
|
if (!strip_suffix(p->pack_name, ".pack", &len))
|
||||||
strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
|
die("BUG: pack_name does not end in .pack");
|
||||||
|
idx_name = xstrfmt("%.*s.idx", (int)len, p->pack_name);
|
||||||
ret = check_packed_git_idx(idx_name, p);
|
ret = check_packed_git_idx(idx_name, p);
|
||||||
free(idx_name);
|
free(idx_name);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1161,11 +1144,12 @@ static void try_to_free_pack_memory(size_t size)
|
||||||
release_pack_memory(size);
|
release_pack_memory(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct packed_git *add_packed_git(const char *path, int path_len, int local)
|
struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
|
||||||
{
|
{
|
||||||
static int have_set_try_to_free_routine;
|
static int have_set_try_to_free_routine;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct packed_git *p = alloc_packed_git(path_len + 2);
|
size_t alloc;
|
||||||
|
struct packed_git *p;
|
||||||
|
|
||||||
if (!have_set_try_to_free_routine) {
|
if (!have_set_try_to_free_routine) {
|
||||||
have_set_try_to_free_routine = 1;
|
have_set_try_to_free_routine = 1;
|
||||||
|
@ -1176,18 +1160,22 @@ struct packed_git *add_packed_git(const char *path, int path_len, int local)
|
||||||
* Make sure a corresponding .pack file exists and that
|
* Make sure a corresponding .pack file exists and that
|
||||||
* the index looks sane.
|
* the index looks sane.
|
||||||
*/
|
*/
|
||||||
path_len -= strlen(".idx");
|
if (!strip_suffix_mem(path, &path_len, ".idx"))
|
||||||
if (path_len < 1) {
|
|
||||||
free(p);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
/*
|
||||||
|
* ".pack" is long enough to hold any suffix we're adding (and
|
||||||
|
* the use xsnprintf double-checks that)
|
||||||
|
*/
|
||||||
|
alloc = path_len + strlen(".pack") + 1;
|
||||||
|
p = alloc_packed_git(alloc);
|
||||||
memcpy(p->pack_name, path, path_len);
|
memcpy(p->pack_name, path, path_len);
|
||||||
|
|
||||||
strcpy(p->pack_name + path_len, ".keep");
|
xsnprintf(p->pack_name + path_len, alloc - path_len, ".keep");
|
||||||
if (!access(p->pack_name, F_OK))
|
if (!access(p->pack_name, F_OK))
|
||||||
p->pack_keep = 1;
|
p->pack_keep = 1;
|
||||||
|
|
||||||
strcpy(p->pack_name + path_len, ".pack");
|
xsnprintf(p->pack_name + path_len, alloc - path_len, ".pack");
|
||||||
if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
|
if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
|
||||||
free(p);
|
free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1207,9 +1195,10 @@ struct packed_git *add_packed_git(const char *path, int path_len, int local)
|
||||||
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
|
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
|
||||||
{
|
{
|
||||||
const char *path = sha1_pack_name(sha1);
|
const char *path = sha1_pack_name(sha1);
|
||||||
struct packed_git *p = alloc_packed_git(strlen(path) + 1);
|
int alloc = strlen(path) + 1;
|
||||||
|
struct packed_git *p = alloc_packed_git(alloc);
|
||||||
|
|
||||||
strcpy(p->pack_name, path);
|
memcpy(p->pack_name, path, alloc); /* includes NUL */
|
||||||
hashcpy(p->sha1, sha1);
|
hashcpy(p->sha1, sha1);
|
||||||
if (check_packed_git_idx(idx_path, p)) {
|
if (check_packed_git_idx(idx_path, p)) {
|
||||||
free(p);
|
free(p);
|
||||||
|
@ -1479,7 +1468,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Generate the header */
|
/* Generate the header */
|
||||||
hdrlen = sprintf(hdr, "%s %lu", typename(obj_type), size) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(obj_type), size) + 1;
|
||||||
|
|
||||||
/* Sha1.. */
|
/* Sha1.. */
|
||||||
git_SHA1_Init(&c);
|
git_SHA1_Init(&c);
|
||||||
|
@ -2945,7 +2934,7 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
|
||||||
git_SHA_CTX c;
|
git_SHA_CTX c;
|
||||||
|
|
||||||
/* Generate the header */
|
/* Generate the header */
|
||||||
*hdrlen = sprintf(hdr, "%s %lu", type, len)+1;
|
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %lu", type, len)+1;
|
||||||
|
|
||||||
/* Sha1.. */
|
/* Sha1.. */
|
||||||
git_SHA1_Init(&c);
|
git_SHA1_Init(&c);
|
||||||
|
@ -3008,7 +2997,7 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type,
|
||||||
unsigned char *sha1)
|
unsigned char *sha1)
|
||||||
{
|
{
|
||||||
char hdr[32];
|
char hdr[32];
|
||||||
int hdrlen;
|
int hdrlen = sizeof(hdr);
|
||||||
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
|
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3038,29 +3027,31 @@ static inline int directory_size(const char *filename)
|
||||||
* We want to avoid cross-directory filename renames, because those
|
* We want to avoid cross-directory filename renames, because those
|
||||||
* can have problems on various filesystems (FAT, NFS, Coda).
|
* can have problems on various filesystems (FAT, NFS, Coda).
|
||||||
*/
|
*/
|
||||||
static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
|
static int create_tmpfile(struct strbuf *tmp, const char *filename)
|
||||||
{
|
{
|
||||||
int fd, dirlen = directory_size(filename);
|
int fd, dirlen = directory_size(filename);
|
||||||
|
|
||||||
if (dirlen + 20 > bufsiz) {
|
strbuf_reset(tmp);
|
||||||
errno = ENAMETOOLONG;
|
strbuf_add(tmp, filename, dirlen);
|
||||||
return -1;
|
strbuf_addstr(tmp, "tmp_obj_XXXXXX");
|
||||||
}
|
fd = git_mkstemp_mode(tmp->buf, 0444);
|
||||||
memcpy(buffer, filename, dirlen);
|
|
||||||
strcpy(buffer + dirlen, "tmp_obj_XXXXXX");
|
|
||||||
fd = git_mkstemp_mode(buffer, 0444);
|
|
||||||
if (fd < 0 && dirlen && errno == ENOENT) {
|
if (fd < 0 && dirlen && errno == ENOENT) {
|
||||||
/* Make sure the directory exists */
|
/*
|
||||||
memcpy(buffer, filename, dirlen);
|
* Make sure the directory exists; note that the contents
|
||||||
buffer[dirlen-1] = 0;
|
* of the buffer are undefined after mkstemp returns an
|
||||||
if (mkdir(buffer, 0777) && errno != EEXIST)
|
* error, so we have to rewrite the whole buffer from
|
||||||
|
* scratch.
|
||||||
|
*/
|
||||||
|
strbuf_reset(tmp);
|
||||||
|
strbuf_add(tmp, filename, dirlen - 1);
|
||||||
|
if (mkdir(tmp->buf, 0777) && errno != EEXIST)
|
||||||
return -1;
|
return -1;
|
||||||
if (adjust_shared_perm(buffer))
|
if (adjust_shared_perm(tmp->buf))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Try again */
|
/* Try again */
|
||||||
strcpy(buffer + dirlen - 1, "/tmp_obj_XXXXXX");
|
strbuf_addstr(tmp, "/tmp_obj_XXXXXX");
|
||||||
fd = git_mkstemp_mode(buffer, 0444);
|
fd = git_mkstemp_mode(tmp->buf, 0444);
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -3073,10 +3064,10 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
git_SHA_CTX c;
|
git_SHA_CTX c;
|
||||||
unsigned char parano_sha1[20];
|
unsigned char parano_sha1[20];
|
||||||
static char tmp_file[PATH_MAX];
|
static struct strbuf tmp_file = STRBUF_INIT;
|
||||||
const char *filename = sha1_file_name(sha1);
|
const char *filename = sha1_file_name(sha1);
|
||||||
|
|
||||||
fd = create_tmpfile(tmp_file, sizeof(tmp_file), filename);
|
fd = create_tmpfile(&tmp_file, filename);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EACCES)
|
if (errno == EACCES)
|
||||||
return error("insufficient permission for adding an object to repository database %s", get_object_directory());
|
return error("insufficient permission for adding an object to repository database %s", get_object_directory());
|
||||||
|
@ -3125,12 +3116,12 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
|
||||||
struct utimbuf utb;
|
struct utimbuf utb;
|
||||||
utb.actime = mtime;
|
utb.actime = mtime;
|
||||||
utb.modtime = mtime;
|
utb.modtime = mtime;
|
||||||
if (utime(tmp_file, &utb) < 0)
|
if (utime(tmp_file.buf, &utb) < 0)
|
||||||
warning("failed utime() on %s: %s",
|
warning("failed utime() on %s: %s",
|
||||||
tmp_file, strerror(errno));
|
tmp_file.buf, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalize_object_file(tmp_file, filename);
|
return finalize_object_file(tmp_file.buf, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int freshen_loose_object(const unsigned char *sha1)
|
static int freshen_loose_object(const unsigned char *sha1)
|
||||||
|
@ -3154,7 +3145,7 @@ static int freshen_packed_object(const unsigned char *sha1)
|
||||||
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
|
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
char hdr[32];
|
char hdr[32];
|
||||||
int hdrlen;
|
int hdrlen = sizeof(hdr);
|
||||||
|
|
||||||
/* Normally if we have it in the pack then we do not bother writing
|
/* Normally if we have it in the pack then we do not bother writing
|
||||||
* it out into .git/objects/??/?{38} file.
|
* it out into .git/objects/??/?{38} file.
|
||||||
|
@ -3172,7 +3163,8 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ
|
||||||
int hdrlen, status = 0;
|
int hdrlen, status = 0;
|
||||||
|
|
||||||
/* type string, SP, %lu of the length plus NUL must fit this */
|
/* type string, SP, %lu of the length plus NUL must fit this */
|
||||||
header = xmalloc(strlen(type) + 32);
|
hdrlen = strlen(type) + 32;
|
||||||
|
header = xmalloc(hdrlen);
|
||||||
write_sha1_file_prepare(buf, len, type, sha1, header, &hdrlen);
|
write_sha1_file_prepare(buf, len, type, sha1, header, &hdrlen);
|
||||||
|
|
||||||
if (!(flags & HASH_WRITE_OBJECT))
|
if (!(flags & HASH_WRITE_OBJECT))
|
||||||
|
@ -3200,7 +3192,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
|
||||||
buf = read_packed_sha1(sha1, &type, &len);
|
buf = read_packed_sha1(sha1, &type, &len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
||||||
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
||||||
ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
|
ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
|
45
sha1_name.c
45
sha1_name.c
|
@ -96,11 +96,15 @@ static void find_short_object_filename(int len, const char *hex_pfx, struct disa
|
||||||
}
|
}
|
||||||
fakeent->next = alt_odb_list;
|
fakeent->next = alt_odb_list;
|
||||||
|
|
||||||
sprintf(hex, "%.2s", hex_pfx);
|
xsnprintf(hex, sizeof(hex), "%.2s", hex_pfx);
|
||||||
for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
|
for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
sprintf(alt->name, "%.2s/", hex_pfx);
|
/*
|
||||||
|
* every alt_odb struct has 42 extra bytes after the base
|
||||||
|
* for exactly this purpose
|
||||||
|
*/
|
||||||
|
xsnprintf(alt->name, 42, "%.2s/", hex_pfx);
|
||||||
dir = opendir(alt->base);
|
dir = opendir(alt->base);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
continue;
|
continue;
|
||||||
|
@ -368,14 +372,13 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
|
||||||
return ds.ambiguous;
|
return ds.ambiguous;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *find_unique_abbrev(const unsigned char *sha1, int len)
|
int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
|
||||||
{
|
{
|
||||||
int status, exists;
|
int status, exists;
|
||||||
static char hex[41];
|
|
||||||
|
|
||||||
memcpy(hex, sha1_to_hex(sha1), 40);
|
sha1_to_hex_r(hex, sha1);
|
||||||
if (len == 40 || !len)
|
if (len == 40 || !len)
|
||||||
return hex;
|
return 40;
|
||||||
exists = has_sha1_file(sha1);
|
exists = has_sha1_file(sha1);
|
||||||
while (len < 40) {
|
while (len < 40) {
|
||||||
unsigned char sha1_ret[20];
|
unsigned char sha1_ret[20];
|
||||||
|
@ -384,10 +387,17 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
? !status
|
? !status
|
||||||
: status == SHORT_NAME_NOT_FOUND) {
|
: status == SHORT_NAME_NOT_FOUND) {
|
||||||
hex[len] = 0;
|
hex[len] = 0;
|
||||||
return hex;
|
return len;
|
||||||
}
|
}
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *find_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
|
{
|
||||||
|
static char hex[GIT_SHA1_HEXSZ + 1];
|
||||||
|
find_unique_abbrev_r(hex, sha1, len);
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1283,8 +1293,7 @@ static void diagnose_invalid_index_path(int stage,
|
||||||
const struct cache_entry *ce;
|
const struct cache_entry *ce;
|
||||||
int pos;
|
int pos;
|
||||||
unsigned namelen = strlen(filename);
|
unsigned namelen = strlen(filename);
|
||||||
unsigned fullnamelen;
|
struct strbuf fullname = STRBUF_INIT;
|
||||||
char *fullname;
|
|
||||||
|
|
||||||
if (!prefix)
|
if (!prefix)
|
||||||
prefix = "";
|
prefix = "";
|
||||||
|
@ -1304,21 +1313,19 @@ static void diagnose_invalid_index_path(int stage,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Confusion between relative and absolute filenames? */
|
/* Confusion between relative and absolute filenames? */
|
||||||
fullnamelen = namelen + strlen(prefix);
|
strbuf_addstr(&fullname, prefix);
|
||||||
fullname = xmalloc(fullnamelen + 1);
|
strbuf_addstr(&fullname, filename);
|
||||||
strcpy(fullname, prefix);
|
pos = cache_name_pos(fullname.buf, fullname.len);
|
||||||
strcat(fullname, filename);
|
|
||||||
pos = cache_name_pos(fullname, fullnamelen);
|
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = -pos - 1;
|
pos = -pos - 1;
|
||||||
if (pos < active_nr) {
|
if (pos < active_nr) {
|
||||||
ce = active_cache[pos];
|
ce = active_cache[pos];
|
||||||
if (ce_namelen(ce) == fullnamelen &&
|
if (ce_namelen(ce) == fullname.len &&
|
||||||
!memcmp(ce->name, fullname, fullnamelen))
|
!memcmp(ce->name, fullname.buf, fullname.len))
|
||||||
die("Path '%s' is in the index, but not '%s'.\n"
|
die("Path '%s' is in the index, but not '%s'.\n"
|
||||||
"Did you mean ':%d:%s' aka ':%d:./%s'?",
|
"Did you mean ':%d:%s' aka ':%d:./%s'?",
|
||||||
fullname, filename,
|
fullname.buf, filename,
|
||||||
ce_stage(ce), fullname,
|
ce_stage(ce), fullname.buf,
|
||||||
ce_stage(ce), filename);
|
ce_stage(ce), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1328,7 +1335,7 @@ static void diagnose_invalid_index_path(int stage,
|
||||||
die("Path '%s' does not exist (neither on disk nor in the index).",
|
die("Path '%s' does not exist (neither on disk nor in the index).",
|
||||||
filename);
|
filename);
|
||||||
|
|
||||||
free(fullname);
|
strbuf_release(&fullname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,11 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
|
||||||
if (packet_max - 5 < n)
|
if (packet_max - 5 < n)
|
||||||
n = packet_max - 5;
|
n = packet_max - 5;
|
||||||
if (0 <= band) {
|
if (0 <= band) {
|
||||||
sprintf(hdr, "%04x", n + 5);
|
xsnprintf(hdr, sizeof(hdr), "%04x", n + 5);
|
||||||
hdr[4] = band;
|
hdr[4] = band;
|
||||||
write_or_die(fd, hdr, 5);
|
write_or_die(fd, hdr, 5);
|
||||||
} else {
|
} else {
|
||||||
sprintf(hdr, "%04x", n + 4);
|
xsnprintf(hdr, sizeof(hdr), "%04x", n + 4);
|
||||||
write_or_die(fd, hdr, 4);
|
write_or_die(fd, hdr, 4);
|
||||||
}
|
}
|
||||||
write_or_die(fd, p, n);
|
write_or_die(fd, p, n);
|
||||||
|
|
13
strbuf.c
13
strbuf.c
|
@ -245,8 +245,8 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size
|
||||||
static char prefix2[2];
|
static char prefix2[2];
|
||||||
|
|
||||||
if (prefix1[0] != comment_line_char) {
|
if (prefix1[0] != comment_line_char) {
|
||||||
sprintf(prefix1, "%c ", comment_line_char);
|
xsnprintf(prefix1, sizeof(prefix1), "%c ", comment_line_char);
|
||||||
sprintf(prefix2, "%c", comment_line_char);
|
xsnprintf(prefix2, sizeof(prefix2), "%c", comment_line_char);
|
||||||
}
|
}
|
||||||
add_lines(out, prefix1, prefix2, buf, size);
|
add_lines(out, prefix1, prefix2, buf, size);
|
||||||
}
|
}
|
||||||
|
@ -743,3 +743,12 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm)
|
||||||
}
|
}
|
||||||
strbuf_setlen(sb, sb->len + len);
|
strbuf_setlen(sb, sb->len + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strbuf_add_unique_abbrev(struct strbuf *sb, const unsigned char *sha1,
|
||||||
|
int abbrev_len)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
|
||||||
|
r = find_unique_abbrev_r(sb->buf + sb->len, sha1, abbrev_len);
|
||||||
|
strbuf_setlen(sb, sb->len + r);
|
||||||
|
}
|
||||||
|
|
23
strbuf.h
23
strbuf.h
|
@ -474,6 +474,14 @@ static inline struct strbuf **strbuf_split(const struct strbuf *sb,
|
||||||
*/
|
*/
|
||||||
extern void strbuf_list_free(struct strbuf **);
|
extern void strbuf_list_free(struct strbuf **);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the abbreviation, as generated by find_unique_abbrev, of `sha1` to
|
||||||
|
* the strbuf `sb`.
|
||||||
|
*/
|
||||||
|
extern void strbuf_add_unique_abbrev(struct strbuf *sb,
|
||||||
|
const unsigned char *sha1,
|
||||||
|
int abbrev_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch the user preferred editor to edit a file and fill the buffer
|
* Launch the user preferred editor to edit a file and fill the buffer
|
||||||
* with the file's contents upon the user completing their editing. The
|
* with the file's contents upon the user completing their editing. The
|
||||||
|
@ -491,10 +499,21 @@ extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *
|
||||||
*/
|
*/
|
||||||
extern void strbuf_addstr_xml_quoted(struct strbuf *sb, const char *s);
|
extern void strbuf_addstr_xml_quoted(struct strbuf *sb, const char *s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Complete" the contents of `sb` by ensuring that either it ends with the
|
||||||
|
* character `term`, or it is empty. This can be used, for example,
|
||||||
|
* to ensure that text ends with a newline, but without creating an empty
|
||||||
|
* blank line if there is no content in the first place.
|
||||||
|
*/
|
||||||
|
static inline void strbuf_complete(struct strbuf *sb, char term)
|
||||||
|
{
|
||||||
|
if (sb->len && sb->buf[sb->len - 1] != term)
|
||||||
|
strbuf_addch(sb, term);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void strbuf_complete_line(struct strbuf *sb)
|
static inline void strbuf_complete_line(struct strbuf *sb)
|
||||||
{
|
{
|
||||||
if (sb->len && sb->buf[sb->len - 1] != '\n')
|
strbuf_complete(sb, '\n');
|
||||||
strbuf_addch(sb, '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int strbuf_branchname(struct strbuf *sb, const char *name);
|
extern int strbuf_branchname(struct strbuf *sb, const char *name);
|
||||||
|
|
|
@ -122,6 +122,7 @@ static int add_submodule_odb(const char *path)
|
||||||
struct strbuf objects_directory = STRBUF_INIT;
|
struct strbuf objects_directory = STRBUF_INIT;
|
||||||
struct alternate_object_database *alt_odb;
|
struct alternate_object_database *alt_odb;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int alloc;
|
||||||
|
|
||||||
strbuf_git_path_submodule(&objects_directory, path, "objects/");
|
strbuf_git_path_submodule(&objects_directory, path, "objects/");
|
||||||
if (!is_directory(objects_directory.buf)) {
|
if (!is_directory(objects_directory.buf)) {
|
||||||
|
@ -135,9 +136,10 @@ static int add_submodule_odb(const char *path)
|
||||||
objects_directory.len))
|
objects_directory.len))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
|
alloc = objects_directory.len + 42; /* for "12/345..." sha1 */
|
||||||
|
alt_odb = xmalloc(sizeof(*alt_odb) + alloc);
|
||||||
alt_odb->next = alt_odb_list;
|
alt_odb->next = alt_odb_list;
|
||||||
strcpy(alt_odb->base, objects_directory.buf);
|
xsnprintf(alt_odb->base, alloc, "%s", objects_directory.buf);
|
||||||
alt_odb->name = alt_odb->base + objects_directory.len;
|
alt_odb->name = alt_odb->base + objects_directory.len;
|
||||||
alt_odb->name[2] = '/';
|
alt_odb->name[2] = '/';
|
||||||
alt_odb->name[40] = '\0';
|
alt_odb->name[40] = '\0';
|
||||||
|
|
|
@ -202,8 +202,8 @@ test_expect_success 'init honors global core.sharedRepository' '
|
||||||
x$(git config -f shared-honor-global/.git/config core.sharedRepository)
|
x$(git config -f shared-honor-global/.git/config core.sharedRepository)
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'init rejects insanely long --template' '
|
test_expect_success 'init allows insanely long --template' '
|
||||||
test_must_fail git init --template=$(printf "x%09999dx" 1) test
|
git init --template=$(printf "x%09999dx" 1) test
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'init creates a new directory' '
|
test_expect_success 'init creates a new directory' '
|
||||||
|
|
|
@ -63,4 +63,33 @@ test_expect_success 'symbolic-ref fails to delete real ref' '
|
||||||
'
|
'
|
||||||
reset_to_sane
|
reset_to_sane
|
||||||
|
|
||||||
|
test_expect_success 'create large ref name' '
|
||||||
|
# make 256+ character ref; some systems may not handle that,
|
||||||
|
# so be gentle
|
||||||
|
long=0123456789abcdef &&
|
||||||
|
long=$long/$long/$long/$long &&
|
||||||
|
long=$long/$long/$long/$long &&
|
||||||
|
long_ref=refs/heads/$long &&
|
||||||
|
tree=$(git write-tree) &&
|
||||||
|
commit=$(echo foo | git commit-tree $tree) &&
|
||||||
|
if git update-ref $long_ref $commit; then
|
||||||
|
test_set_prereq LONG_REF
|
||||||
|
else
|
||||||
|
echo >&2 "long refs not supported"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
|
||||||
|
git symbolic-ref HEAD $long_ref &&
|
||||||
|
echo $long_ref >expect &&
|
||||||
|
git symbolic-ref HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success LONG_REF 'we can parse long symbolic ref' '
|
||||||
|
echo $commit >expect &&
|
||||||
|
git rev-parse --verify HEAD >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
|
@ -69,4 +69,32 @@ test_expect_success 'update backfilled tag without primary transfer' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success 'set up fake git-daemon' '
|
||||||
|
mkdir remote &&
|
||||||
|
git init --bare remote/one.git &&
|
||||||
|
mkdir remote/host &&
|
||||||
|
git init --bare remote/host/two.git &&
|
||||||
|
write_script fake-daemon <<-\EOF &&
|
||||||
|
git daemon --inetd \
|
||||||
|
--informative-errors \
|
||||||
|
--export-all \
|
||||||
|
--base-path="$TRASH_DIRECTORY/remote" \
|
||||||
|
--interpolated-path="$TRASH_DIRECTORY/remote/%H%D" \
|
||||||
|
"$TRASH_DIRECTORY/remote"
|
||||||
|
EOF
|
||||||
|
export TRASH_DIRECTORY &&
|
||||||
|
PATH=$TRASH_DIRECTORY:$PATH
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ext command can connect to git daemon (no vhost)' '
|
||||||
|
rm -rf dst &&
|
||||||
|
git clone "ext::fake-daemon %G/one.git" dst
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ext command can connect to git daemon (vhost)' '
|
||||||
|
rm -rf dst &&
|
||||||
|
git clone "ext::fake-daemon %G/two.git %Vhost" dst
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
2
tag.c
2
tag.c
|
@ -82,7 +82,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
|
||||||
nl = memchr(bufptr, '\n', tail - bufptr);
|
nl = memchr(bufptr, '\n', tail - bufptr);
|
||||||
if (!nl || sizeof(type) <= (nl - bufptr))
|
if (!nl || sizeof(type) <= (nl - bufptr))
|
||||||
return -1;
|
return -1;
|
||||||
strncpy(type, bufptr, nl - bufptr);
|
memcpy(type, bufptr, nl - bufptr);
|
||||||
type[nl - bufptr] = '\0';
|
type[nl - bufptr] = '\0';
|
||||||
bufptr = nl + 1;
|
bufptr = nl + 1;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ static int dump_cache_tree(struct cache_tree *it,
|
||||||
struct cache_tree_sub *rdwn;
|
struct cache_tree_sub *rdwn;
|
||||||
|
|
||||||
rdwn = cache_tree_sub(ref, down->name);
|
rdwn = cache_tree_sub(ref, down->name);
|
||||||
sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
|
xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
|
||||||
if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
|
if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
|
||||||
errs = 1;
|
errs = 1;
|
||||||
}
|
}
|
||||||
|
|
23
trace.c
23
trace.c
|
@ -277,25 +277,24 @@ void trace_performance_fl(const char *file, int line, uint64_t nanos,
|
||||||
|
|
||||||
static const char *quote_crnl(const char *path)
|
static const char *quote_crnl(const char *path)
|
||||||
{
|
{
|
||||||
static char new_path[PATH_MAX];
|
static struct strbuf new_path = STRBUF_INIT;
|
||||||
const char *p2 = path;
|
|
||||||
char *p1 = new_path;
|
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (*p2) {
|
strbuf_reset(&new_path);
|
||||||
switch (*p2) {
|
|
||||||
case '\\': *p1++ = '\\'; *p1++ = '\\'; break;
|
while (*path) {
|
||||||
case '\n': *p1++ = '\\'; *p1++ = 'n'; break;
|
switch (*path) {
|
||||||
case '\r': *p1++ = '\\'; *p1++ = 'r'; break;
|
case '\\': strbuf_addstr(&new_path, "\\\\"); break;
|
||||||
|
case '\n': strbuf_addstr(&new_path, "\\n"); break;
|
||||||
|
case '\r': strbuf_addstr(&new_path, "\\r"); break;
|
||||||
default:
|
default:
|
||||||
*p1++ = *p2;
|
strbuf_addch(&new_path, *path);
|
||||||
}
|
}
|
||||||
p2++;
|
path++;
|
||||||
}
|
}
|
||||||
*p1 = '\0';
|
return new_path.buf;
|
||||||
return new_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: move prefix to startup_info struct and get rid of this arg */
|
/* FIXME: move prefix to startup_info struct and get rid of this arg */
|
||||||
|
|
13
transport.c
13
transport.c
|
@ -654,23 +654,24 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
|
||||||
"[new branch]"),
|
"[new branch]"),
|
||||||
ref, ref->peer_ref, NULL, porcelain);
|
ref, ref->peer_ref, NULL, porcelain);
|
||||||
else {
|
else {
|
||||||
char quickref[84];
|
struct strbuf quickref = STRBUF_INIT;
|
||||||
char type;
|
char type;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
|
|
||||||
strcpy(quickref, status_abbrev(ref->old_sha1));
|
strbuf_addstr(&quickref, status_abbrev(ref->old_sha1));
|
||||||
if (ref->forced_update) {
|
if (ref->forced_update) {
|
||||||
strcat(quickref, "...");
|
strbuf_addstr(&quickref, "...");
|
||||||
type = '+';
|
type = '+';
|
||||||
msg = "forced update";
|
msg = "forced update";
|
||||||
} else {
|
} else {
|
||||||
strcat(quickref, "..");
|
strbuf_addstr(&quickref, "..");
|
||||||
type = ' ';
|
type = ' ';
|
||||||
msg = NULL;
|
msg = NULL;
|
||||||
}
|
}
|
||||||
strcat(quickref, status_abbrev(ref->new_sha1));
|
strbuf_addstr(&quickref, status_abbrev(ref->new_sha1));
|
||||||
|
|
||||||
print_ref_status(type, quickref, ref, ref->peer_ref, msg, porcelain);
|
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
|
||||||
|
strbuf_release(&quickref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1350,9 +1350,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
|
||||||
* Then we need to make sure that we do not lose a locally
|
* Then we need to make sure that we do not lose a locally
|
||||||
* present file that is not ignored.
|
* present file that is not ignored.
|
||||||
*/
|
*/
|
||||||
pathbuf = xmalloc(namelen + 2);
|
pathbuf = xstrfmt("%.*s/", namelen, ce->name);
|
||||||
memcpy(pathbuf, ce->name, namelen);
|
|
||||||
strcpy(pathbuf+namelen, "/");
|
|
||||||
|
|
||||||
memset(&d, 0, sizeof(d));
|
memset(&d, 0, sizeof(d));
|
||||||
if (o->dir)
|
if (o->dir)
|
||||||
|
|
3
url.c
3
url.c
|
@ -120,8 +120,7 @@ char *url_decode_parameter_value(const char **query)
|
||||||
void end_url_with_slash(struct strbuf *buf, const char *url)
|
void end_url_with_slash(struct strbuf *buf, const char *url)
|
||||||
{
|
{
|
||||||
strbuf_addstr(buf, url);
|
strbuf_addstr(buf, url);
|
||||||
if (buf->len && buf->buf[buf->len - 1] != '/')
|
strbuf_complete(buf, '/');
|
||||||
strbuf_addch(buf, '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_end_url_with_slash(const char *url, char **dest) {
|
void str_end_url_with_slash(const char *url, char **dest) {
|
||||||
|
|
5
walker.c
5
walker.c
|
@ -17,10 +17,9 @@ void walker_say(struct walker *walker, const char *fmt, const char *hex)
|
||||||
|
|
||||||
static void report_missing(const struct object *obj)
|
static void report_missing(const struct object *obj)
|
||||||
{
|
{
|
||||||
char missing_hex[41];
|
|
||||||
strcpy(missing_hex, sha1_to_hex(obj->sha1));
|
|
||||||
fprintf(stderr, "Cannot obtain needed %s %s\n",
|
fprintf(stderr, "Cannot obtain needed %s %s\n",
|
||||||
obj->type ? typename(obj->type): "object", missing_hex);
|
obj->type ? typename(obj->type): "object",
|
||||||
|
sha1_to_hex(obj->sha1));
|
||||||
if (!is_null_sha1(current_commit_sha1))
|
if (!is_null_sha1(current_commit_sha1))
|
||||||
fprintf(stderr, "while processing commit %s.\n",
|
fprintf(stderr, "while processing commit %s.\n",
|
||||||
sha1_to_hex(current_commit_sha1));
|
sha1_to_hex(current_commit_sha1));
|
||||||
|
|
16
wrapper.c
16
wrapper.c
|
@ -621,6 +621,22 @@ char *xgetcwd(void)
|
||||||
return strbuf_detach(&sb, NULL);
|
return strbuf_detach(&sb, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xsnprintf(char *dst, size_t max, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(dst, max, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
die("BUG: your snprintf is broken");
|
||||||
|
if (len >= max)
|
||||||
|
die("BUG: attempt to snprintf into too-small buffer");
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static int write_file_v(const char *path, int fatal,
|
static int write_file_v(const char *path, int fatal,
|
||||||
const char *fmt, va_list params)
|
const char *fmt, va_list params)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче