Avoid using identifiers that clash with C++ keywords.  Even though
it is not a goal to compile Git with C++ compilers, changes like
this help use of code analysis tools that targets C++ on our
codebase.

* bw/c-plus-plus: (37 commits)
  replace: rename 'new' variables
  trailer: rename 'template' variables
  tempfile: rename 'template' variables
  wrapper: rename 'template' variables
  environment: rename 'namespace' variables
  diff: rename 'template' variables
  environment: rename 'template' variables
  init-db: rename 'template' variables
  unpack-trees: rename 'new' variables
  trailer: rename 'new' variables
  submodule: rename 'new' variables
  split-index: rename 'new' variables
  remote: rename 'new' variables
  ref-filter: rename 'new' variables
  read-cache: rename 'new' variables
  line-log: rename 'new' variables
  imap-send: rename 'new' variables
  http: rename 'new' variables
  entry: rename 'new' variables
  diffcore-delta: rename 'new' variables
  ...
This commit is contained in:
Junio C Hamano 2018-03-06 14:54:07 -08:00
Родитель c14d5f99cd efdfe11f4f
Коммит 169c9c0169
63 изменённых файлов: 663 добавлений и 662 удалений

122
apply.c
Просмотреть файл

@ -2301,7 +2301,7 @@ static void update_pre_post_images(struct image *preimage,
size_t len, size_t postlen) size_t len, size_t postlen)
{ {
int i, ctx, reduced; int i, ctx, reduced;
char *new, *old, *fixed; char *new_buf, *old_buf, *fixed;
struct image fixed_preimage; struct image fixed_preimage;
/* /*
@ -2327,25 +2327,25 @@ static void update_pre_post_images(struct image *preimage,
* We trust the caller to tell us if the update can be done * We trust the caller to tell us if the update can be done
* in place (postlen==0) or not. * in place (postlen==0) or not.
*/ */
old = postimage->buf; old_buf = postimage->buf;
if (postlen) if (postlen)
new = postimage->buf = xmalloc(postlen); new_buf = postimage->buf = xmalloc(postlen);
else else
new = old; new_buf = old_buf;
fixed = preimage->buf; fixed = preimage->buf;
for (i = reduced = ctx = 0; i < postimage->nr; i++) { for (i = reduced = ctx = 0; i < postimage->nr; i++) {
size_t l_len = postimage->line[i].len; size_t l_len = postimage->line[i].len;
if (!(postimage->line[i].flag & LINE_COMMON)) { if (!(postimage->line[i].flag & LINE_COMMON)) {
/* an added line -- no counterparts in preimage */ /* an added line -- no counterparts in preimage */
memmove(new, old, l_len); memmove(new_buf, old_buf, l_len);
old += l_len; old_buf += l_len;
new += l_len; new_buf += l_len;
continue; continue;
} }
/* a common context -- skip it in the original postimage */ /* a common context -- skip it in the original postimage */
old += l_len; old_buf += l_len;
/* and find the corresponding one in the fixed preimage */ /* and find the corresponding one in the fixed preimage */
while (ctx < preimage->nr && while (ctx < preimage->nr &&
@ -2365,29 +2365,29 @@ static void update_pre_post_images(struct image *preimage,
/* and copy it in, while fixing the line length */ /* and copy it in, while fixing the line length */
l_len = preimage->line[ctx].len; l_len = preimage->line[ctx].len;
memcpy(new, fixed, l_len); memcpy(new_buf, fixed, l_len);
new += l_len; new_buf += l_len;
fixed += l_len; fixed += l_len;
postimage->line[i].len = l_len; postimage->line[i].len = l_len;
ctx++; ctx++;
} }
if (postlen if (postlen
? postlen < new - postimage->buf ? postlen < new_buf - postimage->buf
: postimage->len < new - postimage->buf) : postimage->len < new_buf - postimage->buf)
die("BUG: caller miscounted postlen: asked %d, orig = %d, used = %d", die("BUG: caller miscounted postlen: asked %d, orig = %d, used = %d",
(int)postlen, (int) postimage->len, (int)(new - postimage->buf)); (int)postlen, (int) postimage->len, (int)(new_buf - postimage->buf));
/* Fix the length of the whole thing */ /* Fix the length of the whole thing */
postimage->len = new - postimage->buf; postimage->len = new_buf - postimage->buf;
postimage->nr -= reduced; postimage->nr -= reduced;
} }
static int line_by_line_fuzzy_match(struct image *img, static int line_by_line_fuzzy_match(struct image *img,
struct image *preimage, struct image *preimage,
struct image *postimage, struct image *postimage,
unsigned long try, unsigned long current,
int try_lno, int current_lno,
int preimage_limit) int preimage_limit)
{ {
int i; int i;
@ -2404,9 +2404,9 @@ static int line_by_line_fuzzy_match(struct image *img,
for (i = 0; i < preimage_limit; i++) { for (i = 0; i < preimage_limit; i++) {
size_t prelen = preimage->line[i].len; size_t prelen = preimage->line[i].len;
size_t imglen = img->line[try_lno+i].len; size_t imglen = img->line[current_lno+i].len;
if (!fuzzy_matchlines(img->buf + try + imgoff, imglen, if (!fuzzy_matchlines(img->buf + current + imgoff, imglen,
preimage->buf + preoff, prelen)) preimage->buf + preoff, prelen))
return 0; return 0;
if (preimage->line[i].flag & LINE_COMMON) if (preimage->line[i].flag & LINE_COMMON)
@ -2443,7 +2443,7 @@ static int line_by_line_fuzzy_match(struct image *img,
*/ */
extra_chars = preimage_end - preimage_eof; extra_chars = preimage_end - preimage_eof;
strbuf_init(&fixed, imgoff + extra_chars); strbuf_init(&fixed, imgoff + extra_chars);
strbuf_add(&fixed, img->buf + try, imgoff); strbuf_add(&fixed, img->buf + current, imgoff);
strbuf_add(&fixed, preimage_eof, extra_chars); strbuf_add(&fixed, preimage_eof, extra_chars);
fixed_buf = strbuf_detach(&fixed, &fixed_len); fixed_buf = strbuf_detach(&fixed, &fixed_len);
update_pre_post_images(preimage, postimage, update_pre_post_images(preimage, postimage,
@ -2455,8 +2455,8 @@ static int match_fragment(struct apply_state *state,
struct image *img, struct image *img,
struct image *preimage, struct image *preimage,
struct image *postimage, struct image *postimage,
unsigned long try, unsigned long current,
int try_lno, int current_lno,
unsigned ws_rule, unsigned ws_rule,
int match_beginning, int match_end) int match_beginning, int match_end)
{ {
@ -2466,12 +2466,12 @@ static int match_fragment(struct apply_state *state,
size_t fixed_len, postlen; size_t fixed_len, postlen;
int preimage_limit; int preimage_limit;
if (preimage->nr + try_lno <= img->nr) { if (preimage->nr + current_lno <= img->nr) {
/* /*
* The hunk falls within the boundaries of img. * The hunk falls within the boundaries of img.
*/ */
preimage_limit = preimage->nr; preimage_limit = preimage->nr;
if (match_end && (preimage->nr + try_lno != img->nr)) if (match_end && (preimage->nr + current_lno != img->nr))
return 0; return 0;
} else if (state->ws_error_action == correct_ws_error && } else if (state->ws_error_action == correct_ws_error &&
(ws_rule & WS_BLANK_AT_EOF)) { (ws_rule & WS_BLANK_AT_EOF)) {
@ -2482,7 +2482,7 @@ static int match_fragment(struct apply_state *state,
* match with img, and the remainder of the preimage * match with img, and the remainder of the preimage
* must be blank. * must be blank.
*/ */
preimage_limit = img->nr - try_lno; preimage_limit = img->nr - current_lno;
} else { } else {
/* /*
* The hunk extends beyond the end of the img and * The hunk extends beyond the end of the img and
@ -2492,27 +2492,27 @@ static int match_fragment(struct apply_state *state,
return 0; return 0;
} }
if (match_beginning && try_lno) if (match_beginning && current_lno)
return 0; return 0;
/* Quick hash check */ /* Quick hash check */
for (i = 0; i < preimage_limit; i++) for (i = 0; i < preimage_limit; i++)
if ((img->line[try_lno + i].flag & LINE_PATCHED) || if ((img->line[current_lno + i].flag & LINE_PATCHED) ||
(preimage->line[i].hash != img->line[try_lno + i].hash)) (preimage->line[i].hash != img->line[current_lno + i].hash))
return 0; return 0;
if (preimage_limit == preimage->nr) { if (preimage_limit == preimage->nr) {
/* /*
* Do we have an exact match? If we were told to match * Do we have an exact match? If we were told to match
* at the end, size must be exactly at try+fragsize, * at the end, size must be exactly at current+fragsize,
* otherwise try+fragsize must be still within the preimage, * otherwise current+fragsize must be still within the preimage,
* and either case, the old piece should match the preimage * and either case, the old piece should match the preimage
* exactly. * exactly.
*/ */
if ((match_end if ((match_end
? (try + preimage->len == img->len) ? (current + preimage->len == img->len)
: (try + preimage->len <= img->len)) && : (current + preimage->len <= img->len)) &&
!memcmp(img->buf + try, preimage->buf, preimage->len)) !memcmp(img->buf + current, preimage->buf, preimage->len))
return 1; return 1;
} else { } else {
/* /*
@ -2543,7 +2543,7 @@ static int match_fragment(struct apply_state *state,
*/ */
if (state->ws_ignore_action == ignore_ws_change) if (state->ws_ignore_action == ignore_ws_change)
return line_by_line_fuzzy_match(img, preimage, postimage, return line_by_line_fuzzy_match(img, preimage, postimage,
try, try_lno, preimage_limit); current, current_lno, preimage_limit);
if (state->ws_error_action != correct_ws_error) if (state->ws_error_action != correct_ws_error)
return 0; return 0;
@ -2577,10 +2577,10 @@ static int match_fragment(struct apply_state *state,
*/ */
strbuf_init(&fixed, preimage->len + 1); strbuf_init(&fixed, preimage->len + 1);
orig = preimage->buf; orig = preimage->buf;
target = img->buf + try; target = img->buf + current;
for (i = 0; i < preimage_limit; i++) { for (i = 0; i < preimage_limit; i++) {
size_t oldlen = preimage->line[i].len; size_t oldlen = preimage->line[i].len;
size_t tgtlen = img->line[try_lno + i].len; size_t tgtlen = img->line[current_lno + i].len;
size_t fixstart = fixed.len; size_t fixstart = fixed.len;
struct strbuf tgtfix; struct strbuf tgtfix;
int match; int match;
@ -2666,8 +2666,8 @@ static int find_pos(struct apply_state *state,
int match_beginning, int match_end) int match_beginning, int match_end)
{ {
int i; int i;
unsigned long backwards, forwards, try; unsigned long backwards, forwards, current;
int backwards_lno, forwards_lno, try_lno; int backwards_lno, forwards_lno, current_lno;
/* /*
* If match_beginning or match_end is specified, there is no * If match_beginning or match_end is specified, there is no
@ -2687,25 +2687,25 @@ static int find_pos(struct apply_state *state,
if ((size_t) line > img->nr) if ((size_t) line > img->nr)
line = img->nr; line = img->nr;
try = 0; current = 0;
for (i = 0; i < line; i++) for (i = 0; i < line; i++)
try += img->line[i].len; current += img->line[i].len;
/* /*
* There's probably some smart way to do this, but I'll leave * There's probably some smart way to do this, but I'll leave
* that to the smart and beautiful people. I'm simple and stupid. * that to the smart and beautiful people. I'm simple and stupid.
*/ */
backwards = try; backwards = current;
backwards_lno = line; backwards_lno = line;
forwards = try; forwards = current;
forwards_lno = line; forwards_lno = line;
try_lno = line; current_lno = line;
for (i = 0; ; i++) { for (i = 0; ; i++) {
if (match_fragment(state, img, preimage, postimage, if (match_fragment(state, img, preimage, postimage,
try, try_lno, ws_rule, current, current_lno, ws_rule,
match_beginning, match_end)) match_beginning, match_end))
return try_lno; return current_lno;
again: again:
if (backwards_lno == 0 && forwards_lno == img->nr) if (backwards_lno == 0 && forwards_lno == img->nr)
@ -2718,8 +2718,8 @@ static int find_pos(struct apply_state *state,
} }
backwards_lno--; backwards_lno--;
backwards -= img->line[backwards_lno].len; backwards -= img->line[backwards_lno].len;
try = backwards; current = backwards;
try_lno = backwards_lno; current_lno = backwards_lno;
} else { } else {
if (forwards_lno == img->nr) { if (forwards_lno == img->nr) {
i++; i++;
@ -2727,8 +2727,8 @@ static int find_pos(struct apply_state *state,
} }
forwards += img->line[forwards_lno].len; forwards += img->line[forwards_lno].len;
forwards_lno++; forwards_lno++;
try = forwards; current = forwards;
try_lno = forwards_lno; current_lno = forwards_lno;
} }
} }
@ -4163,30 +4163,30 @@ static void show_mode_change(struct patch *p, int show_name)
static void show_rename_copy(struct patch *p) static void show_rename_copy(struct patch *p)
{ {
const char *renamecopy = p->is_rename ? "rename" : "copy"; const char *renamecopy = p->is_rename ? "rename" : "copy";
const char *old, *new; const char *old_name, *new_name;
/* Find common prefix */ /* Find common prefix */
old = p->old_name; old_name = p->old_name;
new = p->new_name; new_name = p->new_name;
while (1) { while (1) {
const char *slash_old, *slash_new; const char *slash_old, *slash_new;
slash_old = strchr(old, '/'); slash_old = strchr(old_name, '/');
slash_new = strchr(new, '/'); slash_new = strchr(new_name, '/');
if (!slash_old || if (!slash_old ||
!slash_new || !slash_new ||
slash_old - old != slash_new - new || slash_old - old_name != slash_new - new_name ||
memcmp(old, new, slash_new - new)) memcmp(old_name, new_name, slash_new - new_name))
break; break;
old = slash_old + 1; old_name = slash_old + 1;
new = slash_new + 1; new_name = slash_new + 1;
} }
/* p->old_name thru old is the common prefix, and old and new /* p->old_name thru old_name is the common prefix, and old_name and new_name
* through the end of names are renames * through the end of names are renames
*/ */
if (old != p->old_name) if (old_name != p->old_name)
printf(" %s %.*s{%s => %s} (%d%%)\n", renamecopy, printf(" %s %.*s{%s => %s} (%d%%)\n", renamecopy,
(int)(old - p->old_name), p->old_name, (int)(old_name - p->old_name), p->old_name,
old, new, p->score); old_name, new_name, p->score);
else else
printf(" %s %s => %s (%d%%)\n", renamecopy, printf(" %s %s => %s (%d%%)\n", renamecopy,
p->old_name, p->new_name, p->score); p->old_name, p->new_name, p->score);

33
blame.c
Просмотреть файл

@ -998,28 +998,29 @@ unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e)
} }
/* /*
* best_so_far[] and this[] are both a split of an existing blame_entry * best_so_far[] and potential[] are both a split of an existing blame_entry
* that passes blame to the parent. Maintain best_so_far the best split * that passes blame to the parent. Maintain best_so_far the best split so
* so far, by comparing this and best_so_far and copying this into * far, by comparing potential and best_so_far and copying potential into
* bst_so_far as needed. * bst_so_far as needed.
*/ */
static void copy_split_if_better(struct blame_scoreboard *sb, static void copy_split_if_better(struct blame_scoreboard *sb,
struct blame_entry *best_so_far, struct blame_entry *best_so_far,
struct blame_entry *this) struct blame_entry *potential)
{ {
int i; int i;
if (!this[1].suspect) if (!potential[1].suspect)
return; return;
if (best_so_far[1].suspect) { if (best_so_far[1].suspect) {
if (blame_entry_score(sb, &this[1]) < blame_entry_score(sb, &best_so_far[1])) if (blame_entry_score(sb, &potential[1]) <
blame_entry_score(sb, &best_so_far[1]))
return; return;
} }
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
blame_origin_incref(this[i].suspect); blame_origin_incref(potential[i].suspect);
decref_split(best_so_far); decref_split(best_so_far);
memcpy(best_so_far, this, sizeof(struct blame_entry [3])); memcpy(best_so_far, potential, sizeof(struct blame_entry[3]));
} }
/* /*
@ -1046,12 +1047,12 @@ static void handle_split(struct blame_scoreboard *sb,
if (ent->num_lines <= tlno) if (ent->num_lines <= tlno)
return; return;
if (tlno < same) { if (tlno < same) {
struct blame_entry this[3]; struct blame_entry potential[3];
tlno += ent->s_lno; tlno += ent->s_lno;
same += ent->s_lno; same += ent->s_lno;
split_overlap(this, ent, tlno, plno, same, parent); split_overlap(potential, ent, tlno, plno, same, parent);
copy_split_if_better(sb, split, this); copy_split_if_better(sb, split, potential);
decref_split(this); decref_split(potential);
} }
} }
@ -1273,7 +1274,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
struct diff_filepair *p = diff_queued_diff.queue[i]; struct diff_filepair *p = diff_queued_diff.queue[i];
struct blame_origin *norigin; struct blame_origin *norigin;
mmfile_t file_p; mmfile_t file_p;
struct blame_entry this[3]; struct blame_entry potential[3];
if (!DIFF_FILE_VALID(p->one)) if (!DIFF_FILE_VALID(p->one))
continue; /* does not exist in parent */ continue; /* does not exist in parent */
@ -1292,10 +1293,10 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
for (j = 0; j < num_ents; j++) { for (j = 0; j < num_ents; j++) {
find_copy_in_blob(sb, blame_list[j].ent, find_copy_in_blob(sb, blame_list[j].ent,
norigin, this, &file_p); norigin, potential, &file_p);
copy_split_if_better(sb, blame_list[j].split, copy_split_if_better(sb, blame_list[j].split,
this); potential);
decref_split(this); decref_split(potential);
} }
blame_origin_decref(norigin); blame_origin_decref(norigin);
} }

Просмотреть файл

@ -76,7 +76,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
buf = NULL; buf = NULL;
switch (opt) { switch (opt) {
case 't': case 't':
oi.typename = &sb; oi.type_name = &sb;
if (sha1_object_info_extended(oid.hash, &oi, flags) < 0) if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
die("git cat-file: could not get object info"); die("git cat-file: could not get object info");
if (sb.len) { if (sb.len) {
@ -229,7 +229,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
if (data->mark_query) if (data->mark_query)
data->info.typep = &data->type; data->info.typep = &data->type;
else else
strbuf_addstr(sb, typename(data->type)); strbuf_addstr(sb, type_name(data->type));
} else if (is_atom("objectsize", atom, len)) { } else if (is_atom("objectsize", atom, len)) {
if (data->mark_query) if (data->mark_query)
data->info.sizep = &data->size; data->info.sizep = &data->size;

Просмотреть файл

@ -54,14 +54,14 @@ struct checkout_opts {
struct tree *source_tree; struct tree *source_tree;
}; };
static int post_checkout_hook(struct commit *old, struct commit *new, static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
int changed) int changed)
{ {
return run_hook_le(NULL, "post-checkout", return run_hook_le(NULL, "post-checkout",
oid_to_hex(old ? &old->object.oid : &null_oid), oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid),
oid_to_hex(new ? &new->object.oid : &null_oid), oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid),
changed ? "1" : "0", NULL); changed ? "1" : "0", NULL);
/* "new" can be NULL when checking out from the index before /* "new_commit" can be NULL when checking out from the index before
a commit exists. */ a commit exists. */
} }
@ -471,8 +471,8 @@ static void setup_branch_path(struct branch_info *branch)
} }
static int merge_working_tree(const struct checkout_opts *opts, static int merge_working_tree(const struct checkout_opts *opts,
struct branch_info *old, struct branch_info *old_branch_info,
struct branch_info *new, struct branch_info *new_branch_info,
int *writeout_error) int *writeout_error)
{ {
int ret; int ret;
@ -484,7 +484,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
resolve_undo_clear(); resolve_undo_clear();
if (opts->force) { if (opts->force) {
ret = reset_tree(new->commit->tree, opts, 1, writeout_error); ret = reset_tree(new_branch_info->commit->tree, opts, 1, writeout_error);
if (ret) if (ret)
return ret; return ret;
} else { } else {
@ -510,7 +510,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
topts.initial_checkout = is_cache_unborn(); topts.initial_checkout = is_cache_unborn();
topts.update = 1; topts.update = 1;
topts.merge = 1; topts.merge = 1;
topts.gently = opts->merge && old->commit; topts.gently = opts->merge && old_branch_info->commit;
topts.verbose_update = opts->show_progress; topts.verbose_update = opts->show_progress;
topts.fn = twoway_merge; topts.fn = twoway_merge;
if (opts->overwrite_ignore) { if (opts->overwrite_ignore) {
@ -518,11 +518,11 @@ static int merge_working_tree(const struct checkout_opts *opts,
topts.dir->flags |= DIR_SHOW_IGNORED; topts.dir->flags |= DIR_SHOW_IGNORED;
setup_standard_excludes(topts.dir); setup_standard_excludes(topts.dir);
} }
tree = parse_tree_indirect(old->commit ? tree = parse_tree_indirect(old_branch_info->commit ?
&old->commit->object.oid : &old_branch_info->commit->object.oid :
the_hash_algo->empty_tree); the_hash_algo->empty_tree);
init_tree_desc(&trees[0], tree->buffer, tree->size); init_tree_desc(&trees[0], tree->buffer, tree->size);
tree = parse_tree_indirect(&new->commit->object.oid); tree = parse_tree_indirect(&new_branch_info->commit->object.oid);
init_tree_desc(&trees[1], tree->buffer, tree->size); init_tree_desc(&trees[1], tree->buffer, tree->size);
ret = unpack_trees(2, trees, &topts); ret = unpack_trees(2, trees, &topts);
@ -539,10 +539,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
return 1; return 1;
/* /*
* Without old->commit, the below is the same as * Without old_branch_info->commit, the below is the same as
* the two-tree unpack we already tried and failed. * the two-tree unpack we already tried and failed.
*/ */
if (!old->commit) if (!old_branch_info->commit)
return 1; return 1;
/* Do more real merge */ /* Do more real merge */
@ -570,18 +570,18 @@ static int merge_working_tree(const struct checkout_opts *opts,
o.verbosity = 0; o.verbosity = 0;
work = write_tree_from_memory(&o); work = write_tree_from_memory(&o);
ret = reset_tree(new->commit->tree, opts, 1, ret = reset_tree(new_branch_info->commit->tree, opts, 1,
writeout_error); writeout_error);
if (ret) if (ret)
return ret; return ret;
o.ancestor = old->name; o.ancestor = old_branch_info->name;
o.branch1 = new->name; o.branch1 = new_branch_info->name;
o.branch2 = "local"; o.branch2 = "local";
ret = merge_trees(&o, new->commit->tree, work, ret = merge_trees(&o, new_branch_info->commit->tree, work,
old->commit->tree, &result); old_branch_info->commit->tree, &result);
if (ret < 0) if (ret < 0)
exit(128); exit(128);
ret = reset_tree(new->commit->tree, opts, 0, ret = reset_tree(new_branch_info->commit->tree, opts, 0,
writeout_error); writeout_error);
strbuf_release(&o.obuf); strbuf_release(&o.obuf);
if (ret) if (ret)
@ -599,15 +599,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
die(_("unable to write new index file")); die(_("unable to write new index file"));
if (!opts->force && !opts->quiet) if (!opts->force && !opts->quiet)
show_local_changes(&new->commit->object, &opts->diff_options); show_local_changes(&new_branch_info->commit->object, &opts->diff_options);
return 0; return 0;
} }
static void report_tracking(struct branch_info *new) static void report_tracking(struct branch_info *new_branch_info)
{ {
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
struct branch *branch = branch_get(new->name); struct branch *branch = branch_get(new_branch_info->name);
if (!format_tracking_info(branch, &sb)) if (!format_tracking_info(branch, &sb))
return; return;
@ -616,8 +616,8 @@ static void report_tracking(struct branch_info *new)
} }
static void update_refs_for_switch(const struct checkout_opts *opts, static void update_refs_for_switch(const struct checkout_opts *opts,
struct branch_info *old, struct branch_info *old_branch_info,
struct branch_info *new) struct branch_info *new_branch_info)
{ {
struct strbuf msg = STRBUF_INIT; struct strbuf msg = STRBUF_INIT;
const char *old_desc, *reflog_msg; const char *old_desc, *reflog_msg;
@ -644,69 +644,69 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
free(refname); free(refname);
} }
else else
create_branch(opts->new_branch, new->name, create_branch(opts->new_branch, new_branch_info->name,
opts->new_branch_force ? 1 : 0, opts->new_branch_force ? 1 : 0,
opts->new_branch_force ? 1 : 0, opts->new_branch_force ? 1 : 0,
opts->new_branch_log, opts->new_branch_log,
opts->quiet, opts->quiet,
opts->track); opts->track);
new->name = opts->new_branch; new_branch_info->name = opts->new_branch;
setup_branch_path(new); setup_branch_path(new_branch_info);
} }
old_desc = old->name; old_desc = old_branch_info->name;
if (!old_desc && old->commit) if (!old_desc && old_branch_info->commit)
old_desc = oid_to_hex(&old->commit->object.oid); old_desc = oid_to_hex(&old_branch_info->commit->object.oid);
reflog_msg = getenv("GIT_REFLOG_ACTION"); reflog_msg = getenv("GIT_REFLOG_ACTION");
if (!reflog_msg) if (!reflog_msg)
strbuf_addf(&msg, "checkout: moving from %s to %s", strbuf_addf(&msg, "checkout: moving from %s to %s",
old_desc ? old_desc : "(invalid)", new->name); old_desc ? old_desc : "(invalid)", new_branch_info->name);
else else
strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg)); strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) { if (!strcmp(new_branch_info->name, "HEAD") && !new_branch_info->path && !opts->force_detach) {
/* Nothing to do. */ /* Nothing to do. */
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */ } else if (opts->force_detach || !new_branch_info->path) { /* No longer on any branch. */
update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL, update_ref(msg.buf, "HEAD", &new_branch_info->commit->object.oid, NULL,
REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR); REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
if (!opts->quiet) { if (!opts->quiet) {
if (old->path && if (old_branch_info->path &&
advice_detached_head && !opts->force_detach) advice_detached_head && !opts->force_detach)
detach_advice(new->name); detach_advice(new_branch_info->name);
describe_detached_head(_("HEAD is now at"), new->commit); describe_detached_head(_("HEAD is now at"), new_branch_info->commit);
} }
} else if (new->path) { /* Switch branches. */ } else if (new_branch_info->path) { /* Switch branches. */
if (create_symref("HEAD", new->path, msg.buf) < 0) if (create_symref("HEAD", new_branch_info->path, msg.buf) < 0)
die(_("unable to update HEAD")); die(_("unable to update HEAD"));
if (!opts->quiet) { if (!opts->quiet) {
if (old->path && !strcmp(new->path, old->path)) { if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) {
if (opts->new_branch_force) if (opts->new_branch_force)
fprintf(stderr, _("Reset branch '%s'\n"), fprintf(stderr, _("Reset branch '%s'\n"),
new->name); new_branch_info->name);
else else
fprintf(stderr, _("Already on '%s'\n"), fprintf(stderr, _("Already on '%s'\n"),
new->name); new_branch_info->name);
} else if (opts->new_branch) { } else if (opts->new_branch) {
if (opts->branch_exists) if (opts->branch_exists)
fprintf(stderr, _("Switched to and reset branch '%s'\n"), new->name); fprintf(stderr, _("Switched to and reset branch '%s'\n"), new_branch_info->name);
else else
fprintf(stderr, _("Switched to a new branch '%s'\n"), new->name); fprintf(stderr, _("Switched to a new branch '%s'\n"), new_branch_info->name);
} else { } else {
fprintf(stderr, _("Switched to branch '%s'\n"), fprintf(stderr, _("Switched to branch '%s'\n"),
new->name); new_branch_info->name);
} }
} }
if (old->path && old->name) { if (old_branch_info->path && old_branch_info->name) {
if (!ref_exists(old->path) && reflog_exists(old->path)) if (!ref_exists(old_branch_info->path) && reflog_exists(old_branch_info->path))
delete_reflog(old->path); delete_reflog(old_branch_info->path);
} }
} }
remove_branch_state(); remove_branch_state();
strbuf_release(&msg); strbuf_release(&msg);
if (!opts->quiet && if (!opts->quiet &&
(new->path || (!opts->force_detach && !strcmp(new->name, "HEAD")))) (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
report_tracking(new); report_tracking(new_branch_info);
} }
static int add_pending_uninteresting_ref(const char *refname, static int add_pending_uninteresting_ref(const char *refname,
@ -786,10 +786,10 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
* HEAD. If it is not reachable from any ref, this is the last chance * HEAD. If it is not reachable from any ref, this is the last chance
* for the user to do so without resorting to reflog. * for the user to do so without resorting to reflog.
*/ */
static void orphaned_commit_warning(struct commit *old, struct commit *new) static void orphaned_commit_warning(struct commit *old_commit, struct commit *new_commit)
{ {
struct rev_info revs; struct rev_info revs;
struct object *object = &old->object; struct object *object = &old_commit->object;
init_revisions(&revs, NULL); init_revisions(&revs, NULL);
setup_revisions(0, NULL, &revs, NULL); setup_revisions(0, NULL, &revs, NULL);
@ -798,57 +798,57 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
add_pending_object(&revs, object, oid_to_hex(&object->oid)); add_pending_object(&revs, object, oid_to_hex(&object->oid));
for_each_ref(add_pending_uninteresting_ref, &revs); for_each_ref(add_pending_uninteresting_ref, &revs);
add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING); add_pending_oid(&revs, "HEAD", &new_commit->object.oid, UNINTERESTING);
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
die(_("internal error in revision walk")); die(_("internal error in revision walk"));
if (!(old->object.flags & UNINTERESTING)) if (!(old_commit->object.flags & UNINTERESTING))
suggest_reattach(old, &revs); suggest_reattach(old_commit, &revs);
else else
describe_detached_head(_("Previous HEAD position was"), old); describe_detached_head(_("Previous HEAD position was"), old_commit);
/* Clean up objects used, as they will be reused. */ /* Clean up objects used, as they will be reused. */
clear_commit_marks_all(ALL_REV_FLAGS); clear_commit_marks_all(ALL_REV_FLAGS);
} }
static int switch_branches(const struct checkout_opts *opts, static int switch_branches(const struct checkout_opts *opts,
struct branch_info *new) struct branch_info *new_branch_info)
{ {
int ret = 0; int ret = 0;
struct branch_info old; struct branch_info old_branch_info;
void *path_to_free; void *path_to_free;
struct object_id rev; struct object_id rev;
int flag, writeout_error = 0; int flag, writeout_error = 0;
memset(&old, 0, sizeof(old)); memset(&old_branch_info, 0, sizeof(old_branch_info));
old.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag); old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
if (old.path) if (old_branch_info.path)
old.commit = lookup_commit_reference_gently(&rev, 1); old_branch_info.commit = lookup_commit_reference_gently(&rev, 1);
if (!(flag & REF_ISSYMREF)) if (!(flag & REF_ISSYMREF))
old.path = NULL; old_branch_info.path = NULL;
if (old.path) if (old_branch_info.path)
skip_prefix(old.path, "refs/heads/", &old.name); skip_prefix(old_branch_info.path, "refs/heads/", &old_branch_info.name);
if (!new->name) { if (!new_branch_info->name) {
new->name = "HEAD"; new_branch_info->name = "HEAD";
new->commit = old.commit; new_branch_info->commit = old_branch_info.commit;
if (!new->commit) if (!new_branch_info->commit)
die(_("You are on a branch yet to be born")); die(_("You are on a branch yet to be born"));
parse_commit_or_die(new->commit); parse_commit_or_die(new_branch_info->commit);
} }
ret = merge_working_tree(opts, &old, new, &writeout_error); ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
if (ret) { if (ret) {
free(path_to_free); free(path_to_free);
return ret; return ret;
} }
if (!opts->quiet && !old.path && old.commit && new->commit != old.commit) if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)
orphaned_commit_warning(old.commit, new->commit); orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
update_refs_for_switch(opts, &old, new); update_refs_for_switch(opts, &old_branch_info, new_branch_info);
ret = post_checkout_hook(old.commit, new->commit, 1); ret = post_checkout_hook(old_branch_info.commit, new_branch_info->commit, 1);
free(path_to_free); free(path_to_free);
return ret || writeout_error; return ret || writeout_error;
} }
@ -869,7 +869,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
static int parse_branchname_arg(int argc, const char **argv, static int parse_branchname_arg(int argc, const char **argv,
int dwim_new_local_branch_ok, int dwim_new_local_branch_ok,
struct branch_info *new, struct branch_info *new_branch_info,
struct checkout_opts *opts, struct checkout_opts *opts,
struct object_id *rev) struct object_id *rev)
{ {
@ -987,22 +987,22 @@ static int parse_branchname_arg(int argc, const char **argv,
argv++; argv++;
argc--; argc--;
new->name = arg; new_branch_info->name = arg;
setup_branch_path(new); setup_branch_path(new_branch_info);
if (!check_refname_format(new->path, 0) && if (!check_refname_format(new_branch_info->path, 0) &&
!read_ref(new->path, &branch_rev)) !read_ref(new_branch_info->path, &branch_rev))
oidcpy(rev, &branch_rev); oidcpy(rev, &branch_rev);
else else
new->path = NULL; /* not an existing branch */ new_branch_info->path = NULL; /* not an existing branch */
new->commit = lookup_commit_reference_gently(rev, 1); new_branch_info->commit = lookup_commit_reference_gently(rev, 1);
if (!new->commit) { if (!new_branch_info->commit) {
/* not a commit */ /* not a commit */
*source_tree = parse_tree_indirect(rev); *source_tree = parse_tree_indirect(rev);
} else { } else {
parse_commit_or_die(new->commit); parse_commit_or_die(new_branch_info->commit);
*source_tree = new->commit->tree; *source_tree = new_branch_info->commit->tree;
} }
if (!*source_tree) /* case (1): want a tree */ if (!*source_tree) /* case (1): want a tree */
@ -1042,7 +1042,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
} }
static int checkout_branch(struct checkout_opts *opts, static int checkout_branch(struct checkout_opts *opts,
struct branch_info *new) struct branch_info *new_branch_info)
{ {
if (opts->pathspec.nr) if (opts->pathspec.nr)
die(_("paths cannot be used with switching branches")); die(_("paths cannot be used with switching branches"));
@ -1071,21 +1071,21 @@ static int checkout_branch(struct checkout_opts *opts,
} else if (opts->track == BRANCH_TRACK_UNSPECIFIED) } else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
opts->track = git_branch_track; opts->track = git_branch_track;
if (new->name && !new->commit) if (new_branch_info->name && !new_branch_info->commit)
die(_("Cannot switch branch to a non-commit '%s'"), die(_("Cannot switch branch to a non-commit '%s'"),
new->name); new_branch_info->name);
if (new->path && !opts->force_detach && !opts->new_branch && if (new_branch_info->path && !opts->force_detach && !opts->new_branch &&
!opts->ignore_other_worktrees) { !opts->ignore_other_worktrees) {
int flag; int flag;
char *head_ref = resolve_refdup("HEAD", 0, NULL, &flag); char *head_ref = resolve_refdup("HEAD", 0, NULL, &flag);
if (head_ref && if (head_ref &&
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path))) (!(flag & REF_ISSYMREF) || strcmp(head_ref, new_branch_info->path)))
die_if_checked_out(new->path, 1); die_if_checked_out(new_branch_info->path, 1);
free(head_ref); free(head_ref);
} }
if (!new->commit && opts->new_branch) { if (!new_branch_info->commit && opts->new_branch) {
struct object_id rev; struct object_id rev;
int flag; int flag;
@ -1093,13 +1093,13 @@ static int checkout_branch(struct checkout_opts *opts,
(flag & REF_ISSYMREF) && is_null_oid(&rev)) (flag & REF_ISSYMREF) && is_null_oid(&rev))
return switch_unborn_to_new_branch(opts); return switch_unborn_to_new_branch(opts);
} }
return switch_branches(opts, new); return switch_branches(opts, new_branch_info);
} }
int cmd_checkout(int argc, const char **argv, const char *prefix) int cmd_checkout(int argc, const char **argv, const char *prefix)
{ {
struct checkout_opts opts; struct checkout_opts opts;
struct branch_info new; struct branch_info new_branch_info;
char *conflict_style = NULL; char *conflict_style = NULL;
int dwim_new_local_branch = 1; int dwim_new_local_branch = 1;
struct option options[] = { struct option options[] = {
@ -1137,7 +1137,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
}; };
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
memset(&new, 0, sizeof(new)); memset(&new_branch_info, 0, sizeof(new_branch_info));
opts.overwrite_ignore = 1; opts.overwrite_ignore = 1;
opts.prefix = prefix; opts.prefix = prefix;
opts.show_progress = -1; opts.show_progress = -1;
@ -1209,7 +1209,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.track == BRANCH_TRACK_UNSPECIFIED && opts.track == BRANCH_TRACK_UNSPECIFIED &&
!opts.new_branch; !opts.new_branch;
int n = parse_branchname_arg(argc, argv, dwim_ok, int n = parse_branchname_arg(argc, argv, dwim_ok,
&new, &opts, &rev); &new_branch_info, &opts, &rev);
argv += n; argv += n;
argc -= n; argc -= n;
} }
@ -1252,7 +1252,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
UNLEAK(opts); UNLEAK(opts);
if (opts.patch_mode || opts.pathspec.nr) if (opts.patch_mode || opts.pathspec.nr)
return checkout_paths(&opts, new.name); return checkout_paths(&opts, new_branch_info.name);
else else
return checkout_branch(&opts, &new); return checkout_branch(&opts, &new_branch_info);
} }

Просмотреть файл

@ -76,7 +76,7 @@ static int diff_tree_stdin(char *line)
if (obj->type == OBJ_TREE) if (obj->type == OBJ_TREE)
return stdin_diff_trees((struct tree *)obj, p); return stdin_diff_trees((struct tree *)obj, p);
error("Object %s is a %s, not a commit or tree", error("Object %s is a %s, not a commit or tree",
oid_to_hex(&oid), typename(obj->type)); oid_to_hex(&oid), type_name(obj->type));
return -1; return -1;
} }

Просмотреть файл

@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
buf = read_sha1_file(oid->hash, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)
die ("Could not read blob %s", oid_to_hex(oid)); die ("Could not read blob %s", oid_to_hex(oid));
if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0) if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0)
die("sha1 mismatch in blob %s", oid_to_hex(oid)); die("sha1 mismatch in blob %s", oid_to_hex(oid));
object = parse_object_buffer(oid, type, size, buf, &eaten); object = parse_object_buffer(oid, type, size, buf, &eaten);
} }
@ -757,7 +757,7 @@ static void handle_tag(const char *name, struct tag *tag)
if (tagged->type != OBJ_COMMIT) { if (tagged->type != OBJ_COMMIT) {
die ("Tag %s tags unexported %s!", die ("Tag %s tags unexported %s!",
oid_to_hex(&tag->object.oid), oid_to_hex(&tag->object.oid),
typename(tagged->type)); type_name(tagged->type));
} }
p = (struct commit *)tagged; p = (struct commit *)tagged;
for (;;) { for (;;) {
@ -839,7 +839,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
if (!commit) { if (!commit) {
warning("%s: Unexpected object of type %s, skipping.", warning("%s: Unexpected object of type %s, skipping.",
e->name, e->name,
typename(e->item->type)); type_name(e->item->type));
continue; continue;
} }
@ -851,7 +851,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
continue; continue;
default: /* OBJ_TAG (nested tags) is already handled */ default: /* OBJ_TAG (nested tags) is already handled */
warning("Tag points to object of unexpected type %s, skipping.", warning("Tag points to object of unexpected type %s, skipping.",
typename(commit->object.type)); type_name(commit->object.type));
continue; continue;
} }

Просмотреть файл

@ -70,7 +70,7 @@ static const char *printable_type(struct object *obj)
object_as_type(obj, type, 0); object_as_type(obj, type, 0);
} }
ret = typename(obj->type); ret = type_name(obj->type);
if (!ret) if (!ret)
ret = "unknown"; ret = "unknown";
@ -137,7 +137,7 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
printf("broken link from %7s %s\n", printf("broken link from %7s %s\n",
printable_type(parent), describe_object(parent)); printable_type(parent), describe_object(parent));
printf("broken link from %7s %s\n", printf("broken link from %7s %s\n",
(type == OBJ_ANY ? "unknown" : typename(type)), "unknown"); (type == OBJ_ANY ? "unknown" : type_name(type)), "unknown");
errors_found |= ERROR_REACHABLE; errors_found |= ERROR_REACHABLE;
return 1; return 1;
} }

