Skip to content

Commit

Permalink
Merge branch 'bw/c-plus-plus'
Browse files Browse the repository at this point in the history
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
  ...
  • Loading branch information
gitster committed Mar 6, 2018
2 parents c14d5f9 + efdfe11 commit 169c9c0
Show file tree
Hide file tree
Showing 63 changed files with 663 additions and 662 deletions.
122 changes: 61 additions & 61 deletions apply.c
Expand Up @@ -2301,7 +2301,7 @@ static void update_pre_post_images(struct image *preimage,
size_t len, size_t postlen)
{
int i, ctx, reduced;
char *new, *old, *fixed;
char *new_buf, *old_buf, *fixed;
struct image fixed_preimage;

/*
Expand All @@ -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
* in place (postlen==0) or not.
*/
old = postimage->buf;
old_buf = postimage->buf;
if (postlen)
new = postimage->buf = xmalloc(postlen);
new_buf = postimage->buf = xmalloc(postlen);
else
new = old;
new_buf = old_buf;
fixed = preimage->buf;

for (i = reduced = ctx = 0; i < postimage->nr; i++) {
size_t l_len = postimage->line[i].len;
if (!(postimage->line[i].flag & LINE_COMMON)) {
/* an added line -- no counterparts in preimage */
memmove(new, old, l_len);
old += l_len;
new += l_len;
memmove(new_buf, old_buf, l_len);
old_buf += l_len;
new_buf += l_len;
continue;
}

/* 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 */
while (ctx < preimage->nr &&
Expand All @@ -2365,29 +2365,29 @@ static void update_pre_post_images(struct image *preimage,

/* and copy it in, while fixing the line length */
l_len = preimage->line[ctx].len;
memcpy(new, fixed, l_len);
new += l_len;
memcpy(new_buf, fixed, l_len);
new_buf += l_len;
fixed += l_len;
postimage->line[i].len = l_len;
ctx++;
}

if (postlen
? postlen < new - postimage->buf
: postimage->len < new - postimage->buf)
? postlen < new_buf - postimage->buf
: postimage->len < new_buf - postimage->buf)
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 */
postimage->len = new - postimage->buf;
postimage->len = new_buf - postimage->buf;
postimage->nr -= reduced;
}

static int line_by_line_fuzzy_match(struct image *img,
struct image *preimage,
struct image *postimage,
unsigned long try,
int try_lno,
unsigned long current,
int current_lno,
int preimage_limit)
{
int i;
Expand All @@ -2404,9 +2404,9 @@ static int line_by_line_fuzzy_match(struct image *img,

for (i = 0; i < preimage_limit; i++) {
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))
return 0;
if (preimage->line[i].flag & LINE_COMMON)
Expand Down Expand Up @@ -2443,7 +2443,7 @@ static int line_by_line_fuzzy_match(struct image *img,
*/
extra_chars = preimage_end - preimage_eof;
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);
fixed_buf = strbuf_detach(&fixed, &fixed_len);
update_pre_post_images(preimage, postimage,
Expand All @@ -2455,8 +2455,8 @@ static int match_fragment(struct apply_state *state,
struct image *img,
struct image *preimage,
struct image *postimage,
unsigned long try,
int try_lno,
unsigned long current,
int current_lno,
unsigned ws_rule,
int match_beginning, int match_end)
{
Expand All @@ -2466,12 +2466,12 @@ static int match_fragment(struct apply_state *state,
size_t fixed_len, postlen;
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.
*/
preimage_limit = preimage->nr;
if (match_end && (preimage->nr + try_lno != img->nr))
if (match_end && (preimage->nr + current_lno != img->nr))
return 0;
} else if (state->ws_error_action == correct_ws_error &&
(ws_rule & WS_BLANK_AT_EOF)) {
Expand All @@ -2482,7 +2482,7 @@ static int match_fragment(struct apply_state *state,
* match with img, and the remainder of the preimage
* must be blank.
*/
preimage_limit = img->nr - try_lno;
preimage_limit = img->nr - current_lno;
} else {
/*
* The hunk extends beyond the end of the img and
Expand All @@ -2492,27 +2492,27 @@ static int match_fragment(struct apply_state *state,
return 0;
}

if (match_beginning && try_lno)
if (match_beginning && current_lno)
return 0;

/* Quick hash check */
for (i = 0; i < preimage_limit; i++)
if ((img->line[try_lno + i].flag & LINE_PATCHED) ||
(preimage->line[i].hash != img->line[try_lno + i].hash))
if ((img->line[current_lno + i].flag & LINE_PATCHED) ||
(preimage->line[i].hash != img->line[current_lno + i].hash))
return 0;

if (preimage_limit == preimage->nr) {
/*
* Do we have an exact match? If we were told to match
* at the end, size must be exactly at try+fragsize,
* otherwise try+fragsize must be still within the preimage,
* at the end, size must be exactly at current+fragsize,
* otherwise current+fragsize must be still within the preimage,
* and either case, the old piece should match the preimage
* exactly.
*/
if ((match_end
? (try + preimage->len == img->len)
: (try + preimage->len <= img->len)) &&
!memcmp(img->buf + try, preimage->buf, preimage->len))
? (current + preimage->len == img->len)
: (current + preimage->len <= img->len)) &&
!memcmp(img->buf + current, preimage->buf, preimage->len))
return 1;
} else {
/*
Expand Down Expand Up @@ -2543,7 +2543,7 @@ static int match_fragment(struct apply_state *state,
*/
if (state->ws_ignore_action == ignore_ws_change)
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)
return 0;
Expand Down Expand Up @@ -2577,10 +2577,10 @@ static int match_fragment(struct apply_state *state,
*/
strbuf_init(&fixed, preimage->len + 1);
orig = preimage->buf;
target = img->buf + try;
target = img->buf + current;
for (i = 0; i < preimage_limit; i++) {
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;
struct strbuf tgtfix;
int match;
Expand Down Expand Up @@ -2666,8 +2666,8 @@ static int find_pos(struct apply_state *state,
int match_beginning, int match_end)
{
int i;
unsigned long backwards, forwards, try;
int backwards_lno, forwards_lno, try_lno;
unsigned long backwards, forwards, current;
int backwards_lno, forwards_lno, current_lno;

/*
* If match_beginning or match_end is specified, there is no
Expand All @@ -2687,25 +2687,25 @@ static int find_pos(struct apply_state *state,
if ((size_t) line > img->nr)
line = img->nr;

try = 0;
current = 0;
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
* that to the smart and beautiful people. I'm simple and stupid.
*/
backwards = try;
backwards = current;
backwards_lno = line;
forwards = try;
forwards = current;
forwards_lno = line;
try_lno = line;
current_lno = line;

for (i = 0; ; i++) {
if (match_fragment(state, img, preimage, postimage,
try, try_lno, ws_rule,
current, current_lno, ws_rule,
match_beginning, match_end))
return try_lno;
return current_lno;

again:
if (backwards_lno == 0 && forwards_lno == img->nr)
Expand All @@ -2718,17 +2718,17 @@ static int find_pos(struct apply_state *state,
}
backwards_lno--;
backwards -= img->line[backwards_lno].len;
try = backwards;
try_lno = backwards_lno;
current = backwards;
current_lno = backwards_lno;
} else {
if (forwards_lno == img->nr) {
i++;
goto again;
}
forwards += img->line[forwards_lno].len;
forwards_lno++;
try = forwards;
try_lno = forwards_lno;
current = forwards;
current_lno = forwards_lno;
}

}
Expand Down Expand Up @@ -4163,30 +4163,30 @@ static void show_mode_change(struct patch *p, int show_name)
static void show_rename_copy(struct patch *p)
{
const char *renamecopy = p->is_rename ? "rename" : "copy";
const char *old, *new;
const char *old_name, *new_name;

/* Find common prefix */
old = p->old_name;
new = p->new_name;
old_name = p->old_name;
new_name = p->new_name;
while (1) {
const char *slash_old, *slash_new;
slash_old = strchr(old, '/');
slash_new = strchr(new, '/');
slash_old = strchr(old_name, '/');
slash_new = strchr(new_name, '/');
if (!slash_old ||
!slash_new ||
slash_old - old != slash_new - new ||
memcmp(old, new, slash_new - new))
slash_old - old_name != slash_new - new_name ||
memcmp(old_name, new_name, slash_new - new_name))
break;
old = slash_old + 1;
new = slash_new + 1;
old_name = slash_old + 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
*/
if (old != p->old_name)
if (old_name != p->old_name)
printf(" %s %.*s{%s => %s} (%d%%)\n", renamecopy,
(int)(old - p->old_name), p->old_name,
old, new, p->score);
(int)(old_name - p->old_name), p->old_name,
old_name, new_name, p->score);
else
printf(" %s %s => %s (%d%%)\n", renamecopy,
p->old_name, p->new_name, p->score);
Expand Down
33 changes: 17 additions & 16 deletions blame.c
Expand Up @@ -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
* that passes blame to the parent. Maintain best_so_far the best split
* so far, by comparing this and best_so_far and copying this into
* 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 so
* far, by comparing potential and best_so_far and copying potential into
* bst_so_far as needed.
*/
static void copy_split_if_better(struct blame_scoreboard *sb,
struct blame_entry *best_so_far,
struct blame_entry *this)
struct blame_entry *potential)
{
int i;

if (!this[1].suspect)
if (!potential[1].suspect)
return;
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;
}

for (i = 0; i < 3; i++)
blame_origin_incref(this[i].suspect);
blame_origin_incref(potential[i].suspect);
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]));
}

/*
Expand All @@ -1046,12 +1047,12 @@ static void handle_split(struct blame_scoreboard *sb,
if (ent->num_lines <= tlno)
return;
if (tlno < same) {
struct blame_entry this[3];
struct blame_entry potential[3];
tlno += ent->s_lno;
same += ent->s_lno;
split_overlap(this, ent, tlno, plno, same, parent);
copy_split_if_better(sb, split, this);
decref_split(this);
split_overlap(potential, ent, tlno, plno, same, parent);
copy_split_if_better(sb, split, potential);
decref_split(potential);
}
}

Expand Down Expand Up @@ -1273,7 +1274,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
struct diff_filepair *p = diff_queued_diff.queue[i];
struct blame_origin *norigin;
mmfile_t file_p;
struct blame_entry this[3];
struct blame_entry potential[3];

if (!DIFF_FILE_VALID(p->one))
continue; /* does not exist in parent */
Expand All @@ -1292,10 +1293,10 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,

for (j = 0; j < num_ents; j++) {
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,
this);
decref_split(this);
potential);
decref_split(potential);
}
blame_origin_decref(norigin);
}
Expand Down
4 changes: 2 additions & 2 deletions builtin/cat-file.c
Expand Up @@ -76,7 +76,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
buf = NULL;
switch (opt) {
case 't':
oi.typename = &sb;
oi.type_name = &sb;
if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (sb.len) {
Expand Down Expand Up @@ -229,7 +229,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
if (data->mark_query)
data->info.typep = &data->type;
else
strbuf_addstr(sb, typename(data->type));
strbuf_addstr(sb, type_name(data->type));
} else if (is_atom("objectsize", atom, len)) {
if (data->mark_query)
data->info.sizep = &data->size;
Expand Down

0 comments on commit 169c9c0

Please sign in to comment.