Просмотреть файл

@ -627,7 +627,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
free(data); free(data);
return hit; return hit;
} }
die(_("unable to grep from object of type %s"), typename(obj->type)); die(_("unable to grep from object of type %s"), type_name(obj->type));
} }
static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,

Просмотреть файл

@ -194,11 +194,11 @@ static void do_add_man_viewer_info(const char *name,
size_t len, size_t len,
const char *value) const char *value)
{ {
struct man_viewer_info_list *new; struct man_viewer_info_list *new_man_viewer;
FLEX_ALLOC_MEM(new, name, name, len); FLEX_ALLOC_MEM(new_man_viewer, name, name, len);
new->info = xstrdup(value); new_man_viewer->info = xstrdup(value);
new->next = man_viewer_info_list; new_man_viewer->next = man_viewer_info_list;
man_viewer_info_list = new; man_viewer_info_list = new_man_viewer;
} }
static int add_man_viewer_path(const char *name, static int add_man_viewer_path(const char *name,

Просмотреть файл

@ -228,7 +228,7 @@ static unsigned check_object(struct object *obj)
if (type != obj->type) if (type != obj->type)
die(_("object %s: expected type %s, found %s"), die(_("object %s: expected type %s, found %s"),
oid_to_hex(&obj->oid), oid_to_hex(&obj->oid),
typename(obj->type), typename(type)); type_name(obj->type), type_name(type));
obj->flags |= FLAG_CHECKED; obj->flags |= FLAG_CHECKED;
return 1; return 1;
} }
@ -448,7 +448,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
int hdrlen; int hdrlen;
if (!is_delta_type(type)) { if (!is_delta_type(type)) {
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), size) + 1; hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), size) + 1;
the_hash_algo->init_fn(&c); the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, hdrlen); the_hash_algo->update_fn(&c, hdr, hdrlen);
} else } else
@ -849,7 +849,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
obj = parse_object_buffer(oid, type, size, buf, obj = parse_object_buffer(oid, type, size, buf,
&eaten); &eaten);
if (!obj) if (!obj)
die(_("invalid %s"), typename(type)); die(_("invalid %s"), type_name(type));
if (do_fsck_object && if (do_fsck_object &&
fsck_object(obj, buf, size, &fsck_options)) fsck_object(obj, buf, size, &fsck_options))
die(_("Error in object")); die(_("Error in object"));
@ -959,7 +959,7 @@ static void resolve_delta(struct object_entry *delta_obj,
if (!result->data) if (!result->data)
bad_object(delta_obj->idx.offset, _("failed to apply delta")); bad_object(delta_obj->idx.offset, _("failed to apply delta"));
hash_object_file(result->data, result->size, hash_object_file(result->data, result->size,
typename(delta_obj->real_type), &delta_obj->idx.oid); type_name(delta_obj->real_type), &delta_obj->idx.oid);
sha1_object(result->data, NULL, result->size, delta_obj->real_type, sha1_object(result->data, NULL, result->size, delta_obj->real_type,
&delta_obj->idx.oid); &delta_obj->idx.oid);
counter_lock(); counter_lock();
@ -1378,7 +1378,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
continue; continue;
if (check_sha1_signature(d->sha1, base_obj->data, if (check_sha1_signature(d->sha1, base_obj->data,
base_obj->size, typename(type))) base_obj->size, type_name(type)))
die(_("local object %s is corrupt"), sha1_to_hex(d->sha1)); die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
base_obj->obj = append_obj_to_pack(f, d->sha1, base_obj->obj = append_obj_to_pack(f, d->sha1,
base_obj->data, base_obj->size, type); base_obj->data, base_obj->size, type);
@ -1615,7 +1615,7 @@ static void show_pack_info(int stat_only)
continue; continue;
printf("%s %-6s %lu %lu %"PRIuMAX, printf("%s %-6s %lu %lu %"PRIuMAX,
oid_to_hex(&obj->idx.oid), oid_to_hex(&obj->idx.oid),
typename(obj->real_type), obj->size, type_name(obj->real_type), obj->size,
(unsigned long)(obj[1].idx.offset - obj->idx.offset), (unsigned long)(obj[1].idx.offset - obj->idx.offset),
(uintmax_t)obj->idx.offset); (uintmax_t)obj->idx.offset);
if (is_delta_type(obj->type)) { if (is_delta_type(obj->type)) {

Просмотреть файл

@ -24,11 +24,11 @@ static int init_is_bare_repository = 0;
static int init_shared_repository = -1; static int init_shared_repository = -1;
static const char *init_db_template_dir; static const char *init_db_template_dir;
static void copy_templates_1(struct strbuf *path, struct strbuf *template, static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
DIR *dir) DIR *dir)
{ {
size_t path_baselen = path->len; size_t path_baselen = path->len;
size_t template_baselen = template->len; size_t template_baselen = template_path->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
@ -44,12 +44,12 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template,
int exists = 0; int exists = 0;
strbuf_setlen(path, path_baselen); strbuf_setlen(path, path_baselen);
strbuf_setlen(template, template_baselen); strbuf_setlen(template_path, template_baselen);
if (de->d_name[0] == '.') if (de->d_name[0] == '.')
continue; continue;
strbuf_addstr(path, de->d_name); strbuf_addstr(path, de->d_name);
strbuf_addstr(template, de->d_name); strbuf_addstr(template_path, de->d_name);
if (lstat(path->buf, &st_git)) { if (lstat(path->buf, &st_git)) {
if (errno != ENOENT) if (errno != ENOENT)
die_errno(_("cannot stat '%s'"), path->buf); die_errno(_("cannot stat '%s'"), path->buf);
@ -57,36 +57,36 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template,
else else
exists = 1; exists = 1;
if (lstat(template->buf, &st_template)) if (lstat(template_path->buf, &st_template))
die_errno(_("cannot stat template '%s'"), template->buf); die_errno(_("cannot stat template '%s'"), template_path->buf);
if (S_ISDIR(st_template.st_mode)) { if (S_ISDIR(st_template.st_mode)) {
DIR *subdir = opendir(template->buf); DIR *subdir = opendir(template_path->buf);
if (!subdir) if (!subdir)
die_errno(_("cannot opendir '%s'"), template->buf); die_errno(_("cannot opendir '%s'"), template_path->buf);
strbuf_addch(path, '/'); strbuf_addch(path, '/');
strbuf_addch(template, '/'); strbuf_addch(template_path, '/');
copy_templates_1(path, template, subdir); copy_templates_1(path, template_path, 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)) {
struct strbuf lnk = STRBUF_INIT; struct strbuf lnk = STRBUF_INIT;
if (strbuf_readlink(&lnk, template->buf, 0) < 0) if (strbuf_readlink(&lnk, template_path->buf, 0) < 0)
die_errno(_("cannot readlink '%s'"), template->buf); die_errno(_("cannot readlink '%s'"), template_path->buf);
if (symlink(lnk.buf, path->buf)) if (symlink(lnk.buf, path->buf))
die_errno(_("cannot symlink '%s' '%s'"), die_errno(_("cannot symlink '%s' '%s'"),
lnk.buf, path->buf); lnk.buf, path->buf);
strbuf_release(&lnk); strbuf_release(&lnk);
} }
else if (S_ISREG(st_template.st_mode)) { else if (S_ISREG(st_template.st_mode)) {
if (copy_file(path->buf, template->buf, st_template.st_mode)) if (copy_file(path->buf, template_path->buf, st_template.st_mode))
die_errno(_("cannot copy '%s' to '%s'"), die_errno(_("cannot copy '%s' to '%s'"),
template->buf, path->buf); template_path->buf, path->buf);
} }
else else
error(_("ignoring template %s"), template->buf); error(_("ignoring template %s"), template_path->buf);
} }
} }

Просмотреть файл

@ -521,7 +521,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
if (desc && desc->obj && desc->obj->type == OBJ_TAG) { if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
strbuf_addf(msg, "%s\t\t%s '%s'\n", strbuf_addf(msg, "%s\t\t%s '%s'\n",
oid_to_hex(&desc->obj->oid), oid_to_hex(&desc->obj->oid),
typename(desc->obj->type), type_name(desc->obj->type),
remote); remote);
goto cleanup; goto cleanup;
} }

Просмотреть файл

@ -112,7 +112,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
mode_type = object_type(mode); mode_type = object_type(mode);
if (mode_type != type_from_string(ptr)) { if (mode_type != type_from_string(ptr)) {
die("entry '%s' object type (%s) doesn't match mode type (%s)", die("entry '%s' object type (%s) doesn't match mode type (%s)",
path, ptr, typename(mode_type)); path, ptr, type_name(mode_type));
} }
/* Check the type of object identified by sha1 */ /* Check the type of object identified by sha1 */
@ -131,7 +131,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
* because the new tree entry will never be correct. * because the new tree entry will never be correct.
*/ */
die("entry '%s' object %s is a %s but specified type was (%s)", die("entry '%s' object %s is a %s but specified type was (%s)",
path, sha1_to_hex(sha1), typename(obj_type), typename(mode_type)); path, sha1_to_hex(sha1), type_name(obj_type), type_name(mode_type));
} }
} }

Просмотреть файл

@ -1379,10 +1379,10 @@ static void cleanup_preferred_base(void)
it = pbase_tree; it = pbase_tree;
pbase_tree = NULL; pbase_tree = NULL;
while (it) { while (it) {
struct pbase_tree *this = it; struct pbase_tree *tmp = it;
it = this->next; it = tmp->next;
free(this->pcache.tree_data); free(tmp->pcache.tree_data);
free(this); free(tmp);
} }
for (i = 0; i < ARRAY_SIZE(pbase_tree_cache); i++) { for (i = 0; i < ARRAY_SIZE(pbase_tree_cache); i++) {

Просмотреть файл

@ -48,17 +48,17 @@ static inline void llist_item_put(struct llist_item *item)
static inline struct llist_item *llist_item_get(void) static inline struct llist_item *llist_item_get(void)
{ {
struct llist_item *new; struct llist_item *new_item;
if ( free_nodes ) { if ( free_nodes ) {
new = free_nodes; new_item = free_nodes;
free_nodes = free_nodes->next; free_nodes = free_nodes->next;
} else { } else {
int i = 1; int i = 1;
ALLOC_ARRAY(new, BLKSIZE); ALLOC_ARRAY(new_item, BLKSIZE);
for (; i < BLKSIZE; i++) for (; i < BLKSIZE; i++)
llist_item_put(&new[i]); llist_item_put(&new_item[i]);
} }
return new; return new_item;
} }
static void llist_free(struct llist *list) static void llist_free(struct llist *list)
@ -80,26 +80,26 @@ static inline void llist_init(struct llist **list)
static struct llist * llist_copy(struct llist *list) static struct llist * llist_copy(struct llist *list)
{ {
struct llist *ret; struct llist *ret;
struct llist_item *new, *old, *prev; struct llist_item *new_item, *old_item, *prev;
llist_init(&ret); llist_init(&ret);
if ((ret->size = list->size) == 0) if ((ret->size = list->size) == 0)
return ret; return ret;
new = ret->front = llist_item_get(); new_item = ret->front = llist_item_get();
new->sha1 = list->front->sha1; new_item->sha1 = list->front->sha1;
old = list->front->next; old_item = list->front->next;
while (old) { while (old_item) {
prev = new; prev = new_item;
new = llist_item_get(); new_item = llist_item_get();
prev->next = new; prev->next = new_item;
new->sha1 = old->sha1; new_item->sha1 = old_item->sha1;
old = old->next; old_item = old_item->next;
} }
new->next = NULL; new_item->next = NULL;
ret->back = new; ret->back = new_item;
return ret; return ret;
} }
@ -108,24 +108,24 @@ static inline struct llist_item *llist_insert(struct llist *list,
struct llist_item *after, struct llist_item *after,
const unsigned char *sha1) const unsigned char *sha1)
{ {
struct llist_item *new = llist_item_get(); struct llist_item *new_item = llist_item_get();
new->sha1 = sha1; new_item->sha1 = sha1;
new->next = NULL; new_item->next = NULL;
if (after != NULL) { if (after != NULL) {
new->next = after->next; new_item->next = after->next;
after->next = new; after->next = new_item;
if (after == list->back) if (after == list->back)
list->back = new; list->back = new_item;
} else {/* insert in front */ } else {/* insert in front */
if (list->size == 0) if (list->size == 0)
list->back = new; list->back = new_item;
else else
new->next = list->front; new_item->next = list->front;
list->front = new; list->front = new_item;
} }
list->size++; list->size++;
return new; return new_item;
} }
static inline struct llist_item *llist_insert_back(struct llist *list, static inline struct llist_item *llist_insert_back(struct llist *list,

Просмотреть файл

@ -52,7 +52,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (show_only || verbose) { if (show_only || verbose) {
enum object_type type = sha1_object_info(oid->hash, NULL); enum object_type type = sha1_object_info(oid->hash, NULL);
printf("%s %s\n", oid_to_hex(oid), printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? typename(type) : "unknown"); (type > 0) ? type_name(type) : "unknown");
} }
if (!show_only) if (!show_only)
unlink_or_warn(fullpath); unlink_or_warn(fullpath);

Просмотреть файл

@ -289,20 +289,20 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
struct expire_reflog_policy_cb *cb = cb_data; struct expire_reflog_policy_cb *cb = cb_data;
struct commit *old, *new; struct commit *old_commit, *new_commit;
if (timestamp < cb->cmd.expire_total) if (timestamp < cb->cmd.expire_total)
return 1; return 1;
old = new = NULL; old_commit = new_commit = NULL;
if (cb->cmd.stalefix && if (cb->cmd.stalefix &&
(!keep_entry(&old, ooid) || !keep_entry(&new, noid))) (!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
return 1; return 1;
if (timestamp < cb->cmd.expire_unreachable) { if (timestamp < cb->cmd.expire_unreachable) {
if (cb->unreachable_expire_kind == UE_ALWAYS) if (cb->unreachable_expire_kind == UE_ALWAYS)
return 1; return 1;
if (unreachable(cb, old, ooid) || unreachable(cb, new, noid)) if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid))
return 1; return 1;
} }

Просмотреть файл

@ -322,7 +322,7 @@ static void read_branches(void)
struct ref_states { struct ref_states {
struct remote *remote; struct remote *remote;
struct string_list new, stale, tracked, heads, push; struct string_list new_refs, stale, tracked, heads, push;
int queried; int queried;
}; };
@ -337,12 +337,12 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
die(_("Could not get fetch map for refspec %s"), die(_("Could not get fetch map for refspec %s"),
states->remote->fetch_refspec[i]); states->remote->fetch_refspec[i]);
states->new.strdup_strings = 1; states->new_refs.strdup_strings = 1;
states->tracked.strdup_strings = 1; states->tracked.strdup_strings = 1;
states->stale.strdup_strings = 1; states->stale.strdup_strings = 1;
for (ref = fetch_map; ref; ref = ref->next) { for (ref = fetch_map; ref; ref = ref->next) {
if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
string_list_append(&states->new, abbrev_branch(ref->name)); string_list_append(&states->new_refs, abbrev_branch(ref->name));
else else
string_list_append(&states->tracked, abbrev_branch(ref->name)); string_list_append(&states->tracked, abbrev_branch(ref->name));
} }
@ -356,7 +356,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
free_refs(stale_refs); free_refs(stale_refs);
free_refs(fetch_map); free_refs(fetch_map);
string_list_sort(&states->new); string_list_sort(&states->new_refs);
string_list_sort(&states->tracked); string_list_sort(&states->tracked);
string_list_sort(&states->stale); string_list_sort(&states->stale);
@ -546,8 +546,8 @@ static int add_branch_for_removal(const char *refname,
} }
struct rename_info { struct rename_info {
const char *old; const char *old_name;
const char *new; const char *new_name;
struct string_list *remote_branches; struct string_list *remote_branches;
}; };
@ -560,7 +560,7 @@ static int read_remote_branches(const char *refname,
int flag; int flag;
const char *symref; const char *symref;
strbuf_addf(&buf, "refs/remotes/%s/", rename->old); strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
if (starts_with(refname, buf.buf)) { if (starts_with(refname, buf.buf)) {
item = string_list_append(rename->remote_branches, xstrdup(refname)); item = string_list_append(rename->remote_branches, xstrdup(refname));
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING, symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
@ -615,36 +615,36 @@ static int mv(int argc, const char **argv)
if (argc != 3) if (argc != 3)
usage_with_options(builtin_remote_rename_usage, options); usage_with_options(builtin_remote_rename_usage, options);
rename.old = argv[1]; rename.old_name = argv[1];
rename.new = argv[2]; rename.new_name = argv[2];
rename.remote_branches = &remote_branches; rename.remote_branches = &remote_branches;
oldremote = remote_get(rename.old); oldremote = remote_get(rename.old_name);
if (!remote_is_configured(oldremote, 1)) if (!remote_is_configured(oldremote, 1))
die(_("No such remote: %s"), rename.old); die(_("No such remote: %s"), rename.old_name);
if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG) if (!strcmp(rename.old_name, rename.new_name) && oldremote->origin != REMOTE_CONFIG)
return migrate_file(oldremote); return migrate_file(oldremote);
newremote = remote_get(rename.new); newremote = remote_get(rename.new_name);
if (remote_is_configured(newremote, 1)) if (remote_is_configured(newremote, 1))
die(_("remote %s already exists."), rename.new); die(_("remote %s already exists."), rename.new_name);
strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new); strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name);
if (!valid_fetch_refspec(buf.buf)) if (!valid_fetch_refspec(buf.buf))
die(_("'%s' is not a valid remote name"), rename.new); die(_("'%s' is not a valid remote name"), rename.new_name);
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s", rename.old); strbuf_addf(&buf, "remote.%s", rename.old_name);
strbuf_addf(&buf2, "remote.%s", rename.new); strbuf_addf(&buf2, "remote.%s", rename.new_name);
if (git_config_rename_section(buf.buf, buf2.buf) < 1) if (git_config_rename_section(buf.buf, buf2.buf) < 1)
return error(_("Could not rename config section '%s' to '%s'"), return error(_("Could not rename config section '%s' to '%s'"),
buf.buf, buf2.buf); buf.buf, buf2.buf);
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", rename.new); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
git_config_set_multivar(buf.buf, NULL, NULL, 1); git_config_set_multivar(buf.buf, NULL, NULL, 1);
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
for (i = 0; i < oldremote->fetch_refspec_nr; i++) { for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
char *ptr; char *ptr;
@ -655,8 +655,8 @@ static int mv(int argc, const char **argv)
refspec_updated = 1; refspec_updated = 1;
strbuf_splice(&buf2, strbuf_splice(&buf2,
ptr-buf2.buf + strlen(":refs/remotes/"), ptr-buf2.buf + strlen(":refs/remotes/"),
strlen(rename.old), rename.new, strlen(rename.old_name), rename.new_name,
strlen(rename.new)); strlen(rename.new_name));
} else } else
warning(_("Not updating non-default fetch refspec\n" warning(_("Not updating non-default fetch refspec\n"
"\t%s\n" "\t%s\n"
@ -670,10 +670,10 @@ static int mv(int argc, const char **argv)
for (i = 0; i < branch_list.nr; i++) { for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *item = branch_list.items + i; struct string_list_item *item = branch_list.items + i;
struct branch_info *info = item->util; struct branch_info *info = item->util;
if (info->remote_name && !strcmp(info->remote_name, rename.old)) { if (info->remote_name && !strcmp(info->remote_name, rename.old_name)) {
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addf(&buf, "branch.%s.remote", item->string); strbuf_addf(&buf, "branch.%s.remote", item->string);
git_config_set(buf.buf, rename.new); git_config_set(buf.buf, rename.new_name);
} }
} }
@ -703,8 +703,8 @@ static int mv(int argc, const char **argv)
continue; continue;
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addstr(&buf, item->string); strbuf_addstr(&buf, item->string);
strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name),
rename.new, strlen(rename.new)); rename.new_name, strlen(rename.new_name));
strbuf_reset(&buf2); strbuf_reset(&buf2);
strbuf_addf(&buf2, "remote: renamed %s to %s", strbuf_addf(&buf2, "remote: renamed %s to %s",
item->string, buf.buf); item->string, buf.buf);
@ -718,12 +718,12 @@ static int mv(int argc, const char **argv)
continue; continue;
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addstr(&buf, item->string); strbuf_addstr(&buf, item->string);
strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name),
rename.new, strlen(rename.new)); rename.new_name, strlen(rename.new_name));
strbuf_reset(&buf2); strbuf_reset(&buf2);
strbuf_addstr(&buf2, item->util); strbuf_addstr(&buf2, item->util);
strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old), strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old_name),
rename.new, strlen(rename.new)); rename.new_name, strlen(rename.new_name));
strbuf_reset(&buf3); strbuf_reset(&buf3);
strbuf_addf(&buf3, "remote: renamed %s to %s", strbuf_addf(&buf3, "remote: renamed %s to %s",
item->string, buf.buf); item->string, buf.buf);
@ -822,7 +822,7 @@ static void clear_push_info(void *util, const char *string)
static void free_remote_ref_states(struct ref_states *states) static void free_remote_ref_states(struct ref_states *states)
{ {
string_list_clear(&states->new, 0); string_list_clear(&states->new_refs, 0);
string_list_clear(&states->stale, 1); string_list_clear(&states->stale, 1);
string_list_clear(&states->tracked, 0); string_list_clear(&states->tracked, 0);
string_list_clear(&states->heads, 0); string_list_clear(&states->heads, 0);
@ -907,7 +907,7 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)
if (states->queried) { if (states->queried) {
const char *fmt = "%s"; const char *fmt = "%s";
const char *arg = ""; const char *arg = "";
if (string_list_has_string(&states->new, name)) { if (string_list_has_string(&states->new_refs, name)) {
fmt = _(" new (next fetch will store in remotes/%s)"); fmt = _(" new (next fetch will store in remotes/%s)");
arg = states->remote->name; arg = states->remote->name;
} else if (string_list_has_string(&states->tracked, name)) } else if (string_list_has_string(&states->tracked, name))
@ -1176,7 +1176,7 @@ static int show(int argc, const char **argv)
/* remote branch info */ /* remote branch info */
info.width = 0; info.width = 0;
for_each_string_list(&states.new, add_remote_to_show_info, &info); for_each_string_list(&states.new_refs, add_remote_to_show_info, &info);
for_each_string_list(&states.tracked, add_remote_to_show_info, &info); for_each_string_list(&states.tracked, add_remote_to_show_info, &info);
for_each_string_list(&states.stale, add_remote_to_show_info, &info); for_each_string_list(&states.stale, add_remote_to_show_info, &info);
if (info.list->nr) if (info.list->nr)

Просмотреть файл

@ -56,8 +56,8 @@ static int show_reference(const char *refname, const struct object_id *oid,
obj_type = sha1_object_info(object.hash, NULL); obj_type = sha1_object_info(object.hash, NULL);
repl_type = sha1_object_info(oid->hash, NULL); repl_type = sha1_object_info(oid->hash, NULL);
printf("%s (%s) -> %s (%s)\n", refname, typename(obj_type), printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), typename(repl_type)); oid_to_hex(oid), type_name(repl_type));
} }
} }
@ -168,8 +168,8 @@ static int replace_object_oid(const char *object_ref,
die("Objects must be of the same type.\n" die("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n" "'%s' points to a replaced object of type '%s'\n"
"while '%s' points to a replacement object of type '%s'.", "while '%s' points to a replacement object of type '%s'.",
object_ref, typename(obj_type), object_ref, type_name(obj_type),
replace_ref, typename(repl_type)); replace_ref, type_name(repl_type));
check_ref_valid(object, &prev, &ref, force); check_ref_valid(object, &prev, &ref, force);
@ -215,7 +215,7 @@ static void export_object(const struct object_id *oid, enum object_type type,
argv_array_push(&cmd.args, "--no-replace-objects"); argv_array_push(&cmd.args, "--no-replace-objects");
argv_array_push(&cmd.args, "cat-file"); argv_array_push(&cmd.args, "cat-file");
if (raw) if (raw)
argv_array_push(&cmd.args, typename(type)); argv_array_push(&cmd.args, type_name(type));
else else
argv_array_push(&cmd.args, "-p"); argv_array_push(&cmd.args, "-p");
argv_array_push(&cmd.args, oid_to_hex(oid)); argv_array_push(&cmd.args, oid_to_hex(oid));
@ -284,30 +284,30 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
{ {
char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
enum object_type type; enum object_type type;
struct object_id old, new, prev; struct object_id old_oid, new_oid, prev;
struct strbuf ref = STRBUF_INIT; struct strbuf ref = STRBUF_INIT;
if (get_oid(object_ref, &old) < 0) if (get_oid(object_ref, &old_oid) < 0)
die("Not a valid object name: '%s'", object_ref); die("Not a valid object name: '%s'", object_ref);
type = sha1_object_info(old.hash, NULL); type = sha1_object_info(old_oid.hash, NULL);
if (type < 0) if (type < 0)
die("unable to get object type for %s", oid_to_hex(&old)); die("unable to get object type for %s", oid_to_hex(&old_oid));
check_ref_valid(&old, &prev, &ref, force); check_ref_valid(&old_oid, &prev, &ref, force);
strbuf_release(&ref); strbuf_release(&ref);
export_object(&old, type, raw, tmpfile); export_object(&old_oid, type, raw, tmpfile);
if (launch_editor(tmpfile, NULL, NULL) < 0) if (launch_editor(tmpfile, NULL, NULL) < 0)
die("editing object file failed"); die("editing object file failed");
import_object(&new, type, raw, tmpfile); import_object(&new_oid, type, raw, tmpfile);
free(tmpfile); free(tmpfile);
if (!oidcmp(&old, &new)) if (!oidcmp(&old_oid, &new_oid))
return error("new object is the same as the old one: '%s'", oid_to_hex(&old)); return error("new object is the same as the old one: '%s'", oid_to_hex(&old_oid));
return replace_object_oid(object_ref, &old, "replacement", &new, force); return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force);
} }
static void replace_parents(struct strbuf *buf, int argc, const char **argv) static void replace_parents(struct strbuf *buf, int argc, const char **argv)
@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
struct tag *tag; struct tag *tag;
int i; int i;
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &tag_oid); hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &tag_oid);
tag = lookup_tag(&tag_oid); tag = lookup_tag(&tag_oid);
if (!tag) if (!tag)
die(_("bad mergetag in commit '%s'"), ref); die(_("bad mergetag in commit '%s'"), ref);
@ -386,16 +386,16 @@ static void check_mergetags(struct commit *commit, int argc, const char **argv)
static int create_graft(int argc, const char **argv, int force) static int create_graft(int argc, const char **argv, int force)
{ {
struct object_id old, new; struct object_id old_oid, new_oid;
const char *old_ref = argv[0]; const char *old_ref = argv[0];
struct commit *commit; struct commit *commit;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *buffer; const char *buffer;
unsigned long size; unsigned long size;
if (get_oid(old_ref, &old) < 0) if (get_oid(old_ref, &old_oid) < 0)
die(_("Not a valid object name: '%s'"), old_ref); die(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_or_die(&old, old_ref); commit = lookup_commit_or_die(&old_oid, old_ref);
buffer = get_commit_buffer(commit, &size); buffer = get_commit_buffer(commit, &size);
strbuf_add(&buf, buffer, size); strbuf_add(&buf, buffer, size);
@ -410,15 +410,15 @@ static int create_graft(int argc, const char **argv, int force)
check_mergetags(commit, argc, argv); check_mergetags(commit, argc, argv);
if (write_object_file(buf.buf, buf.len, commit_type, &new)) if (write_object_file(buf.buf, buf.len, commit_type, &new_oid))
die(_("could not write replacement commit for: '%s'"), old_ref); die(_("could not write replacement commit for: '%s'"), old_ref);
strbuf_release(&buf); strbuf_release(&buf);
if (!oidcmp(&old, &new)) if (!oidcmp(&old_oid, &new_oid))
return error("new commit is the same as the old one: '%s'", oid_to_hex(&old)); return error("new commit is the same as the old one: '%s'", oid_to_hex(&old_oid));
return replace_object_oid(old_ref, &old, "replacement", &new, force); return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force);
} }
int cmd_replace(int argc, const char **argv, const char *prefix) int cmd_replace(int argc, const char **argv, const char *prefix)

Просмотреть файл

@ -243,28 +243,28 @@ static int show_file(const char *arg, int output_prefix)
static int try_difference(const char *arg) static int try_difference(const char *arg)
{ {
char *dotdot; char *dotdot;
struct object_id oid; struct object_id start_oid;
struct object_id end; struct object_id end_oid;
const char *next; const char *end;
const char *this; const char *start;
int symmetric; int symmetric;
static const char head_by_default[] = "HEAD"; static const char head_by_default[] = "HEAD";
if (!(dotdot = strstr(arg, ".."))) if (!(dotdot = strstr(arg, "..")))
return 0; return 0;
next = dotdot + 2; end = dotdot + 2;
this = arg; start = arg;
symmetric = (*next == '.'); symmetric = (*end == '.');
*dotdot = 0; *dotdot = 0;
next += symmetric; end += symmetric;
if (!*next) if (!*end)
next = head_by_default; end = head_by_default;
if (dotdot == arg) if (dotdot == arg)
this = head_by_default; start = head_by_default;
if (this == head_by_default && next == head_by_default && if (start == head_by_default && end == head_by_default &&
!symmetric) { !symmetric) {
/* /*
* Just ".."? That is not a range but the * Just ".."? That is not a range but the
@ -274,14 +274,14 @@ static int try_difference(const char *arg)
return 0; return 0;
} }
if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) { if (!get_oid_committish(start, &start_oid) && !get_oid_committish(end, &end_oid)) {
show_rev(NORMAL, &end, next); show_rev(NORMAL, &end_oid, end);
show_rev(symmetric ? NORMAL : REVERSED, &oid, this); show_rev(symmetric ? NORMAL : REVERSED, &start_oid, start);
if (symmetric) { if (symmetric) {
struct commit_list *exclude; struct commit_list *exclude;
struct commit *a, *b; struct commit *a, *b;
a = lookup_commit_reference(&oid); a = lookup_commit_reference(&start_oid);
b = lookup_commit_reference(&end); b = lookup_commit_reference(&end_oid);
exclude = get_merge_bases(a, b); exclude = get_merge_bases(a, b);
while (exclude) { while (exclude) {
struct commit *commit = pop_commit(&exclude); struct commit *commit = pop_commit(&exclude);

Просмотреть файл

@ -221,7 +221,7 @@ static void create_tag(const struct object_id *object, const char *tag,
"tag %s\n" "tag %s\n"
"tagger %s\n\n", "tagger %s\n\n",
oid_to_hex(object), oid_to_hex(object),
typename(type), type_name(type),
tag, tag,
git_committer_info(IDENT_STRICT)); git_committer_info(IDENT_STRICT));

Просмотреть файл

@ -173,7 +173,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
struct object_id oid; struct object_id oid;
if (write_object_file(obj_buf->buffer, obj_buf->size, if (write_object_file(obj_buf->buffer, obj_buf->size,
typename(obj->type), &oid) < 0) type_name(obj->type), &oid) < 0)
die("failed to write object %s", oid_to_hex(&obj->oid)); die("failed to write object %s", oid_to_hex(&obj->oid));
obj->flags |= FLAG_WRITTEN; obj->flags |= FLAG_WRITTEN;
} }
@ -238,7 +238,7 @@ static void write_object(unsigned nr, enum object_type type,
void *buf, unsigned long size) void *buf, unsigned long size)
{ {
if (!strict) { if (!strict) {
if (write_object_file(buf, size, typename(type), if (write_object_file(buf, size, type_name(type),
&obj_list[nr].oid) < 0) &obj_list[nr].oid) < 0)
die("failed to write object"); die("failed to write object");
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
@ -246,7 +246,7 @@ static void write_object(unsigned nr, enum object_type type,
obj_list[nr].obj = NULL; obj_list[nr].obj = NULL;
} else if (type == OBJ_BLOB) { } else if (type == OBJ_BLOB) {
struct blob *blob; struct blob *blob;
if (write_object_file(buf, size, typename(type), if (write_object_file(buf, size, type_name(type),
&obj_list[nr].oid) < 0) &obj_list[nr].oid) < 0)
die("failed to write object"); die("failed to write object");
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
@ -261,12 +261,12 @@ static void write_object(unsigned nr, enum object_type type,
} else { } else {
struct object *obj; struct object *obj;
int eaten; int eaten;
hash_object_file(buf, size, typename(type), &obj_list[nr].oid); hash_object_file(buf, size, type_name(type), &obj_list[nr].oid);
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf, obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
&eaten); &eaten);
if (!obj) if (!obj)
die("invalid %s", typename(type)); die("invalid %s", type_name(type));
add_object_buffer(obj, buf, size); add_object_buffer(obj, buf, size);
obj->flags |= FLAG_OPEN; obj->flags |= FLAG_OPEN;
obj_list[nr].obj = obj; obj_list[nr].obj = obj;

Просмотреть файл

@ -49,7 +49,7 @@ static int verify_commit(const char *name, unsigned flags)
return error("%s: unable to read file.", name); return error("%s: unable to read file.", name);
if (type != OBJ_COMMIT) if (type != OBJ_COMMIT)
return error("%s: cannot verify a non-commit object of type %s.", return error("%s: cannot verify a non-commit object of type %s.",
name, typename(type)); name, type_name(type));
ret = run_gpg_verify(&oid, buf, size, flags); ret = run_gpg_verify(&oid, buf, size, flags);

Просмотреть файл

@ -203,7 +203,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
return error("cannot find the current offset"); return error("cannot find the current offset");
header_len = xsnprintf((char *)obuf, sizeof(obuf), "%s %" PRIuMAX, header_len = xsnprintf((char *)obuf, sizeof(obuf), "%s %" PRIuMAX,
typename(type), (uintmax_t)size) + 1; type_name(type), (uintmax_t)size) + 1;
the_hash_algo->init_fn(&ctx); the_hash_algo->init_fn(&ctx);
the_hash_algo->update_fn(&ctx, obuf, header_len); the_hash_algo->update_fn(&ctx, obuf, header_len);

Просмотреть файл

@ -1661,7 +1661,7 @@ struct pack_entry {
* usual "XXXXXX" trailer, and the resulting filename is written into the * usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor. * "template" buffer. Returns the open descriptor.
*/ */
extern int odb_mkstemp(struct strbuf *template, const char *pattern); extern int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
/* /*
* Create a pack .keep file named "name" (which should generally be the output * Create a pack .keep file named "name" (which should generally be the output
@ -1732,7 +1732,7 @@ struct object_info {
unsigned long *sizep; unsigned long *sizep;
off_t *disk_sizep; off_t *disk_sizep;
unsigned char *delta_base_sha1; unsigned char *delta_base_sha1;
struct strbuf *typename; struct strbuf *type_name;
void **contentp; void **contentp;
/* Response */ /* Response */

Просмотреть файл

@ -162,7 +162,7 @@ enum coalesce_direction { MATCH, BASE, NEW };
/* Coalesce new lines into base by finding LCS */ /* Coalesce new lines into base by finding LCS */
static struct lline *coalesce_lines(struct lline *base, int *lenbase, static struct lline *coalesce_lines(struct lline *base, int *lenbase,
struct lline *new, int lennew, struct lline *newline, int lennew,
unsigned long parent, long flags) unsigned long parent, long flags)
{ {
int **lcs; int **lcs;
@ -170,12 +170,12 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
struct lline *baseend, *newend = NULL; struct lline *baseend, *newend = NULL;
int i, j, origbaselen = *lenbase; int i, j, origbaselen = *lenbase;
if (new == NULL) if (newline == NULL)
return base; return base;
if (base == NULL) { if (base == NULL) {
*lenbase = lennew; *lenbase = lennew;
return new; return newline;
} }
/* /*
@ -200,7 +200,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
directions[0][j] = NEW; directions[0][j] = NEW;
for (i = 1, baseend = base; i < origbaselen + 1; i++) { for (i = 1, baseend = base; i < origbaselen + 1; i++) {
for (j = 1, newend = new; j < lennew + 1; j++) { for (j = 1, newend = newline; j < lennew + 1; j++) {
if (match_string_spaces(baseend->line, baseend->len, if (match_string_spaces(baseend->line, baseend->len,
newend->line, newend->len, flags)) { newend->line, newend->len, flags)) {
lcs[i][j] = lcs[i - 1][j - 1] + 1; lcs[i][j] = lcs[i - 1][j - 1] + 1;
@ -241,7 +241,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
if (lline->prev) if (lline->prev)
lline->prev->next = lline->next; lline->prev->next = lline->next;
else else
new = lline->next; newline = lline->next;
if (lline->next) if (lline->next)
lline->next->prev = lline->prev; lline->next->prev = lline->prev;
@ -270,7 +270,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
} }
} }
newend = new; newend = newline;
while (newend) { while (newend) {
struct lline *lline = newend; struct lline *lline = newend;
newend = newend->next; newend = newend->next;

Просмотреть файл

@ -272,7 +272,7 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
oid_to_hex(&commit->object.oid)); oid_to_hex(&commit->object.oid));
if (type != OBJ_COMMIT) if (type != OBJ_COMMIT)
die("expected commit for %s, got %s", die("expected commit for %s, got %s",
oid_to_hex(&commit->object.oid), typename(type)); oid_to_hex(&commit->object.oid), type_name(type));
if (sizep) if (sizep)
*sizep = size; *sizep = size;
} }
@ -859,19 +859,19 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
commit_list_insert(in->item, &ret); commit_list_insert(in->item, &ret);
for (i = in->next; i; i = i->next) { for (i = in->next; i; i = i->next) {
struct commit_list *new = NULL, *end = NULL; struct commit_list *new_commits = NULL, *end = NULL;
for (j = ret; j; j = j->next) { for (j = ret; j; j = j->next) {
struct commit_list *bases; struct commit_list *bases;
bases = get_merge_bases(i->item, j->item); bases = get_merge_bases(i->item, j->item);
if (!new) if (!new_commits)
new = bases; new_commits = bases;
else else
end->next = bases; end->next = bases;
for (k = bases; k; k = k->next) for (k = bases; k; k = k->next)
end = k; end = k;
} }
ret = new; ret = new_commits;
} }
return ret; return ret;
} }
@ -1614,11 +1614,11 @@ struct commit *get_merge_parent(const char *name)
struct commit_list **commit_list_append(struct commit *commit, struct commit_list **commit_list_append(struct commit *commit,
struct commit_list **next) struct commit_list **next)
{ {
struct commit_list *new = xmalloc(sizeof(struct commit_list)); struct commit_list *new_commit = xmalloc(sizeof(struct commit_list));
new->item = commit; new_commit->item = commit;
*next = new; *next = new_commit;
new->next = NULL; new_commit->next = NULL;
return &new->next; return &new_commit->next;
} }
const char *find_commit_header(const char *msg, const char *key, size_t *out_len) const char *find_commit_header(const char *msg, const char *key, size_t *out_len)

Просмотреть файл

@ -15,7 +15,7 @@ static char *get_stdin(void)
static void show_new(enum object_type type, unsigned char *sha1_new) static void show_new(enum object_type type, unsigned char *sha1_new)
{ {
fprintf(stderr, " %s: %s\n", typename(type), fprintf(stderr, " %s: %s\n", type_name(type),
find_unique_abbrev(sha1_new, DEFAULT_ABBREV)); find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
} }

Просмотреть файл

@ -304,7 +304,7 @@ static int get_stat_data(const struct cache_entry *ce,
} }
static void show_new_file(struct rev_info *revs, static void show_new_file(struct rev_info *revs,
const struct cache_entry *new, const struct cache_entry *new_file,
int cached, int match_missing) int cached, int match_missing)
{ {
const struct object_id *oid; const struct object_id *oid;
@ -315,16 +315,16 @@ static void show_new_file(struct rev_info *revs,
* New file in the index: it might actually be different in * New file in the index: it might actually be different in
* the working tree. * the working tree.
*/ */
if (get_stat_data(new, &oid, &mode, cached, match_missing, if (get_stat_data(new_file, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0) &dirty_submodule, &revs->diffopt) < 0)
return; return;
diff_index_show_file(revs, "+", new, oid, !is_null_oid(oid), mode, dirty_submodule); diff_index_show_file(revs, "+", new_file, oid, !is_null_oid(oid), mode, dirty_submodule);
} }
static int show_modified(struct rev_info *revs, static int show_modified(struct rev_info *revs,
const struct cache_entry *old, const struct cache_entry *old_entry,
const struct cache_entry *new, const struct cache_entry *new_entry,
int report_missing, int report_missing,
int cached, int match_missing) int cached, int match_missing)
{ {
@ -332,47 +332,47 @@ static int show_modified(struct rev_info *revs,
const struct object_id *oid; const struct object_id *oid;
unsigned dirty_submodule = 0; unsigned dirty_submodule = 0;
if (get_stat_data(new, &oid, &mode, cached, match_missing, if (get_stat_data(new_entry, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0) { &dirty_submodule, &revs->diffopt) < 0) {
if (report_missing) if (report_missing)
diff_index_show_file(revs, "-", old, diff_index_show_file(revs, "-", old_entry,
&old->oid, 1, old->ce_mode, &old_entry->oid, 1, old_entry->ce_mode,
0); 0);
return -1; return -1;
} }
if (revs->combine_merges && !cached && if (revs->combine_merges && !cached &&
(oidcmp(oid, &old->oid) || oidcmp(&old->oid, &new->oid))) { (oidcmp(oid, &old_entry->oid) || oidcmp(&old_entry->oid, &new_entry->oid))) {
struct combine_diff_path *p; struct combine_diff_path *p;
int pathlen = ce_namelen(new); int pathlen = ce_namelen(new_entry);
p = xmalloc(combine_diff_path_size(2, pathlen)); p = xmalloc(combine_diff_path_size(2, pathlen));
p->path = (char *) &p->parent[2]; p->path = (char *) &p->parent[2];
p->next = NULL; p->next = NULL;
memcpy(p->path, new->name, pathlen); memcpy(p->path, new_entry->name, pathlen);
p->path[pathlen] = 0; p->path[pathlen] = 0;
p->mode = mode; p->mode = mode;
oidclr(&p->oid); oidclr(&p->oid);
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent)); memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED; p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new->ce_mode; p->parent[0].mode = new_entry->ce_mode;
oidcpy(&p->parent[0].oid, &new->oid); oidcpy(&p->parent[0].oid, &new_entry->oid);
p->parent[1].status = DIFF_STATUS_MODIFIED; p->parent[1].status = DIFF_STATUS_MODIFIED;
p->parent[1].mode = old->ce_mode; p->parent[1].mode = old_entry->ce_mode;
oidcpy(&p->parent[1].oid, &old->oid); oidcpy(&p->parent[1].oid, &old_entry->oid);
show_combined_diff(p, 2, revs->dense_combined_merges, revs); show_combined_diff(p, 2, revs->dense_combined_merges, revs);
free(p); free(p);
return 0; return 0;
} }
oldmode = old->ce_mode; oldmode = old_entry->ce_mode;
if (mode == oldmode && !oidcmp(oid, &old->oid) && !dirty_submodule && if (mode == oldmode && !oidcmp(oid, &old_entry->oid) && !dirty_submodule &&
!revs->diffopt.flags.find_copies_harder) !revs->diffopt.flags.find_copies_harder)
return 0; return 0;
diff_change(&revs->diffopt, oldmode, mode, diff_change(&revs->diffopt, oldmode, mode,
&old->oid, oid, 1, !is_null_oid(oid), &old_entry->oid, oid, 1, !is_null_oid(oid),
old->name, 0, dirty_submodule); old_entry->name, 0, dirty_submodule);
return 0; return 0;
} }

70
diff.c
Просмотреть файл

@ -1504,7 +1504,7 @@ struct diff_words_style_elem {
struct diff_words_style { struct diff_words_style {
enum diff_words_type type; enum diff_words_type type;
struct diff_words_style_elem new, old, ctx; struct diff_words_style_elem new_word, old_word, ctx;
const char *newline; const char *newline;
}; };
@ -1655,12 +1655,12 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
} }
if (minus_begin != minus_end) { if (minus_begin != minus_end) {
fn_out_diff_words_write_helper(diff_words->opt, fn_out_diff_words_write_helper(diff_words->opt,
&style->old, style->newline, &style->old_word, style->newline,
minus_end - minus_begin, minus_begin); minus_end - minus_begin, minus_begin);
} }
if (plus_begin != plus_end) { if (plus_begin != plus_end) {
fn_out_diff_words_write_helper(diff_words->opt, fn_out_diff_words_write_helper(diff_words->opt,
&style->new, style->newline, &style->new_word, style->newline,
plus_end - plus_begin, plus_begin); plus_end - plus_begin, plus_begin);
} }
@ -1758,7 +1758,7 @@ static void diff_words_show(struct diff_words_data *diff_words)
emit_diff_symbol(diff_words->opt, DIFF_SYMBOL_WORD_DIFF, emit_diff_symbol(diff_words->opt, DIFF_SYMBOL_WORD_DIFF,
line_prefix, strlen(line_prefix), 0); line_prefix, strlen(line_prefix), 0);
fn_out_diff_words_write_helper(diff_words->opt, fn_out_diff_words_write_helper(diff_words->opt,
&style->old, style->newline, &style->old_word, style->newline,
diff_words->minus.text.size, diff_words->minus.text.size,
diff_words->minus.text.ptr); diff_words->minus.text.ptr);
diff_words->minus.text.size = 0; diff_words->minus.text.size = 0;
@ -1883,8 +1883,8 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
} }
if (want_color(o->use_color)) { if (want_color(o->use_color)) {
struct diff_words_style *st = ecbdata->diff_words->style; struct diff_words_style *st = ecbdata->diff_words->style;
st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD); st->old_word.color = diff_get_color_opt(o, DIFF_FILE_OLD);
st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW); st->new_word.color = diff_get_color_opt(o, DIFF_FILE_NEW);
st->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT); st->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT);
} }
} }
@ -2047,8 +2047,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
static char *pprint_rename(const char *a, const char *b) static char *pprint_rename(const char *a, const char *b)
{ {
const char *old = a; const char *old_name = a;
const char *new = b; const char *new_name = b;
struct strbuf name = STRBUF_INIT; struct strbuf name = STRBUF_INIT;
int pfx_length, sfx_length; int pfx_length, sfx_length;
int pfx_adjust_for_slash; int pfx_adjust_for_slash;
@ -2067,16 +2067,16 @@ static char *pprint_rename(const char *a, const char *b)
/* Find common prefix */ /* Find common prefix */
pfx_length = 0; pfx_length = 0;
while (*old && *new && *old == *new) { while (*old_name && *new_name && *old_name == *new_name) {
if (*old == '/') if (*old_name == '/')
pfx_length = old - a + 1; pfx_length = old_name - a + 1;
old++; old_name++;
new++; new_name++;
} }
/* Find common suffix */ /* Find common suffix */
old = a + len_a; old_name = a + len_a;
new = b + len_b; new_name = b + len_b;
sfx_length = 0; sfx_length = 0;
/* /*
* If there is a common prefix, it must end in a slash. In * If there is a common prefix, it must end in a slash. In
@ -2087,13 +2087,13 @@ static char *pprint_rename(const char *a, const char *b)
* underrun the input strings. * underrun the input strings.
*/ */
pfx_adjust_for_slash = (pfx_length ? 1 : 0); pfx_adjust_for_slash = (pfx_length ? 1 : 0);
while (a + pfx_length - pfx_adjust_for_slash <= old && while (a + pfx_length - pfx_adjust_for_slash <= old_name &&
b + pfx_length - pfx_adjust_for_slash <= new && b + pfx_length - pfx_adjust_for_slash <= new_name &&
*old == *new) { *old_name == *new_name) {
if (*old == '/') if (*old_name == '/')
sfx_length = len_a - (old - a); sfx_length = len_a - (old_name - a);
old--; old_name--;
new--; new_name--;
} }
/* /*
@ -2594,14 +2594,14 @@ struct dirstat_dir {
static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir, static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
unsigned long changed, const char *base, int baselen) unsigned long changed, const char *base, int baselen)
{ {
unsigned long this_dir = 0; unsigned long sum_changes = 0;
unsigned int sources = 0; unsigned int sources = 0;
const char *line_prefix = diff_line_prefix(opt); const char *line_prefix = diff_line_prefix(opt);
while (dir->nr) { while (dir->nr) {
struct dirstat_file *f = dir->files; struct dirstat_file *f = dir->files;
int namelen = strlen(f->name); int namelen = strlen(f->name);
unsigned long this; unsigned long changes;
char *slash; char *slash;
if (namelen < baselen) if (namelen < baselen)
@ -2611,15 +2611,15 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
slash = strchr(f->name + baselen, '/'); slash = strchr(f->name + baselen, '/');
if (slash) { if (slash) {
int newbaselen = slash + 1 - f->name; int newbaselen = slash + 1 - f->name;
this = gather_dirstat(opt, dir, changed, f->name, newbaselen); changes = gather_dirstat(opt, dir, changed, f->name, newbaselen);
sources++; sources++;
} else { } else {
this = f->changed; changes = f->changed;
dir->files++; dir->files++;
dir->nr--; dir->nr--;
sources += 2; sources += 2;
} }
this_dir += this; sum_changes += changes;
} }
/* /*
@ -2629,8 +2629,8 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
* under this directory (sources == 1). * under this directory (sources == 1).
*/ */
if (baselen && sources != 1) { if (baselen && sources != 1) {
if (this_dir) { if (sum_changes) {
int permille = this_dir * 1000 / changed; int permille = sum_changes * 1000 / changed;
if (permille >= dir->permille) { if (permille >= dir->permille) {
fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix, fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
permille / 10, permille % 10, baselen, base); permille / 10, permille % 10, baselen, base);
@ -2639,7 +2639,7 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
} }
} }
} }
return this_dir; return sum_changes;
} }
static int dirstat_compare(const void *_a, const void *_b) static int dirstat_compare(const void *_a, const void *_b)
@ -3660,15 +3660,15 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
int mode) int mode)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct strbuf template = STRBUF_INIT; struct strbuf tempfile = STRBUF_INIT;
char *path_dup = xstrdup(path); char *path_dup = xstrdup(path);
const char *base = basename(path_dup); const char *base = basename(path_dup);
/* Generate "XXXXXX_basename.ext" */ /* Generate "XXXXXX_basename.ext" */
strbuf_addstr(&template, "XXXXXX_"); strbuf_addstr(&tempfile, "XXXXXX_");
strbuf_addstr(&template, base); strbuf_addstr(&tempfile, base);
temp->tempfile = mks_tempfile_ts(template.buf, strlen(base) + 1); temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
if (!temp->tempfile) if (!temp->tempfile)
die_errno("unable to create temp-file"); die_errno("unable to create temp-file");
if (convert_to_working_tree(path, if (convert_to_working_tree(path,
@ -3683,7 +3683,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
oid_to_hex_r(temp->hex, oid); oid_to_hex_r(temp->hex, oid);
xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode); xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);
strbuf_release(&buf); strbuf_release(&buf);
strbuf_release(&template); strbuf_release(&tempfile);
free(path_dup); free(path_dup);
} }

Просмотреть файл

@ -48,16 +48,16 @@ struct spanhash_top {
static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig) static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
{ {
struct spanhash_top *new; struct spanhash_top *new_spanhash;
int i; int i;
int osz = 1 << orig->alloc_log2; int osz = 1 << orig->alloc_log2;
int sz = osz << 1; int sz = osz << 1;
new = xmalloc(st_add(sizeof(*orig), new_spanhash = xmalloc(st_add(sizeof(*orig),
st_mult(sizeof(struct spanhash), sz))); st_mult(sizeof(struct spanhash), sz)));
new->alloc_log2 = orig->alloc_log2 + 1; new_spanhash->alloc_log2 = orig->alloc_log2 + 1;
new->free = INITIAL_FREE(new->alloc_log2); new_spanhash->free = INITIAL_FREE(new_spanhash->alloc_log2);
memset(new->data, 0, sizeof(struct spanhash) * sz); memset(new_spanhash->data, 0, sizeof(struct spanhash) * sz);
for (i = 0; i < osz; i++) { for (i = 0; i < osz; i++) {
struct spanhash *o = &(orig->data[i]); struct spanhash *o = &(orig->data[i]);
int bucket; int bucket;
@ -65,11 +65,11 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
continue; continue;
bucket = o->hashval & (sz - 1); bucket = o->hashval & (sz - 1);
while (1) { while (1) {
struct spanhash *h = &(new->data[bucket++]); struct spanhash *h = &(new_spanhash->data[bucket++]);
if (!h->cnt) { if (!h->cnt) {
h->hashval = o->hashval; h->hashval = o->hashval;
h->cnt = o->cnt; h->cnt = o->cnt;
new->free--; new_spanhash->free--;
break; break;
} }
if (sz <= bucket) if (sz <= bucket)
@ -77,7 +77,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
} }
} }
free(orig); free(orig);
return new; return new_spanhash;
} }
static struct spanhash_top *add_spanhash(struct spanhash_top *top, static struct spanhash_top *add_spanhash(struct spanhash_top *top,

40
entry.c
Просмотреть файл

@ -85,12 +85,12 @@ static int create_file(const char *path, unsigned int mode)
static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size) static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
{ {
enum object_type type; enum object_type type;
void *new = read_sha1_file(ce->oid.hash, &type, size); void *blob_data = read_sha1_file(ce->oid.hash, &type, size);
if (new) { if (blob_data) {
if (type == OBJ_BLOB) if (type == OBJ_BLOB)
return new; return blob_data;
free(new); free(blob_data);
} }
return NULL; return NULL;
} }
@ -256,7 +256,7 @@ static int write_entry(struct cache_entry *ce,
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT; unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
struct delayed_checkout *dco = state->delayed_checkout; struct delayed_checkout *dco = state->delayed_checkout;
int fd, ret, fstat_done = 0; int fd, ret, fstat_done = 0;
char *new; char *new_blob;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
unsigned long size; unsigned long size;
ssize_t wrote; ssize_t wrote;
@ -276,8 +276,8 @@ static int write_entry(struct cache_entry *ce,
switch (ce_mode_s_ifmt) { switch (ce_mode_s_ifmt) {
case S_IFLNK: case S_IFLNK:
new = read_blob_entry(ce, &size); new_blob = read_blob_entry(ce, &size);
if (!new) if (!new_blob)
return error("unable to read sha1 file of %s (%s)", return error("unable to read sha1 file of %s (%s)",
path, oid_to_hex(&ce->oid)); path, oid_to_hex(&ce->oid));
@ -288,8 +288,8 @@ static int write_entry(struct cache_entry *ce,
if (!has_symlinks || to_tempfile) if (!has_symlinks || to_tempfile)
goto write_file_entry; goto write_file_entry;
ret = symlink(new, path); ret = symlink(new_blob, path);
free(new); free(new_blob);
if (ret) if (ret)
return error_errno("unable to create symlink %s", path); return error_errno("unable to create symlink %s", path);
break; break;
@ -300,11 +300,11 @@ static int write_entry(struct cache_entry *ce,
* bother reading it at all. * bother reading it at all.
*/ */
if (dco && dco->state == CE_RETRY) { if (dco && dco->state == CE_RETRY) {
new = NULL; new_blob = NULL;
size = 0; size = 0;
} else { } else {
new = read_blob_entry(ce, &size); new_blob = read_blob_entry(ce, &size);
if (!new) if (!new_blob)
return error("unable to read sha1 file of %s (%s)", return error("unable to read sha1 file of %s (%s)",
path, oid_to_hex(&ce->oid)); path, oid_to_hex(&ce->oid));
} }
@ -313,18 +313,18 @@ static int write_entry(struct cache_entry *ce,
* Convert from git internal format to working tree format * Convert from git internal format to working tree format
*/ */
if (dco && dco->state != CE_NO_DELAY) { if (dco && dco->state != CE_NO_DELAY) {
ret = async_convert_to_working_tree(ce->name, new, ret = async_convert_to_working_tree(ce->name, new_blob,
size, &buf, dco); size, &buf, dco);
if (ret && string_list_has_string(&dco->paths, ce->name)) { if (ret && string_list_has_string(&dco->paths, ce->name)) {
free(new); free(new_blob);
goto delayed; goto delayed;
} }
} else } else
ret = convert_to_working_tree(ce->name, new, size, &buf); ret = convert_to_working_tree(ce->name, new_blob, size, &buf);
if (ret) { if (ret) {
free(new); free(new_blob);
new = strbuf_detach(&buf, &newsize); new_blob = strbuf_detach(&buf, &newsize);
size = newsize; size = newsize;
} }
/* /*
@ -336,15 +336,15 @@ static int write_entry(struct cache_entry *ce,
write_file_entry: write_file_entry:
fd = open_output_fd(path, ce, to_tempfile); fd = open_output_fd(path, ce, to_tempfile);
if (fd < 0) { if (fd < 0) {
free(new); free(new_blob);
return error_errno("unable to create file %s", path); return error_errno("unable to create file %s", path);
} }
wrote = write_in_full(fd, new, size); wrote = write_in_full(fd, new_blob, size);
if (!to_tempfile) if (!to_tempfile)
fstat_done = fstat_output(fd, state, &st); fstat_done = fstat_output(fd, state, &st);
close(fd); close(fd);
free(new); free(new_blob);
if (wrote < 0) if (wrote < 0)
return error("unable to write file %s", path); return error("unable to write file %s", path);
break; break;

Просмотреть файл

@ -100,7 +100,7 @@ int ignore_untracked_cache_config;
/* This is set by setup_git_dir_gently() and/or git_default_config() */ /* This is set by setup_git_dir_gently() and/or git_default_config() */
char *git_work_tree_cfg; char *git_work_tree_cfg;
static char *namespace; static char *git_namespace;
static const char *super_prefix; static const char *super_prefix;
@ -158,8 +158,8 @@ void setup_git_env(void)
free(git_replace_ref_base); free(git_replace_ref_base);
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
: "refs/replace/"); : "refs/replace/");
free(namespace); free(git_namespace);
namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
if (shallow_file) if (shallow_file)
set_alternate_shallow_file(shallow_file, 0); set_alternate_shallow_file(shallow_file, 0);
@ -193,9 +193,9 @@ const char *get_git_common_dir(void)
const char *get_git_namespace(void) const char *get_git_namespace(void)
{ {
if (!namespace) if (!git_namespace)
BUG("git environment hasn't been setup"); BUG("git environment hasn't been setup");
return namespace; return git_namespace;
} }
const char *strip_namespace(const char *namespaced_ref) const char *strip_namespace(const char *namespaced_ref)
@ -249,7 +249,7 @@ char *get_object_directory(void)
return the_repository->objectdir; return the_repository->objectdir;
} }
int odb_mkstemp(struct strbuf *template, const char *pattern) int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
{ {
int fd; int fd;
/* /*
@ -257,16 +257,16 @@ int odb_mkstemp(struct strbuf *template, const char *pattern)
* restrictive except to remove write permission. * restrictive except to remove write permission.
*/ */
int mode = 0444; int mode = 0444;
git_path_buf(template, "objects/%s", pattern); git_path_buf(temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(template->buf, mode); fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd) if (0 <= fd)
return fd; return fd;
/* slow path */ /* slow path */
/* some mkstemp implementations erase template on failure */ /* some mkstemp implementations erase temp_filename on failure */
git_path_buf(template, "objects/%s", pattern); git_path_buf(temp_filename, "objects/%s", pattern);
safe_create_leading_directories(template->buf); safe_create_leading_directories(temp_filename->buf);
return xmkstemp_mode(template->buf, mode); return xmkstemp_mode(temp_filename->buf, mode);
} }
int odb_pack_keep(const char *name) int odb_pack_keep(const char *name)

Просмотреть файл

@ -1096,7 +1096,7 @@ static int store_object(
git_zstream s; git_zstream s;
hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu", hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu",
typename(type), (unsigned long)dat->len) + 1; type_name(type), (unsigned long)dat->len) + 1;
the_hash_algo->init_fn(&c); the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, hdrlen); the_hash_algo->update_fn(&c, hdr, hdrlen);
the_hash_algo->update_fn(&c, dat->buf, dat->len); the_hash_algo->update_fn(&c, dat->buf, dat->len);
@ -2423,7 +2423,7 @@ static void file_change_m(const char *p, struct branch *b)
else if (oe) { else if (oe) {
if (oe->type != OBJ_COMMIT) if (oe->type != OBJ_COMMIT)
die("Not a commit (actually a %s): %s", die("Not a commit (actually a %s): %s",
typename(oe->type), command_buf.buf); type_name(oe->type), command_buf.buf);
} }
/* /*
* Accept the sha1 without checking; it expected to be in * Accept the sha1 without checking; it expected to be in
@ -2450,7 +2450,7 @@ static void file_change_m(const char *p, struct branch *b)
command_buf.buf); command_buf.buf);
if (type != expected) if (type != expected)
die("Not a %s (actually a %s): %s", die("Not a %s (actually a %s): %s",
typename(expected), typename(type), type_name(expected), type_name(type),
command_buf.buf); command_buf.buf);
} }
@ -2601,14 +2601,14 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
} else if (oe) { } else if (oe) {
if (oe->type != OBJ_BLOB) if (oe->type != OBJ_BLOB)
die("Not a blob (actually a %s): %s", die("Not a blob (actually a %s): %s",
typename(oe->type), command_buf.buf); type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) { } else if (!is_null_oid(&oid)) {
enum object_type type = sha1_object_info(oid.hash, NULL); enum object_type type = sha1_object_info(oid.hash, NULL);
if (type < 0) if (type < 0)
die("Blob not found: %s", command_buf.buf); die("Blob not found: %s", command_buf.buf);
if (type != OBJ_BLOB) if (type != OBJ_BLOB)
die("Not a blob (actually a %s): %s", die("Not a blob (actually a %s): %s",
typename(type), command_buf.buf); type_name(type), command_buf.buf);
} }
construct_path_with_fanout(oid_to_hex(&commit_oid), *old_fanout, path); construct_path_with_fanout(oid_to_hex(&commit_oid), *old_fanout, path);
@ -2916,7 +2916,7 @@ static void parse_new_tag(const char *arg)
"object %s\n" "object %s\n"
"type %s\n" "type %s\n"
"tag %s\n", "tag %s\n",
oid_to_hex(&oid), typename(type), t->name); oid_to_hex(&oid), type_name(type), t->name);
if (tagger) if (tagger)
strbuf_addf(&new_data, strbuf_addf(&new_data,
"tagger %s\n", tagger); "tagger %s\n", tagger);
@ -2987,10 +2987,10 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
die("Can't read object %s", oid_to_hex(oid)); die("Can't read object %s", oid_to_hex(oid));
if (type != OBJ_BLOB) if (type != OBJ_BLOB)
die("Object %s is a %s but a blob was expected.", die("Object %s is a %s but a blob was expected.",
oid_to_hex(oid), typename(type)); oid_to_hex(oid), type_name(type));
strbuf_reset(&line); strbuf_reset(&line);
strbuf_addf(&line, "%s %s %lu\n", oid_to_hex(oid), strbuf_addf(&line, "%s %s %lu\n", oid_to_hex(oid),
typename(type), size); type_name(type), size);
cat_blob_write(line.buf, line.len); cat_blob_write(line.buf, line.len);
strbuf_release(&line); strbuf_release(&line);
cat_blob_write(buf, size); cat_blob_write(buf, size);

2
fsck.c
Просмотреть файл

@ -821,7 +821,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
ret = report(options, &tag->object, ret = report(options, &tag->object,
FSCK_MSG_TAG_OBJECT_NOT_TAG, FSCK_MSG_TAG_OBJECT_NOT_TAG,
"expected tag got %s", "expected tag got %s",
typename(type)); type_name(type));
goto done; goto done;
} }
} }

Просмотреть файл

@ -826,8 +826,8 @@ extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
extern int xdup(int fd); extern int xdup(int fd);
extern FILE *xfopen(const char *path, const char *mode); extern FILE *xfopen(const char *path, const char *mode);
extern FILE *xfdopen(int fd, const char *mode); extern FILE *xfdopen(int fd, const char *mode);
extern int xmkstemp(char *template); extern int xmkstemp(char *temp_filename);
extern int xmkstemp_mode(char *template, int mode); extern int xmkstemp_mode(char *temp_filename, int mode);
extern char *xgetcwd(void); extern char *xgetcwd(void);
extern FILE *fopen_for_writing(const char *path); extern FILE *fopen_for_writing(const char *path);
extern FILE *fopen_or_warn(const char *path, const char *mode); extern FILE *fopen_or_warn(const char *path, const char *mode);

Просмотреть файл

@ -362,7 +362,7 @@ static void start_put(struct transfer_request *request)
git_zstream stream; git_zstream stream;
unpacked = read_sha1_file(request->obj->oid.hash, &type, &len); unpacked = read_sha1_file(request->obj->oid.hash, &type, &len);
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1; hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
/* Set it up */ /* Set it up */
git_deflate_init(&stream, zlib_compression_level); git_deflate_init(&stream, zlib_compression_level);

10
http.c
Просмотреть файл

@ -1260,14 +1260,14 @@ static struct fill_chain *fill_cfg;
void add_fill_function(void *data, int (*fill)(void *)) void add_fill_function(void *data, int (*fill)(void *))
{ {
struct fill_chain *new = xmalloc(sizeof(*new)); struct fill_chain *new_fill = xmalloc(sizeof(*new_fill));
struct fill_chain **linkp = &fill_cfg; struct fill_chain **linkp = &fill_cfg;
new->data = data; new_fill->data = data;
new->fill = fill; new_fill->fill = fill;
new->next = NULL; new_fill->next = NULL;
while (*linkp) while (*linkp)
linkp = &(*linkp)->next; linkp = &(*linkp)->next;
*linkp = new; *linkp = new_fill;
} }
void fill_active_slots(void) void fill_active_slots(void)

Просмотреть файл

@ -1189,11 +1189,11 @@ bail:
*/ */
static void lf_to_crlf(struct strbuf *msg) static void lf_to_crlf(struct strbuf *msg)
{ {
char *new; char *new_msg;
size_t i, j; size_t i, j;
char lastc; char lastc;
/* First pass: tally, in j, the size of the new string: */ /* First pass: tally, in j, the size of the new_msg string: */
for (i = j = 0, lastc = '\0'; i < msg->len; i++) { for (i = j = 0, lastc = '\0'; i < msg->len; i++) {
if (msg->buf[i] == '\n' && lastc != '\r') if (msg->buf[i] == '\n' && lastc != '\r')
j++; /* a CR will need to be added here */ j++; /* a CR will need to be added here */
@ -1201,18 +1201,18 @@ static void lf_to_crlf(struct strbuf *msg)
j++; j++;
} }
new = xmallocz(j); new_msg = xmallocz(j);
/* /*
* Second pass: write the new string. Note that this loop is * Second pass: write the new_msg string. Note that this loop is
* otherwise identical to the first pass. * otherwise identical to the first pass.
*/ */
for (i = j = 0, lastc = '\0'; i < msg->len; i++) { for (i = j = 0, lastc = '\0'; i < msg->len; i++) {
if (msg->buf[i] == '\n' && lastc != '\r') if (msg->buf[i] == '\n' && lastc != '\r')
new[j++] = '\r'; new_msg[j++] = '\r';
lastc = new[j++] = msg->buf[i]; lastc = new_msg[j++] = msg->buf[i];
} }
strbuf_attach(msg, new, j, j + 1); strbuf_attach(msg, new_msg, j, j + 1);
} }
/* /*

Просмотреть файл

@ -151,29 +151,29 @@ static void range_set_union(struct range_set *out,
assert(out->nr == 0); assert(out->nr == 0);
while (i < a->nr || j < b->nr) { while (i < a->nr || j < b->nr) {
struct range *new; struct range *new_range;
if (i < a->nr && j < b->nr) { if (i < a->nr && j < b->nr) {
if (ra[i].start < rb[j].start) if (ra[i].start < rb[j].start)
new = &ra[i++]; new_range = &ra[i++];
else if (ra[i].start > rb[j].start) else if (ra[i].start > rb[j].start)
new = &rb[j++]; new_range = &rb[j++];
else if (ra[i].end < rb[j].end) else if (ra[i].end < rb[j].end)
new = &ra[i++]; new_range = &ra[i++];
else else
new = &rb[j++]; new_range = &rb[j++];
} else if (i < a->nr) /* b exhausted */ } else if (i < a->nr) /* b exhausted */
new = &ra[i++]; new_range = &ra[i++];
else /* a exhausted */ else /* a exhausted */
new = &rb[j++]; new_range = &rb[j++];
if (new->start == new->end) if (new_range->start == new_range->end)
; /* empty range */ ; /* empty range */
else if (!out->nr || out->ranges[out->nr-1].end < new->start) { else if (!out->nr || out->ranges[out->nr-1].end < new_range->start) {
range_set_grow(out, 1); range_set_grow(out, 1);
out->ranges[out->nr].start = new->start; out->ranges[out->nr].start = new_range->start;
out->ranges[out->nr].end = new->end; out->ranges[out->nr].end = new_range->end;
out->nr++; out->nr++;
} else if (out->ranges[out->nr-1].end < new->end) { } else if (out->ranges[out->nr-1].end < new_range->end) {
out->ranges[out->nr-1].end = new->end; out->ranges[out->nr-1].end = new_range->end;
} }
} }
} }
@ -696,18 +696,18 @@ static struct line_log_data *line_log_data_merge(struct line_log_data *a,
static void add_line_range(struct rev_info *revs, struct commit *commit, static void add_line_range(struct rev_info *revs, struct commit *commit,
struct line_log_data *range) struct line_log_data *range)
{ {
struct line_log_data *old = NULL; struct line_log_data *old_line = NULL;
struct line_log_data *new = NULL; struct line_log_data *new_line = NULL;
old = lookup_decoration(&revs->line_log_data, &commit->object); old_line = lookup_decoration(&revs->line_log_data, &commit->object);
if (old && range) { if (old_line && range) {
new = line_log_data_merge(old, range); new_line = line_log_data_merge(old_line, range);
free_line_log_data(old); free_line_log_data(old_line);
} else if (range) } else if (range)
new = line_log_data_copy(range); new_line = line_log_data_copy(range);
if (new) if (new_line)
add_decoration(&revs->line_log_data, &commit->object, new); add_decoration(&revs->line_log_data, &commit->object, new_line);
} }
static void clear_commit_line_range(struct rev_info *revs, struct commit *commit) static void clear_commit_line_range(struct rev_info *revs, struct commit *commit)
@ -1042,12 +1042,12 @@ static int process_diff_filepair(struct rev_info *rev,
static struct diff_filepair *diff_filepair_dup(struct diff_filepair *pair) static struct diff_filepair *diff_filepair_dup(struct diff_filepair *pair)
{ {
struct diff_filepair *new = xmalloc(sizeof(struct diff_filepair)); struct diff_filepair *new_filepair = xmalloc(sizeof(struct diff_filepair));
new->one = pair->one; new_filepair->one = pair->one;
new->two = pair->two; new_filepair->two = pair->two;
new->one->count++; new_filepair->one->count++;
new->two->count++; new_filepair->two->count++;
return new; return new_filepair;
} }
static void free_diffqueues(int n, struct diff_queue_struct *dq) static void free_diffqueues(int n, struct diff_queue_struct *dq)

Просмотреть файл

@ -499,7 +499,7 @@ static void show_one_mergetag(struct commit *commit,
int status, nth; int status, nth;
size_t payload_size, gpg_message_offset; size_t payload_size, gpg_message_offset;
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &oid); hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid);
tag = lookup_tag(&oid); tag = lookup_tag(&oid);
if (!tag) if (!tag)
return; /* error message already given */ return; /* error message already given */

Просмотреть файл

@ -26,7 +26,7 @@ static const char *object_type_strings[] = {
"tag", /* OBJ_TAG = 4 */ "tag", /* OBJ_TAG = 4 */
}; };
const char *typename(unsigned int type) const char *type_name(unsigned int type)
{ {
if (type >= ARRAY_SIZE(object_type_strings)) if (type >= ARRAY_SIZE(object_type_strings))
return NULL; return NULL;
@ -166,7 +166,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
if (!quiet) if (!quiet)
error("object %s is a %s, not a %s", error("object %s is a %s, not a %s",
oid_to_hex(&obj->oid), oid_to_hex(&obj->oid),
typename(obj->type), typename(type)); type_name(obj->type), type_name(type));
return NULL; return NULL;
} }
} }
@ -265,7 +265,7 @@ struct object *parse_object(const struct object_id *oid)
buffer = read_sha1_file(oid->hash, &type, &size); buffer = read_sha1_file(oid->hash, &type, &size);
if (buffer) { if (buffer) {
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { if (check_sha1_signature(repl, buffer, size, type_name(type)) < 0) {
free(buffer); free(buffer);
error("sha1 mismatch %s", sha1_to_hex(repl)); error("sha1 mismatch %s", sha1_to_hex(repl));
return NULL; return NULL;

Просмотреть файл

@ -53,7 +53,7 @@ struct object {
struct object_id oid; struct object_id oid;
}; };
extern const char *typename(unsigned int type); extern const char *type_name(unsigned int type);
extern int type_from_string_gently(const char *str, ssize_t, int gentle); extern int type_from_string_gently(const char *str, ssize_t, int gentle);
#define type_from_string(str) type_from_string_gently(str, -1, 0) #define type_from_string(str) type_from_string_gently(str, -1, 0)

Просмотреть файл

@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
err = error("cannot unpack %s from %s at offset %"PRIuMAX"", err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
oid_to_hex(entries[i].oid.oid), p->pack_name, oid_to_hex(entries[i].oid.oid), p->pack_name,
(uintmax_t)entries[i].offset); (uintmax_t)entries[i].offset);
else if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type))) else if (check_sha1_signature(entries[i].oid.hash, data, size, type_name(type)))
err = error("packed %s from %s is corrupt", err = error("packed %s from %s is corrupt",
oid_to_hex(entries[i].oid.oid), p->pack_name); oid_to_hex(entries[i].oid.oid), p->pack_name);
else if (fn) { else if (fn) {

Просмотреть файл

@ -1361,16 +1361,16 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,
*oi->disk_sizep = revidx[1].offset - obj_offset; *oi->disk_sizep = revidx[1].offset - obj_offset;
} }
if (oi->typep || oi->typename) { if (oi->typep || oi->type_name) {
enum object_type ptot; enum object_type ptot;
ptot = packed_to_object_type(p, obj_offset, type, &w_curs, ptot = packed_to_object_type(p, obj_offset, type, &w_curs,
curpos); curpos);
if (oi->typep) if (oi->typep)
*oi->typep = ptot; *oi->typep = ptot;
if (oi->typename) { if (oi->type_name) {
const char *tn = typename(ptot); const char *tn = type_name(ptot);
if (tn) if (tn)
strbuf_addstr(oi->typename, tn); strbuf_addstr(oi->type_name, tn);
} }
if (ptot < 0) { if (ptot < 0) {
type = OBJ_BAD; type = OBJ_BAD;

Просмотреть файл

@ -94,7 +94,7 @@ static void add_recent_object(const struct object_id *oid,
break; break;
default: default:
die("unknown object type for %s: %s", die("unknown object type for %s: %s",
oid_to_hex(oid), typename(type)); oid_to_hex(oid), type_name(type));
} }
if (!obj) if (!obj)

Просмотреть файл

@ -70,20 +70,20 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name) void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name)
{ {
struct cache_entry *old = istate->cache[nr], *new; struct cache_entry *old_entry = istate->cache[nr], *new_entry;
int namelen = strlen(new_name); int namelen = strlen(new_name);
new = xmalloc(cache_entry_size(namelen)); new_entry = xmalloc(cache_entry_size(namelen));
copy_cache_entry(new, old); copy_cache_entry(new_entry, old_entry);
new->ce_flags &= ~CE_HASHED; new_entry->ce_flags &= ~CE_HASHED;
new->ce_namelen = namelen; new_entry->ce_namelen = namelen;
new->index = 0; new_entry->index = 0;
memcpy(new->name, new_name, namelen + 1); memcpy(new_entry->name, new_name, namelen + 1);
cache_tree_invalidate_path(istate, old->name); cache_tree_invalidate_path(istate, old_entry->name);
untracked_cache_remove_from_index(istate, old->name); untracked_cache_remove_from_index(istate, old_entry->name);
remove_index_entry_at(istate, nr); remove_index_entry_at(istate, nr);
add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
} }
void fill_stat_data(struct stat_data *sd, struct stat *st) void fill_stat_data(struct stat_data *sd, struct stat *st)
@ -615,18 +615,18 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,
struct cache_entry *alias) struct cache_entry *alias)
{ {
int len; int len;
struct cache_entry *new; struct cache_entry *new_entry;
if (alias->ce_flags & CE_ADDED) if (alias->ce_flags & CE_ADDED)
die("Will not add file alias '%s' ('%s' already exists in index)", ce->name, alias->name); die("Will not add file alias '%s' ('%s' already exists in index)", ce->name, alias->name);
/* Ok, create the new entry using the name of the existing alias */ /* Ok, create the new entry using the name of the existing alias */
len = ce_namelen(alias); len = ce_namelen(alias);
new = xcalloc(1, cache_entry_size(len)); new_entry = xcalloc(1, cache_entry_size(len));
memcpy(new->name, alias->name, len); memcpy(new_entry->name, alias->name, len);
copy_cache_entry(new, ce); copy_cache_entry(new_entry, ce);
save_or_free_index_entry(istate, ce); save_or_free_index_entry(istate, ce);
return new; return new_entry;
} }
void set_object_name_for_intent_to_add_entry(struct cache_entry *ce) void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
@ -1379,7 +1379,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n"); added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n"); unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
for (i = 0; i < istate->cache_nr; i++) { for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new; struct cache_entry *ce, *new_entry;
int cache_errno = 0; int cache_errno = 0;
int changed = 0; int changed = 0;
int filtered = 0; int filtered = 0;
@ -1408,10 +1408,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
if (filtered) if (filtered)
continue; continue;
new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed); new_entry = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
if (new == ce) if (new_entry == ce)
continue; continue;
if (!new) { if (!new_entry) {
const char *fmt; const char *fmt;
if (really && cache_errno == EINVAL) { if (really && cache_errno == EINVAL) {
@ -1440,7 +1440,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
continue; continue;
} }
replace_index_entry(istate, i, new); replace_index_entry(istate, i, new_entry);
} }
trace_performance_since(start, "refresh index"); trace_performance_since(start, "refresh index");
return has_errors; return has_errors;

Просмотреть файл

@ -529,12 +529,12 @@ static void end_align_handler(struct ref_formatting_stack **stack)
static void align_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state) static void align_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state)
{ {
struct ref_formatting_stack *new; struct ref_formatting_stack *new_stack;
push_stack_element(&state->stack); push_stack_element(&state->stack);
new = state->stack; new_stack = state->stack;
new->at_end = end_align_handler; new_stack->at_end = end_align_handler;
new->at_end_data = &atomv->atom->u.align; new_stack->at_end_data = &atomv->atom->u.align;
} }
static void if_then_else_handler(struct ref_formatting_stack **stack) static void if_then_else_handler(struct ref_formatting_stack **stack)
@ -574,16 +574,16 @@ static void if_then_else_handler(struct ref_formatting_stack **stack)
static void if_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state) static void if_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state)
{ {
struct ref_formatting_stack *new; struct ref_formatting_stack *new_stack;
struct if_then_else *if_then_else = xcalloc(sizeof(struct if_then_else), 1); struct if_then_else *if_then_else = xcalloc(sizeof(struct if_then_else), 1);
if_then_else->str = atomv->atom->u.if_then_else.str; if_then_else->str = atomv->atom->u.if_then_else.str;
if_then_else->cmp_status = atomv->atom->u.if_then_else.cmp_status; if_then_else->cmp_status = atomv->atom->u.if_then_else.cmp_status;
push_stack_element(&state->stack); push_stack_element(&state->stack);
new = state->stack; new_stack = state->stack;
new->at_end = if_then_else_handler; new_stack->at_end = if_then_else_handler;
new->at_end_data = if_then_else; new_stack->at_end_data = if_then_else;
} }
static int is_empty(const char *s) static int is_empty(const char *s)
@ -769,7 +769,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
if (deref) if (deref)
name++; name++;
if (!strcmp(name, "objecttype")) if (!strcmp(name, "objecttype"))
v->s = typename(obj->type); v->s = type_name(obj->type);
else if (!strcmp(name, "objectsize")) { else if (!strcmp(name, "objectsize")) {
v->value = sz; v->value = sz;
v->s = xstrfmt("%lu", sz); v->s = xstrfmt("%lu", sz);
@ -795,7 +795,7 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
if (!strcmp(name, "tag")) if (!strcmp(name, "tag"))
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 = type_name(tag->tagged->type);
else if (!strcmp(name, "object") && tag->tagged) else if (!strcmp(name, "object") && tag->tagged)
v->s = xstrdup(oid_to_hex(&tag->tagged->oid)); v->s = xstrdup(oid_to_hex(&tag->tagged->oid));
} }

Просмотреть файл

@ -1985,33 +1985,33 @@ static void unmark_and_free(struct commit_list *list, unsigned int mark)
int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid) int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
{ {
struct object *o; struct object *o;
struct commit *old, *new; struct commit *old_commit, *new_commit;
struct commit_list *list, *used; struct commit_list *list, *used;
int found = 0; int found = 0;
/* /*
* Both new and old must be commit-ish and new is descendant of * Both new_commit and old_commit must be commit-ish and new_commit is descendant of
* old. Otherwise we require --force. * old_commit. Otherwise we require --force.
*/ */
o = deref_tag(parse_object(old_oid), NULL, 0); o = deref_tag(parse_object(old_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
old = (struct commit *) o; old_commit = (struct commit *) o;
o = deref_tag(parse_object(new_oid), NULL, 0); o = deref_tag(parse_object(new_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
new = (struct commit *) o; new_commit = (struct commit *) o;
if (parse_commit(new) < 0) if (parse_commit(new_commit) < 0)
return 0; return 0;
used = list = NULL; used = list = NULL;
commit_list_insert(new, &list); commit_list_insert(new_commit, &list);
while (list) { while (list) {
new = pop_most_recent_commit(&list, TMP_MARK); new_commit = pop_most_recent_commit(&list, TMP_MARK);
commit_list_insert(new, &used); commit_list_insert(new_commit, &used);
if (new == old) { if (new_commit == old_commit) {
found = 1; found = 1;
break; break;
} }

Просмотреть файл

@ -2883,7 +2883,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
if (!lookup_commit_reference_gently(&oid, 1)) { if (!lookup_commit_reference_gently(&oid, 1)) {
enum object_type type = sha1_object_info(oid.hash, NULL); enum object_type type = sha1_object_info(oid.hash, NULL);
return error(_("%s: can't cherry-pick a %s"), return error(_("%s: can't cherry-pick a %s"),
name, typename(type)); name, type_name(type));
} }
} else } else
return error(_("%s: bad revision"), name); return error(_("%s: bad revision"), name);

Просмотреть файл

@ -804,7 +804,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
return -1; return -1;
/* Generate the header */ /* Generate the header */
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(obj_type), size) + 1; hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(obj_type), size) + 1;
/* Sha1.. */ /* Sha1.. */
the_hash_algo->init_fn(&c); the_hash_algo->init_fn(&c);
@ -1094,8 +1094,8 @@ static int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
} }
type = type_from_string_gently(type_buf, type_len, 1); type = type_from_string_gently(type_buf, type_len, 1);
if (oi->typename) if (oi->type_name)
strbuf_add(oi->typename, type_buf, type_len); strbuf_add(oi->type_name, type_buf, type_len);
/* /*
* Set type to 0 if its an unknown object and * Set type to 0 if its an unknown object and
* we're obtaining the type using '--allow-unknown-type' * we're obtaining the type using '--allow-unknown-type'
@ -1165,7 +1165,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
* return value implicitly indicates whether the * return value implicitly indicates whether the
* object even exists. * object even exists.
*/ */
if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) { if (!oi->typep && !oi->type_name && !oi->sizep && !oi->contentp) {
const char *path; const char *path;
struct stat st; struct stat st;
if (stat_sha1_file(sha1, &st, &path) < 0) if (stat_sha1_file(sha1, &st, &path) < 0)
@ -1249,8 +1249,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
*(oi->disk_sizep) = 0; *(oi->disk_sizep) = 0;
if (oi->delta_base_sha1) if (oi->delta_base_sha1)
hashclr(oi->delta_base_sha1); hashclr(oi->delta_base_sha1);
if (oi->typename) if (oi->type_name)
strbuf_addstr(oi->typename, typename(co->type)); strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp) if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size); *oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED; oi->whence = OI_CACHED;
@ -1339,7 +1339,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
{ {
struct cached_object *co; struct cached_object *co;
hash_object_file(buf, len, typename(type), oid); hash_object_file(buf, len, type_name(type), oid);
if (has_sha1_file(oid->hash) || find_cached_object(oid->hash)) if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
return 0; return 0;
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
@ -1714,7 +1714,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
buf = read_object(oid->hash, &type, &len); buf = read_object(oid->hash, &type, &len);
if (!buf) if (!buf)
return error("cannot read sha1_file for %s", oid_to_hex(oid)); return error("cannot read sha1_file for %s", oid_to_hex(oid));
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1; hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime); ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
free(buf); free(buf);
@ -1798,9 +1798,9 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
} }
if (write_object) if (write_object)
ret = write_object_file(buf, size, typename(type), oid); ret = write_object_file(buf, size, type_name(type), oid);
else else
ret = hash_object_file(buf, size, typename(type), oid); ret = hash_object_file(buf, size, type_name(type), oid);
if (re_allocated) if (re_allocated)
free(buf); free(buf);
return ret; return ret;
@ -1820,10 +1820,10 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
get_conv_flags(flags)); get_conv_flags(flags));
if (write_object) if (write_object)
ret = write_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB), ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
oid); oid);
else else
ret = hash_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB), ret = hash_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
oid); oid);
strbuf_release(&sbuf); strbuf_release(&sbuf);
return ret; return ret;
@ -1973,7 +1973,7 @@ void assert_sha1_type(const unsigned char *sha1, enum object_type expect)
die("%s is not a valid object", sha1_to_hex(sha1)); die("%s is not a valid object", sha1_to_hex(sha1));
if (type != expect) if (type != expect)
die("%s is not a valid '%s' object", sha1_to_hex(sha1), die("%s is not a valid '%s' object", sha1_to_hex(sha1),
typename(expect)); type_name(expect));
} }
int for_each_file_in_obj_subdir(unsigned int subdir_nr, int for_each_file_in_obj_subdir(unsigned int subdir_nr,
@ -2218,7 +2218,7 @@ int read_loose_object(const char *path,
goto out; goto out;
} }
if (check_sha1_signature(expected_sha1, *contents, if (check_sha1_signature(expected_sha1, *contents,
*size, typename(*type))) { *size, type_name(*type))) {
error("sha1 mismatch for %s (expected %s)", path, error("sha1 mismatch for %s (expected %s)", path,
sha1_to_hex(expected_sha1)); sha1_to_hex(expected_sha1));
free(*contents); free(*contents);

Просмотреть файл

@ -381,7 +381,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
advise(" %s %s%s", advise(" %s %s%s",
find_unique_abbrev(oid->hash, DEFAULT_ABBREV), find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
typename(type) ? typename(type) : "unknown type", type_name(type) ? type_name(type) : "unknown type",
desc.buf); desc.buf);
strbuf_release(&desc); strbuf_release(&desc);
@ -901,8 +901,8 @@ struct object *peel_to_type(const char *name, int namelen,
if (name) if (name)
error("%.*s: expected %s type, but the object " error("%.*s: expected %s type, but the object "
"dereferences to %s type", "dereferences to %s type",
namelen, name, typename(expected_type), namelen, name, type_name(expected_type),
typename(o->type)); type_name(o->type));
return NULL; return NULL;
} }
} }

Просмотреть файл

@ -305,17 +305,17 @@ void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce
} }
void replace_index_entry_in_base(struct index_state *istate, void replace_index_entry_in_base(struct index_state *istate,
struct cache_entry *old, struct cache_entry *old_entry,
struct cache_entry *new) struct cache_entry *new_entry)
{ {
if (old->index && if (old_entry->index &&
istate->split_index && istate->split_index &&
istate->split_index->base && istate->split_index->base &&
old->index <= istate->split_index->base->cache_nr) { old_entry->index <= istate->split_index->base->cache_nr) {
new->index = old->index; new_entry->index = old_entry->index;
if (old != istate->split_index->base->cache[new->index - 1]) if (old_entry != istate->split_index->base->cache[new_entry->index - 1])
free(istate->split_index->base->cache[new->index - 1]); free(istate->split_index->base->cache[new_entry->index - 1]);
istate->split_index->base->cache[new->index - 1] = new; istate->split_index->base->cache[new_entry->index - 1] = new_entry;
} }
} }

Просмотреть файл

@ -21,7 +21,7 @@ struct split_index *init_split_index(struct index_state *istate);
void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce); void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce);
void replace_index_entry_in_base(struct index_state *istate, void replace_index_entry_in_base(struct index_state *istate,
struct cache_entry *old, struct cache_entry *old,
struct cache_entry *new); struct cache_entry *new_entry);
int read_link_extension(struct index_state *istate, int read_link_extension(struct index_state *istate,
const void *data, unsigned long sz); const void *data, unsigned long sz);
int write_link_extension(struct strbuf *sb, int write_link_extension(struct strbuf *sb,

Просмотреть файл

@ -590,7 +590,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
struct object_id *one, struct object_id *two, struct object_id *one, struct object_id *two,
unsigned dirty_submodule) unsigned dirty_submodule)
{ {
const struct object_id *old = the_hash_algo->empty_tree, *new = the_hash_algo->empty_tree; const struct object_id *old_oid = the_hash_algo->empty_tree, *new_oid = the_hash_algo->empty_tree;
struct commit *left = NULL, *right = NULL; struct commit *left = NULL, *right = NULL;
struct commit_list *merge_bases = NULL; struct commit_list *merge_bases = NULL;
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
@ -605,9 +605,9 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
goto done; goto done;
if (left) if (left)
old = one; old_oid = one;
if (right) if (right)
new = two; new_oid = two;
cp.git_cmd = 1; cp.git_cmd = 1;
cp.dir = path; cp.dir = path;
@ -630,7 +630,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
argv_array_pushf(&cp.args, "--dst-prefix=%s%s/", argv_array_pushf(&cp.args, "--dst-prefix=%s%s/",
o->b_prefix, path); o->b_prefix, path);
} }
argv_array_push(&cp.args, oid_to_hex(old)); argv_array_push(&cp.args, oid_to_hex(old_oid));
/* /*
* If the submodule has modified content, we will diff against the * If the submodule has modified content, we will diff against the
* work tree, under the assumption that the user has asked for the * work tree, under the assumption that the user has asked for the
@ -638,7 +638,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
* haven't yet been committed to the submodule yet. * haven't yet been committed to the submodule yet.
*/ */
if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED)) if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
argv_array_push(&cp.args, oid_to_hex(new)); argv_array_push(&cp.args, oid_to_hex(new_oid));
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
if (start_command(&cp)) if (start_command(&cp))
@ -831,7 +831,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0; return 0;
default: default:
die(_("submodule entry '%s' (%s) is a %s, not a commit"), die(_("submodule entry '%s' (%s) is a %s, not a commit"),
cb->path, oid_to_hex(oid), typename(type)); cb->path, oid_to_hex(oid), type_name(type));
} }
} }
@ -1578,8 +1578,8 @@ static void submodule_reset_index(const char *path)
* pass NULL for old or new respectively. * pass NULL for old or new respectively.
*/ */
int submodule_move_head(const char *path, int submodule_move_head(const char *path,
const char *old, const char *old_head,
const char *new, const char *new_head,
unsigned flags) unsigned flags)
{ {
int ret = 0; int ret = 0;
@ -1600,7 +1600,7 @@ int submodule_move_head(const char *path,
else else
error_code_ptr = NULL; error_code_ptr = NULL;
if (old && !is_submodule_populated_gently(path, error_code_ptr)) if (old_head && !is_submodule_populated_gently(path, error_code_ptr))
return 0; return 0;
sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(&null_oid, path);
@ -1608,14 +1608,14 @@ int submodule_move_head(const char *path,
if (!sub) if (!sub)
die("BUG: could not get submodule information for '%s'", path); die("BUG: could not get submodule information for '%s'", path);
if (old && !(flags & SUBMODULE_MOVE_HEAD_FORCE)) { if (old_head && !(flags & SUBMODULE_MOVE_HEAD_FORCE)) {
/* Check if the submodule has a dirty index. */ /* Check if the submodule has a dirty index. */
if (submodule_has_dirty_index(sub)) if (submodule_has_dirty_index(sub))
return error(_("submodule '%s' has dirty index"), path); return error(_("submodule '%s' has dirty index"), path);
} }
if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) {
if (old) { if (old_head) {
if (!submodule_uses_gitfile(path)) if (!submodule_uses_gitfile(path))
absorb_git_dir_into_superproject("", path, absorb_git_dir_into_superproject("", path,
ABSORB_GITDIR_RECURSE_SUBMODULES); ABSORB_GITDIR_RECURSE_SUBMODULES);
@ -1629,7 +1629,7 @@ int submodule_move_head(const char *path,
submodule_reset_index(path); submodule_reset_index(path);
} }
if (old && (flags & SUBMODULE_MOVE_HEAD_FORCE)) { if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {
char *gitdir = xstrfmt("%s/modules/%s", char *gitdir = xstrfmt("%s/modules/%s",
get_git_common_dir(), sub->name); get_git_common_dir(), sub->name);
connect_work_tree_and_git_dir(path, gitdir); connect_work_tree_and_git_dir(path, gitdir);
@ -1658,9 +1658,9 @@ int submodule_move_head(const char *path,
argv_array_push(&cp.args, "-m"); argv_array_push(&cp.args, "-m");
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE)) if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX); argv_array_push(&cp.args, old_head ? old_head : EMPTY_TREE_SHA1_HEX);
argv_array_push(&cp.args, new ? new : EMPTY_TREE_SHA1_HEX); argv_array_push(&cp.args, new_head ? new_head : EMPTY_TREE_SHA1_HEX);
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;
@ -1668,7 +1668,7 @@ int submodule_move_head(const char *path,
} }
if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) {
if (new) { if (new_head) {
child_process_init(&cp); child_process_init(&cp);
/* also set the HEAD accordingly */ /* also set the HEAD accordingly */
cp.git_cmd = 1; cp.git_cmd = 1;
@ -1677,7 +1677,7 @@ int submodule_move_head(const char *path,
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
argv_array_pushl(&cp.args, "update-ref", "HEAD", argv_array_pushl(&cp.args, "update-ref", "HEAD",
"--no-deref", new, NULL); "--no-deref", new_head, NULL);
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;

Просмотреть файл

@ -117,7 +117,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
#define SUBMODULE_MOVE_HEAD_FORCE (1<<1) #define SUBMODULE_MOVE_HEAD_FORCE (1<<1)
extern int submodule_move_head(const char *path, extern int submodule_move_head(const char *path,
const char *old, const char *old,
const char *new, const char *new_head,
unsigned flags); unsigned flags);
/* /*

2
tag.c
Просмотреть файл

@ -47,7 +47,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
name_to_report ? name_to_report ?
name_to_report : name_to_report :
find_unique_abbrev(oid->hash, DEFAULT_ABBREV), find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
typename(type)); type_name(type));
buf = read_sha1_file(oid->hash, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)

Просмотреть файл

@ -165,11 +165,11 @@ struct tempfile *register_tempfile(const char *path)
return tempfile; return tempfile;
} }
struct tempfile *mks_tempfile_sm(const char *template, int suffixlen, int mode) struct tempfile *mks_tempfile_sm(const char *filename_template, int suffixlen, int mode)
{ {
struct tempfile *tempfile = new_tempfile(); struct tempfile *tempfile = new_tempfile();
strbuf_add_absolute_path(&tempfile->filename, template); strbuf_add_absolute_path(&tempfile->filename, filename_template);
tempfile->fd = git_mkstemps_mode(tempfile->filename.buf, suffixlen, mode); tempfile->fd = git_mkstemps_mode(tempfile->filename.buf, suffixlen, mode);
if (tempfile->fd < 0) { if (tempfile->fd < 0) {
deactivate_tempfile(tempfile); deactivate_tempfile(tempfile);
@ -179,7 +179,7 @@ struct tempfile *mks_tempfile_sm(const char *template, int suffixlen, int mode)
return tempfile; return tempfile;
} }
struct tempfile *mks_tempfile_tsm(const char *template, int suffixlen, int mode) struct tempfile *mks_tempfile_tsm(const char *filename_template, int suffixlen, int mode)
{ {
struct tempfile *tempfile = new_tempfile(); struct tempfile *tempfile = new_tempfile();
const char *tmpdir; const char *tmpdir;
@ -188,7 +188,7 @@ struct tempfile *mks_tempfile_tsm(const char *template, int suffixlen, int mode)
if (!tmpdir) if (!tmpdir)
tmpdir = "/tmp"; tmpdir = "/tmp";
strbuf_addf(&tempfile->filename, "%s/%s", tmpdir, template); strbuf_addf(&tempfile->filename, "%s/%s", tmpdir, filename_template);
tempfile->fd = git_mkstemps_mode(tempfile->filename.buf, suffixlen, mode); tempfile->fd = git_mkstemps_mode(tempfile->filename.buf, suffixlen, mode);
if (tempfile->fd < 0) { if (tempfile->fd < 0) {
deactivate_tempfile(tempfile); deactivate_tempfile(tempfile);
@ -198,12 +198,12 @@ struct tempfile *mks_tempfile_tsm(const char *template, int suffixlen, int mode)
return tempfile; return tempfile;
} }
struct tempfile *xmks_tempfile_m(const char *template, int mode) struct tempfile *xmks_tempfile_m(const char *filename_template, int mode)
{ {
struct tempfile *tempfile; struct tempfile *tempfile;
struct strbuf full_template = STRBUF_INIT; struct strbuf full_template = STRBUF_INIT;
strbuf_add_absolute_path(&full_template, template); strbuf_add_absolute_path(&full_template, filename_template);
tempfile = mks_tempfile_m(full_template.buf, mode); tempfile = mks_tempfile_m(full_template.buf, mode);
if (!tempfile) if (!tempfile)
die_errno("Unable to create temporary file '%s'", die_errno("Unable to create temporary file '%s'",

Просмотреть файл

@ -135,58 +135,58 @@ extern struct tempfile *register_tempfile(const char *path);
*/ */
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
extern struct tempfile *mks_tempfile_sm(const char *template, extern struct tempfile *mks_tempfile_sm(const char *filename_template,
int suffixlen, int mode); int suffixlen, int mode);
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile_s(const char *template, static inline struct tempfile *mks_tempfile_s(const char *filename_template,
int suffixlen) int suffixlen)
{ {
return mks_tempfile_sm(template, suffixlen, 0600); return mks_tempfile_sm(filename_template, suffixlen, 0600);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile_m(const char *template, int mode) static inline struct tempfile *mks_tempfile_m(const char *filename_template, int mode)
{ {
return mks_tempfile_sm(template, 0, mode); return mks_tempfile_sm(filename_template, 0, mode);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile(const char *template) static inline struct tempfile *mks_tempfile(const char *filename_template)
{ {
return mks_tempfile_sm(template, 0, 0600); return mks_tempfile_sm(filename_template, 0, 0600);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
extern struct tempfile *mks_tempfile_tsm(const char *template, extern struct tempfile *mks_tempfile_tsm(const char *filename_template,
int suffixlen, int mode); int suffixlen, int mode);
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile_ts(const char *template, static inline struct tempfile *mks_tempfile_ts(const char *filename_template,
int suffixlen) int suffixlen)
{ {
return mks_tempfile_tsm(template, suffixlen, 0600); return mks_tempfile_tsm(filename_template, suffixlen, 0600);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile_tm(const char *template, int mode) static inline struct tempfile *mks_tempfile_tm(const char *filename_template, int mode)
{ {
return mks_tempfile_tsm(template, 0, mode); return mks_tempfile_tsm(filename_template, 0, mode);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *mks_tempfile_t(const char *template) static inline struct tempfile *mks_tempfile_t(const char *filename_template)
{ {
return mks_tempfile_tsm(template, 0, 0600); return mks_tempfile_tsm(filename_template, 0, 0600);
} }
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
extern struct tempfile *xmks_tempfile_m(const char *template, int mode); extern struct tempfile *xmks_tempfile_m(const char *filename_template, int mode);
/* See "mks_tempfile functions" above. */ /* See "mks_tempfile functions" above. */
static inline struct tempfile *xmks_tempfile(const char *template) static inline struct tempfile *xmks_tempfile(const char *filename_template)
{ {
return xmks_tempfile_m(template, 0600); return xmks_tempfile_m(filename_template, 0600);
} }
/* /*

Просмотреть файл

@ -174,12 +174,12 @@ static void print_all(FILE *outfile, struct list_head *head,
static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok) static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok)
{ {
struct trailer_item *new = xcalloc(sizeof(*new), 1); struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1);
new->token = arg_tok->token; new_item->token = arg_tok->token;
new->value = arg_tok->value; new_item->value = arg_tok->value;
arg_tok->token = arg_tok->value = NULL; arg_tok->token = arg_tok->value = NULL;
free_arg_item(arg_tok); free_arg_item(arg_tok);
return new; return new_item;
} }
static void add_arg_to_input_list(struct trailer_item *on_tok, static void add_arg_to_input_list(struct trailer_item *on_tok,
@ -666,30 +666,30 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val,
static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, static struct trailer_item *add_trailer_item(struct list_head *head, char *tok,
char *val) char *val)
{ {
struct trailer_item *new = xcalloc(sizeof(*new), 1); struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1);
new->token = tok; new_item->token = tok;
new->value = val; new_item->value = val;
list_add_tail(&new->list, head); list_add_tail(&new_item->list, head);
return new; return new_item;
} }
static void add_arg_item(struct list_head *arg_head, char *tok, char *val, static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
const struct conf_info *conf, const struct conf_info *conf,
const struct new_trailer_item *new_trailer_item) const struct new_trailer_item *new_trailer_item)
{ {
struct arg_item *new = xcalloc(sizeof(*new), 1); struct arg_item *new_item = xcalloc(sizeof(*new_item), 1);
new->token = tok; new_item->token = tok;
new->value = val; new_item->value = val;
duplicate_conf(&new->conf, conf); duplicate_conf(&new_item->conf, conf);
if (new_trailer_item) { if (new_trailer_item) {
if (new_trailer_item->where != WHERE_DEFAULT) if (new_trailer_item->where != WHERE_DEFAULT)
new->conf.where = new_trailer_item->where; new_item->conf.where = new_trailer_item->where;
if (new_trailer_item->if_exists != EXISTS_DEFAULT) if (new_trailer_item->if_exists != EXISTS_DEFAULT)
new->conf.if_exists = new_trailer_item->if_exists; new_item->conf.if_exists = new_trailer_item->if_exists;
if (new_trailer_item->if_missing != MISSING_DEFAULT) if (new_trailer_item->if_missing != MISSING_DEFAULT)
new->conf.if_missing = new_trailer_item->if_missing; new_item->conf.if_missing = new_trailer_item->if_missing;
} }
list_add_tail(&new->list, arg_head); list_add_tail(&new_item->list, arg_head);
} }
static void process_command_line_args(struct list_head *arg_head, static void process_command_line_args(struct list_head *arg_head,
@ -1000,7 +1000,7 @@ static struct tempfile *trailers_tempfile;
static FILE *create_in_place_tempfile(const char *file) static FILE *create_in_place_tempfile(const char *file)
{ {
struct stat st; struct stat st;
struct strbuf template = STRBUF_INIT; struct strbuf filename_template = STRBUF_INIT;
const char *tail; const char *tail;
FILE *outfile; FILE *outfile;
@ -1014,11 +1014,11 @@ static FILE *create_in_place_tempfile(const char *file)
/* Create temporary file in the same directory as the original */ /* Create temporary file in the same directory as the original */
tail = strrchr(file, '/'); tail = strrchr(file, '/');
if (tail != NULL) if (tail != NULL)
strbuf_add(&template, file, tail - file + 1); strbuf_add(&filename_template, file, tail - file + 1);
strbuf_addstr(&template, "git-interpret-trailers-XXXXXX"); strbuf_addstr(&filename_template, "git-interpret-trailers-XXXXXX");
trailers_tempfile = xmks_tempfile_m(template.buf, st.st_mode); trailers_tempfile = xmks_tempfile_m(filename_template.buf, st.st_mode);
strbuf_release(&template); strbuf_release(&filename_template);
outfile = fdopen_tempfile(trailers_tempfile, "w"); outfile = fdopen_tempfile(trailers_tempfile, "w");
if (!outfile) if (!outfile)
die_errno(_("could not open temporary file")); die_errno(_("could not open temporary file"));

Просмотреть файл

@ -195,10 +195,10 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
static struct cache_entry *dup_entry(const struct cache_entry *ce) static struct cache_entry *dup_entry(const struct cache_entry *ce)
{ {
unsigned int size = ce_size(ce); unsigned int size = ce_size(ce);
struct cache_entry *new = xmalloc(size); struct cache_entry *new_entry = xmalloc(size);
memcpy(new, ce, size); memcpy(new_entry, ce, size);
return new; return new_entry;
} }
static void add_entry(struct unpack_trees_options *o, static void add_entry(struct unpack_trees_options *o,

Просмотреть файл

@ -22,7 +22,7 @@ void walker_say(struct walker *walker, const char *fmt, ...)
static void report_missing(const struct object *obj) static void report_missing(const struct object *obj)
{ {
fprintf(stderr, "Cannot obtain needed %s %s\n", fprintf(stderr, "Cannot obtain needed %s %s\n",
obj->type ? typename(obj->type): "object", obj->type ? type_name(obj->type): "object",
oid_to_hex(&obj->oid)); oid_to_hex(&obj->oid));
if (!is_null_oid(&current_commit_oid)) if (!is_null_oid(&current_commit_oid))
fprintf(stderr, "while processing commit %s.\n", fprintf(stderr, "while processing commit %s.\n",
@ -134,7 +134,7 @@ static int process_object(struct walker *walker, struct object *obj)
} }
return error("Unable to determine requirements " return error("Unable to determine requirements "
"of type %s for %s", "of type %s for %s",
typename(obj->type), oid_to_hex(&obj->oid)); type_name(obj->type), oid_to_hex(&obj->oid));
} }
static int process(struct walker *walker, struct object *obj) static int process(struct walker *walker, struct object *obj)

Просмотреть файл

@ -445,21 +445,21 @@ FILE *fopen_or_warn(const char *path, const char *mode)
return NULL; return NULL;
} }
int xmkstemp(char *template) int xmkstemp(char *filename_template)
{ {
int fd; int fd;
char origtemplate[PATH_MAX]; char origtemplate[PATH_MAX];
strlcpy(origtemplate, template, sizeof(origtemplate)); strlcpy(origtemplate, filename_template, sizeof(origtemplate));
fd = mkstemp(template); fd = mkstemp(filename_template);
if (fd < 0) { if (fd < 0) {
int saved_errno = errno; int saved_errno = errno;
const char *nonrelative_template; const char *nonrelative_template;
if (strlen(template) != strlen(origtemplate)) if (strlen(filename_template) != strlen(origtemplate))
template = origtemplate; filename_template = origtemplate;
nonrelative_template = absolute_path(template); nonrelative_template = absolute_path(filename_template);
errno = saved_errno; errno = saved_errno;
die_errno("Unable to create temporary file '%s'", die_errno("Unable to create temporary file '%s'",
nonrelative_template); nonrelative_template);
@ -481,7 +481,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
static const int num_letters = 62; static const int num_letters = 62;
uint64_t value; uint64_t value;
struct timeval tv; struct timeval tv;
char *template; char *filename_template;
size_t len; size_t len;
int fd, count; int fd, count;
@ -503,16 +503,16 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
*/ */
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
value = ((size_t)(tv.tv_usec << 16)) ^ tv.tv_sec ^ getpid(); value = ((size_t)(tv.tv_usec << 16)) ^ tv.tv_sec ^ getpid();
template = &pattern[len - 6 - suffix_len]; filename_template = &pattern[len - 6 - suffix_len];
for (count = 0; count < TMP_MAX; ++count) { for (count = 0; count < TMP_MAX; ++count) {
uint64_t v = value; uint64_t v = value;
/* Fill in the random bits. */ /* Fill in the random bits. */
template[0] = letters[v % num_letters]; v /= num_letters; filename_template[0] = letters[v % num_letters]; v /= num_letters;
template[1] = letters[v % num_letters]; v /= num_letters; filename_template[1] = letters[v % num_letters]; v /= num_letters;
template[2] = letters[v % num_letters]; v /= num_letters; filename_template[2] = letters[v % num_letters]; v /= num_letters;
template[3] = letters[v % num_letters]; v /= num_letters; filename_template[3] = letters[v % num_letters]; v /= num_letters;
template[4] = letters[v % num_letters]; v /= num_letters; filename_template[4] = letters[v % num_letters]; v /= num_letters;
template[5] = letters[v % num_letters]; v /= num_letters; filename_template[5] = letters[v % num_letters]; v /= num_letters;
fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode); fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
if (fd >= 0) if (fd >= 0)
@ -541,21 +541,21 @@ int git_mkstemp_mode(char *pattern, int mode)
return git_mkstemps_mode(pattern, 0, mode); return git_mkstemps_mode(pattern, 0, mode);
} }
int xmkstemp_mode(char *template, int mode) int xmkstemp_mode(char *filename_template, int mode)
{ {
int fd; int fd;
char origtemplate[PATH_MAX]; char origtemplate[PATH_MAX];
strlcpy(origtemplate, template, sizeof(origtemplate)); strlcpy(origtemplate, filename_template, sizeof(origtemplate));
fd = git_mkstemp_mode(template, mode); fd = git_mkstemp_mode(filename_template, mode);
if (fd < 0) { if (fd < 0) {
int saved_errno = errno; int saved_errno = errno;
const char *nonrelative_template; const char *nonrelative_template;
if (!template[0]) if (!filename_template[0])
template = origtemplate; filename_template = origtemplate;
nonrelative_template = absolute_path(template); nonrelative_template = absolute_path(filename_template);
errno = saved_errno; errno = saved_errno;
die_errno("Unable to create temporary file '%s'", die_errno("Unable to create temporary file '%s'",
nonrelative_template); nonrelative_template);