use C99 declaration of variable in for() loop
PATCH 1/1 use C99 declaration of variable in for() loop
With the exception of cbtree.c, which would need initial reworking to remove the usage of goto, it expands the use of variable scope reduction in for loops as permitted by the C99 standard, which was first introduced in the git codebase with commit 44ba10d6.
---
Based on top of next 049e64211f79bdc0639badd06a79810dd7b3b85c
add-interactive.c | 29 ++++----- add-patch.c | 16 +++-- advice.c | 11 ++-- apply.c | 39 +++++------- archive-tar.c | 10 ++- archive.c | 11 +--- attr.c | 24 +++---- base85.c | 3 +- bisect.c | 23 +++---- blame.c | 92 ++++++++++----------------- bloom.c | 17 ++--- branch.c | 3 +- builtin/add.c | 15 +++-- builtin/am.c | 3 +- builtin/annotate.c | 3 +- builtin/archive.c | 4 +- builtin/bisect.c | 7 +-- builtin/blame.c | 14 ++--- builtin/branch.c | 15 ++--- builtin/bugreport.c | 4 +- builtin/cat-file.c | 8 +-- builtin/check-attr.c | 3 +- builtin/check-ignore.c | 4 +- builtin/check-mailmap.c | 3 +- builtin/checkout--worker.c | 4 +- builtin/checkout-index.c | 7 +-- builtin/checkout.c | 6 +- builtin/clean.c | 17 +++-- builtin/clone.c | 17 ++--- builtin/commit-tree.c | 3 +- builtin/commit.c | 11 ++-- builtin/config.c | 3 +- builtin/count-objects.c | 3 +- builtin/credential-cache--daemon.c | 8 +-- builtin/describe.c | 4 +- builtin/diff-index.c | 3 +- builtin/diff.c | 7 +-- builtin/fast-export.c | 24 +++---- builtin/fast-import.c | 56 +++++++---------- builtin/fetch-pack.c | 4 +- builtin/fetch.c | 39 ++++-------- builtin/for-each-repo.c | 7 +-- builtin/fsck.c | 22 +++---- builtin/fsmonitor--daemon.c | 14 +---- builtin/gc.c | 28 +++------ builtin/grep.c | 24 +++---- builtin/hash-object.c | 3 +- builtin/help.c | 14 ++--- builtin/hook.c | 3 +- builtin/index-pack.c | 13 ++-- builtin/interpret-trailers.c | 3 +- builtin/log.c | 17 ++--- builtin/ls-files.c | 14 ++--- builtin/ls-tree.c | 8 +-- builtin/mailsplit.c | 6 +- builtin/merge-base.c | 20 +++--- builtin/merge-index.c | 3 +- builtin/merge-tree.c | 9 +-- builtin/merge.c | 36 +++++------ builtin/name-rev.c | 11 ++-- builtin/notes.c | 4 +- builtin/pack-objects.c | 49 +++++---------- builtin/pack-redundant.c | 3 +- builtin/pull.c | 6 +- builtin/push.c | 4 +- builtin/range-diff.c | 4 +- builtin/read-tree.c | 4 +- builtin/receive-pack.c | 46 +++++--------- builtin/reflog.c | 16 +++-- builtin/remote.c | 37 +++++------ builtin/repack.c | 24 +++---- builtin/replace.c | 10 ++- builtin/replay.c | 4 +- builtin/rerere.c | 3 +- builtin/reset.c | 7 +-- builtin/rev-list.c | 3 +- builtin/rm.c | 10 ++- builtin/send-pack.c | 3 +- builtin/shortlog.c | 4 +- builtin/show-branch.c | 4 +- builtin/sparse-checkout.c | 11 ++-- builtin/stash.c | 27 +++----- builtin/submodule--helper.c | 40 +++++------- builtin/tag.c | 3 +- builtin/unpack-objects.c | 9 +-- builtin/update-index.c | 9 +-- builtin/var.c | 6 +- builtin/verify-pack.c | 3 +- builtin/worktree.c | 12 ++-- bulk-checkin.c | 7 +-- bundle-uri.c | 6 +- bundle.c | 21 +++---- cache-tree.c | 21 +++---- chunk-format.c | 4 +- color.c | 9 +-- column.c | 22 +++---- combine-diff.c | 18 +++--- commit-graph.c | 52 ++++++---------- commit-reach.c | 26 +++----- commit.c | 23 +++---- compat/fsmonitor/fsm-health-win32.c | 4 +- compat/fsmonitor/fsm-listen-darwin.c | 8 +-- compat/mingw.c | 6 +- compat/simple-ipc/ipc-unix-socket.c | 11 +--- compat/simple-ipc/ipc-win32.c | 3 +- compat/strcasestr.c | 7 +-- compat/terminal.c | 7 +-- compat/unsetenv.c | 4 +- config.c | 15 ++--- connect.c | 15 ++--- connected.c | 4 +- convert.c | 18 ++---- credential.c | 12 +--- daemon.c | 21 +++---- date.c | 3 +- decorate.c | 6 +- delta-islands.c | 27 +++----- diagnose.c | 3 +- diff-delta.c | 6 +- diff-lib.c | 4 +- diff.c | 93 ++++++++++------------------ diff.h | 4 +- diffcore-break.c | 7 +-- diffcore-delta.c | 3 +- diffcore-order.c | 11 ++-- diffcore-rename.c | 17 +++-- dir.c | 57 +++++++---------- entry.c | 4 +- environment.c | 4 +- ewah/bitmap.c | 21 +++---- ewah/ewah_io.c | 3 +- fetch-pack.c | 40 ++++-------- fmt-merge-msg.c | 14 ++--- fsck.c | 19 ++---- fsmonitor.c | 9 ++- git.c | 16 ++--- gpg-interface.c | 20 +++--- graph.c | 51 +++++---------- grep.c | 21 +++---- hash-lookup.c | 4 +- hashmap.c | 4 +- help.c | 34 ++++------ hex.c | 9 +-- http-backend.c | 10 ++- http-push.c | 10 +-- http-walker.c | 3 +- http.c | 13 ++-- ident.c | 12 +--- imap-send.c | 4 +- json-writer.c | 15 ++--- khash.h | 8 +-- line-log.c | 43 +++++-------- linear-assignment.c | 4 +- list-objects-filter-options.c | 11 +--- list-objects-filter.c | 14 ++--- list-objects.c | 17 ++--- log-tree.c | 10 ++- ls-refs.c | 4 +- mailinfo.c | 25 +++----- mem-pool.c | 5 +- merge-ll.c | 10 ++- merge-ort.c | 62 +++++++------------ merge-recursive.c | 27 +++----- merge.c | 8 +-- midx.c | 62 ++++++------------- name-hash.c | 19 ++---- negotiator/skipping.c | 3 +- notes-merge.c | 11 ++-- notes-utils.c | 6 +- notes.c | 30 +++------ object-file.c | 40 ++++-------- object-name.c | 55 +++++----------- object.c | 42 ++++--------- oid-array.c | 14 ++--- pack-bitmap-write.c | 25 +++----- pack-bitmap.c | 51 ++++++--------- pack-objects.c | 12 ++-- pack-revindex.c | 8 +-- pack-write.c | 13 ++-- packfile.c | 82 ++++++++---------------- pager.c | 3 +- parallel-checkout.c | 7 +-- parse-options.c | 8 +-- path.c | 11 ++-- pathspec.c | 26 ++++---- pkt-line.c | 3 +- pretty.c | 25 +++----- prio-queue.c | 12 ++-- promisor-remote.c | 6 +- quote.c | 11 +--- reachable.c | 3 +- read-cache.c | 62 ++++++------------- ref-filter.c | 50 +++++---------- reflog-walk.c | 15 ++--- refs.c | 58 ++++++----------- refs/debug.c | 3 +- refs/files-backend.c | 15 ++--- refs/packed-backend.c | 9 +-- refs/ref-cache.c | 16 +---- refs/reftable-backend.c | 7 +-- refspec.c | 6 +- reftable/basics.c | 3 +- reftable/block.c | 3 +- reftable/merged_test.c | 3 +- reftable/pq_test.c | 3 +- reftable/readwrite_test.c | 16 ++--- reftable/record.c | 4 +- reftable/record_test.c | 4 +- reftable/refname_test.c | 3 +- reftable/stack.c | 12 ++-- reftable/stack_test.c | 28 ++++----- remote-curl.c | 6 +- remote.c | 84 +++++++++---------------- rerere.c | 17 ++--- revision.c | 69 +++++++-------------- run-command.c | 21 ++----- scalar.c | 7 +-- send-pack.c | 10 ++- sequencer.c | 40 +++++------- serve.c | 7 +-- server-info.c | 12 ++-- setup.c | 11 +--- shallow.c | 13 ++-- shell.c | 3 +- sideband.c | 11 +--- sparse-index.c | 10 +-- split-index.c | 16 +---- strbuf.c | 20 +++--- string-list.c | 12 ++-- strvec.c | 3 +- submodule.c | 28 +++------ t/helper/test-bloom.c | 7 +-- t/helper/test-dump-cache-tree.c | 3 +- t/helper/test-dump-fsmonitor.c | 3 +- t/helper/test-dump-split-index.c | 3 +- t/helper/test-example-decorate.c | 4 +- t/helper/test-fake-ssh.c | 3 +- t/helper/test-find-pack.c | 3 +- t/helper/test-fsmonitor-client.c | 3 +- t/helper/test-lazy-init-name-hash.c | 4 +- t/helper/test-mergesort.c | 25 +++----- t/helper/test-pack-mtimes.c | 3 +- t/helper/test-parse-options.c | 3 +- t/helper/test-parse-pathspec-file.c | 4 +- t/helper/test-path-utils.c | 12 ++-- t/helper/test-pkt-line.c | 3 +- t/helper/test-proc-receive.c | 4 +- t/helper/test-reach.c | 10 ++- t/helper/test-read-cache.c | 4 +- t/helper/test-read-midx.c | 3 +- t/helper/test-ref-store.c | 3 +- t/helper/test-repository.c | 3 +- t/helper/test-rot13-filter.c | 10 ++- t/helper/test-run-command.c | 4 +- t/helper/test-simple-ipc.c | 18 ++---- t/helper/test-string-list.c | 3 +- t/helper/test-submodule.c | 3 +- t/helper/test-tool.c | 7 +-- t/helper/test-trace2.c | 16 ++--- t/helper/test-wildmatch.c | 3 +- t/helper/test-write-cache.c | 4 +- t/unit-tests/test-lib.c | 4 +- tmp-objdir.c | 3 +- trace2/tr2_cfg.c | 6 +- trace2/tr2_ctr.c | 15 +---- trace2/tr2_sid.c | 3 +- trace2/tr2_sysenv.c | 8 +-- trace2/tr2_tmr.c | 15 +---- trailer.c | 28 +++------ transport-helper.c | 31 ++++------ transport.c | 29 +++------ tree-diff.c | 3 +- tree-walk.c | 11 ++-- unpack-trees.c | 48 +++++--------- upload-pack.c | 33 +++------- userdiff.c | 3 +- version.c | 3 +- versioncmp.c | 6 +- walker.c | 4 +- worktree.c | 8 +-- wrapper.c | 4 +- ws.c | 3 +- wt-status.c | 51 ++++++--------- xdiff-interface.c | 6 +- xdiff/xdiffi.c | 19 ++---- xdiff/xemit.c | 8 +-- xdiff/xhistogram.c | 4 +- xdiff/xmerge.c | 3 +- xdiff/xpatience.c | 3 +- 289 files changed, 1452 insertions(+), 2766 deletions(-)
add-interactive.c +13 -16
@@ -233,7 +233,7 @@ struct list_options {static void list (struct add_i_state *s,struct string_list *list,int *selected,struct list_options *opts) { -int i, last_lf =0 ; +int last_lf =0 ;if (!list->nr)return ;
@@ -242,7 +242,7 @@ static void list(struct add_i_state *s, struct string_list *list, int *selected,color_fprintf_ln (stdout, s->header_color,"%s" , opts->header); -for (i =0 ; i < list->nr; i++) { +for (int i =0 ; i < list->nr; i++) { opts->print_item (i, selected ? selected[i] :0 , list->items + i, opts->print_item_data);
@@ -467,14 +467,13 @@ static void collect_changes_cb(struct diff_queue_struct *q, {struct collection_status *s = data;struct diffstat_t stat = {0 }; -int i;if (!q->nr)return ;compute_diffstat (options, &stat, q); -for (i =0 ; i < stat.nr; i++) { +for (int i =0 ; i < stat.nr; i++) {const char *name = stat.files[i]->name;int hash =strhash (name);struct pathname_entry *entry;
@@ -535,7 +534,6 @@ static int get_modified_files(struct repository *r,int is_initial = !resolve_ref_unsafe ("HEAD" ,RESOLVE_REF_READING , &head_oid,NULL );struct collection_status s = {0 }; -int i;discard_index (r->index);if (repo_read_index_preload (r, ps,0 ) <0 )
@@ -545,7 +543,7 @@ static int get_modified_files(struct repository *r, s.files = &files->items;hashmap_init (&s.file_map, pathname_entry_cmp,NULL ,0 ); -for (i =0 ; i <2 ; i++) { +for (int i =0 ; i <2 ; i++) {struct rev_info rev;struct setup_revision_opt opt = {0 };
@@ -678,7 +676,7 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps, struct list_and_choose_options *opts) {int res =0 , fd; -size_t count, i; +size_t count;struct lock_file index_lock;if (get_modified_files (s->r,WORKTREE_ONLY , files, ps,NULL ,NULL ) <0 )
@@ -702,7 +700,7 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps,return -1 ; } -for (i =0 ; i < files->items.nr; i++) { +for (size_t i =0 ; i < files->items.nr; i++) {const char *name = files->items.items[i].string;struct stat st;
@@ -733,9 +731,9 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps,static void revert_from_diff (struct diff_queue_struct *q, struct diff_options *opt, void *data UNUSED) { -int i, add_flags =ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ; +int add_flags =ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ; -for (i =0 ; i < q->nr; i++) { +for (int i =0 ; i < q->nr; i++) {struct diff_filespec *one = q->queue[i]->one;struct cache_entry *ce;
@@ -758,7 +756,7 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps, struct list_and_choose_options *opts) {int res =0 , fd; -size_t count, i, j; +size_t count, j;struct object_id oid; int is_initial = !resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &oid,
@@ -799,7 +797,7 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps, }ALLOC_ARRAY (paths, count +1 ); -for (i = j =0 ; i < files->items.nr; i++) +for (size_t i = j =0 ; i < files->items.nr; i++)if (files->selected[i]) paths[j++] = files->items.items[i].string; paths[j] =NULL ;
@@ -843,7 +841,6 @@ static int get_untracked_files(struct repository *r, const struct pathspec *ps) {struct dir_struct dir = {0 }; -size_t i;struct strbuf buf =STRBUF_INIT ;if (repo_read_index (r) <0 )
@@ -854,7 +851,7 @@ static int get_untracked_files(struct repository *r,add_pattern_list (&dir,EXC_CMDL ,"--exclude option" );fill_directory (&dir, r->index, ps); -for (i =0 ; i < dir.nr; i++) { +for (size_t i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];if (index_name_is_other (r->index, ent->name, ent->len)) {
@@ -874,7 +871,7 @@ static int run_add_untracked(struct add_i_state *s, const struct pathspec *ps, {struct print_file_item_data *d = opts->list_opts.print_item_data;int res =0 , fd; -size_t count, i; +size_t count;struct lock_file index_lock;if (get_untracked_files (s->r, files, ps) <0 )
@@ -898,7 +895,7 @@ static int run_add_untracked(struct add_i_state *s, const struct pathspec *ps, goto finish_add_untracked; } -for (i =0 ; i < files->items.nr; i++) { +for (size_t i =0 ; i < files->items.nr; i++) {const char *name = files->items.items[i].string;if (files->selected[i] &&add_file_to_index (s->r->index, name,0 ) <0 ) {
add-patch.c +7 -9
@@ -275,13 +275,11 @@ struct add_p_state {static void add_p_state_clear (struct add_p_state *s) { -size_t i; -strbuf_release (&s->answer);strbuf_release (&s->buf);strbuf_release (&s->plain);strbuf_release (&s->colored); -for (i =0 ; i < s->file_diff_nr; i++) +for (size_t i =0 ; i < s->file_diff_nr; i++)free (s->file_diff[i].hunk);free (s->file_diff);clear_add_i_state (&s->s);
@@ -407,7 +405,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)struct strbuf *plain = &s->plain, *colored =NULL ;struct child_process cp =CHILD_PROCESS_INIT ;char *p, *pend, *colored_p =NULL , *colored_pend =NULL , marker ='\0' ; -size_t file_diff_alloc =0 , i, color_arg_index; +size_t file_diff_alloc =0 , color_arg_index;struct file_diff *file_diff =NULL ;struct hunk *hunk =NULL ;int res;
@@ -427,7 +425,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)/* Use `--no-color` explicitly, just in case `diff.color = always`. */ strvec_pushl (&args,"--no-color" ,"--ignore-submodules=dirty" ,"-p" ,"--" ,NULL ); -for (i =0 ; i < ps->nr; i++) +for (size_t i =0 ; i < ps->nr; i++)strvec_push (&args, ps->items[i].original);setup_child_process (s, &cp,NULL );
@@ -878,12 +876,12 @@ static void reassemble_patch(struct add_p_state *s, struct strbuf *out) {struct hunk *hunk; -size_t save_len = s->plain.len, i; +size_t save_len = s->plain.len;ssize_t delta =0 ;render_diff_header (s, file_diff,0 , out); -for (i = file_diff->mode_change; i < file_diff->hunk_nr; i++) { +for (size_t i = file_diff->mode_change; i < file_diff->hunk_nr; i++) {struct hunk merged = {0 }; hunk = file_diff->hunk + i;
@@ -1722,7 +1720,7 @@ int run_add_p(struct repository *r, enum add_p_mode mode,struct add_p_state s = { { r },STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT }; -size_t i, binary_count =0 ; +size_t binary_count =0 ;init_add_i_state (&s.s, r);
@@ -1761,7 +1759,7 @@ int run_add_p(struct repository *r, enum add_p_mode mode,return -1 ; } -for (i =0 ; i < s.file_diff_nr; i++) +for (size_t i =0 ; i < s.file_diff_nr; i++)if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr) binary_count++;else if (patch_update_file (&s, s.file_diff + i))
advice.c +4 -7
@@ -93,14 +93,14 @@ static void vadvise(const char *advice, int display_instructions, const char *key, va_list params) { struct strbuf buf = STRBUF_INIT; -const char *cp, *np; +const char *np;strbuf_vaddf (&buf, advice, params);if (display_instructions)strbuf_addf (&buf, turn_off_instructions, key); -for (cp = buf.buf; *cp; cp = np) { +for (const char *cp = buf.buf; *cp; cp = np) { np =strchrnul (cp,'\n' ); fprintf(stderr, _("%shint: %.*s%s\n"), advise_get_color(ADVICE_COLOR_HINT),
@@ -147,7 +147,6 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...)int git_default_advice_config (const char *var,const char *value) {const char *k, *slot_name; -int i;if (!strcmp (var,"color.advice" )) { advice_use_color =git_config_colorbool (var, value);
@@ -166,7 +165,7 @@ int git_default_advice_config(const char *var, const char *value)if (!skip_prefix (var,"advice." , &k))return 0 ; -for (i =0 ; i <ARRAY_SIZE (advice_setting); i++) { +for (int i =0 ; i <ARRAY_SIZE (advice_setting); i++) {if (strcasecmp (k, advice_setting[i].key))continue ; advice_setting[i].level =git_config_bool (var, value)
@@ -180,9 +179,7 @@ int git_default_advice_config(const char *var, const char *value)void list_config_advices (struct string_list *list,const char *prefix) { -int i; - -for (i =0 ; i <ARRAY_SIZE (advice_setting); i++) +for (int i =0 ; i <ARRAY_SIZE (advice_setting); i++)list_config_item (list, prefix, advice_setting[i].key); }
apply.c +16 -23
@@ -504,7 +504,7 @@ static char *find_name_gnu(struct strbuf *root,static size_t sane_tz_len (const char *line,size_t len) { -const char *tz, *p; +const char *tz;if (len <strlen (" +0500" ) || line[len-strlen (" +0500" )] !=' ' )return 0 ;
@@ -513,7 +513,7 @@ static size_t sane_tz_len(const char *line, size_t len)if (tz[1 ] !='+' && tz[1 ] !='-' )return 0 ; -for (p = tz +2 ; p != line + len; p++) +for (const char *p = tz +2 ; p != line + len; p++)if (!isdigit (*p))return 0 ;
@@ -801,13 +801,13 @@ static int has_epoch_timestamp(const char *nameline)"^[0-2][0-9]:([0-5][0-9]):00(\\.0+)?" " " "([-+][0-2][0-9]:?[0-5][0-9])\n" ; -const char *timestamp =NULL , *cp, *colon; +const char *timestamp =NULL , *colon;static regex_t *stamp;regmatch_t m[10 ];int zoneoffset, epoch_hour, hour, minute;int status; -for (cp = nameline; *cp !='\n' ; cp++) { +for (const char *cp = nameline; *cp !='\n' ; cp++) {if (*cp =='\t' ) timestamp = cp +1 ; }
@@ -1144,13 +1144,12 @@ static const char *skip_tree_prefix(int p_value, int llen) {int nslash; -int i;if (!p_value)return (llen && line[0 ] =='/' ) ?NULL : line; nslash = p_value; -for (i =0 ; i < llen; i++) { +for (int i =0 ; i < llen; i++) {int ch = line[i];if (ch =='/' && --nslash <=0 )return (i ==0 ) ?NULL : &line[i +1 ];
@@ -1550,14 +1549,15 @@ static int find_header(struct apply_state *state,int *hdrsize, struct patch *patch) { - unsigned long offset, len; + unsigned long len; patch->is_toplevel_relative =0 ; patch->is_rename = patch->is_copy =0 ; patch->is_new = patch->is_delete =-1 ; patch->old_mode = patch->new_mode =0 ; patch->old_name = patch->new_name =NULL ; -for (offset =0 ; size >0 ; offset += len, size -= len, line += len, state->linenr++) { +for (unsigned long offset =0 ; size >0 ; offset += len, size -= len, + line += len, state->linenr++) {unsigned long nextlen; len =linelen (line, size);
@@ -2100,7 +2100,6 @@ static void add_name_limit(struct apply_state *state,static int use_patch (struct apply_state *state,struct patch *p) {const char *pathname = p->new_name ? p->new_name : p->old_name; -int i;/* Paths outside are not touched regardless of "--include" */ if (state->prefix && *state->prefix) {
@@ -2110,7 +2109,7 @@ static int use_patch(struct apply_state *state, struct patch *p) }/* See if it matches any of exclude/include rule */ -for (i =0 ; i < state->limit_by_name.nr; i++) { +for (int i =0 ; i < state->limit_by_name.nr; i++) {struct string_list_item *it = &state->limit_by_name.items[i];if (!wildmatch (it->string, pathname,0 ))return (it->util !=NULL );
@@ -2186,8 +2185,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si"Files " , NULL, }; -int i; -for (i =0 ; binhdr[i]; i++) { +for (int i =0 ; binhdr[i]; i++) {int len =strlen (binhdr[i]);if (len < size - hd && !memcmp (binhdr[i], buffer + hd, len)) {
@@ -4131,7 +4129,6 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)/* Build an index that contains just the files needed for a 3way merge */ static int build_fake_ancestor (struct apply_state *state,struct patch *list) { -struct patch *patch;struct index_state result =INDEX_STATE_INIT (state->repo);struct lock_file lock =LOCK_INIT ;int res;
@@ -4139,7 +4136,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)/* Once we start supporting the reverse patch, it may be * worth showing the new sha1 prefix, but until then... */ -for (patch = list; patch; patch = patch->next) { +for (struct patch *patch = list; patch; patch = patch->next) {struct object_id oid;struct cache_entry *ce;const char *name;
@@ -4270,9 +4267,7 @@ static void show_rename_copy(struct patch *p)static void summary_patch_list (struct patch *patch) { -struct patch *p; - -for (p = patch; p; p = p->next) { +for (struct patch *p = patch; p; p = p->next) {if (p->is_new)show_file_mode_name ("create" , p->new_mode, p->new_name);else if (p->is_delete)
@@ -4524,7 +4519,7 @@ static int create_one_file(struct apply_state *state,static int add_conflicted_stages_file (struct apply_state *state,struct patch *patch) { -int stage, namelen; +int namelen;unsigned mode;struct cache_entry *ce;
@@ -4534,7 +4529,7 @@ static int add_conflicted_stages_file(struct apply_state *state, mode = patch->new_mode ? patch->new_mode : (S_IFREG |0644 );remove_file_from_index (state->repo->index, patch->new_name); -for (stage =1 ; stage <4 ; stage++) { +for (int stage =1 ; stage <4 ; stage++) {if (is_null_oid (&patch->threeway_stage[stage -1 ]))continue ; ce =make_empty_cache_entry (state->repo->index, namelen);
@@ -4690,12 +4685,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)*/ static int write_out_results (struct apply_state *state,struct patch *list) { -int phase;int errs =0 ;struct patch *l;struct string_list cpath =STRING_LIST_INIT_DUP ; -for (phase =0 ; phase <2 ; phase++) { +for (int phase =0 ; phase <2 ; phase++) { l = list;while (l) {if (l->rejected)
@@ -4967,12 +4961,11 @@ int apply_all_patches(struct apply_state *state,const char **argv, int options) { - int i; int res;int errs =0 ;int read_stdin =1 ; -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {const char *arg = argv[i];char *to_free =NULL ;int fd;
archive-tar.c +4 -6
@@ -157,11 +157,11 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, const char *value, size_t valuelen) { size_t orig_len = sb->len; -size_t len, tmp; +size_t len;/* "%u %s=%s\n" */ len =1 +1 +strlen (keyword) +1 + valuelen +1 ; -for (tmp =1 ; len /10 >= tmp; tmp *=10 ) +for (size_t tmp =1 ; len /10 >= tmp; tmp *=10 ) len++;strbuf_grow (sb, len);
@@ -362,8 +362,7 @@ static int alloc_tar_filters;static struct archiver *find_tar_filter (const char *name,size_t len) { -int i; -for (i =0 ; i < nr_tar_filters; i++) { +for (int i =0 ; i < nr_tar_filters; i++) {struct archiver *ar = tar_filters[i];if (!xstrncmpz (ar->name, name, len))return ar;
@@ -531,7 +530,6 @@ static struct archiver tar_archiver = {void init_tar_archiver (void ) { -int i;register_archiver (&tar_archiver);tar_filter_config ("tar.tgz.command" , internal_gzip_command,NULL );
@@ -539,7 +537,7 @@ void init_tar_archiver(void)tar_filter_config ("tar.tar.gz.command" , internal_gzip_command,NULL );tar_filter_config ("tar.tar.gz.remote" ,"true" ,NULL );git_config (git_tar_config,NULL ); -for (i =0 ; i < nr_tar_filters; i++) { +for (int i =0 ; i < nr_tar_filters; i++) {/* omit any filters that never had a command configured */ if (tar_filters[i]->filter_command)register_archiver (tar_filters[i]);
archive.c +3 -8
@@ -308,7 +308,6 @@ int write_archive_entries(struct archiver_args *args,struct strbuf path_in_archive =STRBUF_INIT ;struct strbuf content =STRBUF_INIT ;struct object_id fake_oid; -int i;oidcpy (&fake_oid,null_oid ());
@@ -357,7 +356,7 @@ int write_archive_entries(struct archiver_args *args, context.bottom = next; } -for (i =0 ; i < args->extra_files.nr; i++) { +for (int i =0 ; i < args->extra_files.nr; i++) {struct string_list_item *item = args->extra_files.items + i;char *path = item->string;struct extra_file_info *info = item->util;
@@ -396,12 +395,10 @@ int write_archive_entries(struct archiver_args *args,static const struct archiver *lookup_archiver (const char *name) { -int i; -if (!name)return NULL ; -for (i =0 ; i < nr_archivers; i++) { +for (int i =0 ; i < nr_archivers; i++) {if (!strcmp (name, archivers[i]->name))return archivers[i]; }
@@ -784,9 +781,7 @@ static int match_extension(const char *filename, const char *ext)const char *archive_format_from_filename (const char *filename) { -int i; - -for (i =0 ; i < nr_archivers; i++) +for (int i =0 ; i < nr_archivers; i++)if (match_extension (filename, archivers[i]->name))return archivers[i]->name;return NULL ;
attr.c +7 -17
@@ -142,7 +142,6 @@ struct all_attrs_item {*/ static void all_attrs_init (struct attr_hashmap *map,struct attr_check *check) { -int i;unsigned int size;hashmap_lock (map);
@@ -178,7 +177,7 @@ static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)* This re-initialization can live outside of the locked region since * the attribute dictionary is no longer being accessed. */ -for (i =0 ; i < check->all_attrs_nr; i++) { +for (int i =0 ; i < check->all_attrs_nr; i++) { check->all_attrs[i].value =ATTR__UNKNOWN ; check->all_attrs[i].macro =NULL ; }
@@ -471,9 +470,8 @@ struct attr_stack {static void attr_stack_free (struct attr_stack *e) { -unsigned i;free (e->origin); -for (i =0 ; i < e->num_matches; i++) { +for (unsigned i =0 ; i < e->num_matches; i++) {struct match_attr *a = e->attrs[i];size_t j;
@@ -558,11 +556,9 @@ static void check_vector_remove(struct attr_check *check)/* Iterate through all attr_check instances and drop their stacks */ static void drop_all_attr_stacks (void ) { -int i; -vector_lock (); -for (i =0 ; i < check_vector.nr; i++) { +for (int i =0 ; i < check_vector.nr; i++) {drop_attr_stack (&check_vector.checks[i]->stack); }
@@ -1102,9 +1098,7 @@ static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);static int fill_one (struct all_attrs_item *all_attrs,const struct match_attr *a,int rem) { -size_t i; - -for (i = a->num_attr; rem >0 && i >0 ; i--) { +for (size_t i = a->num_attr; rem >0 && i >0 ; i--) {const struct git_attr *attr = a->state[i -1 ].attr;const char **n = &(all_attrs[attr->attr_nr].value);const char *v = a->state[i -1 ].setto;
@@ -1262,9 +1256,7 @@ static const char *interned_mode_string(unsigned int mode) { .val = 0120000 }, { .val = 0160000 }, }; -int i; - -for (i =0 ; i <ARRAY_SIZE (mode_string); i++) { +for (int i =0 ; i <ARRAY_SIZE (mode_string); i++) {if (mode_string[i].val != mode)continue ;if (!*mode_string[i].str)
@@ -1333,12 +1325,11 @@ void git_check_attr(struct index_state *istate,const char *path, struct attr_check *check) { - int i; const struct object_id *tree_oid = default_attr_source();collect_some_attrs (istate, tree_oid, path, check); -for (i =0 ; i < check->nr; i++) { +for (int i =0 ; i < check->nr; i++) {unsigned int n = check->items[i].attr->attr_nr;const char *value = check->all_attrs[n].value;if (value ==ATTR__UNKNOWN )
@@ -1350,13 +1341,12 @@ void git_check_attr(struct index_state *istate,void git_all_attrs (struct index_state *istate,const char *path,struct attr_check *check) { -int i;const struct object_id *tree_oid =default_attr_source ();attr_check_reset (check);collect_some_attrs (istate, tree_oid, path, check); -for (i =0 ; i < check->all_attrs_nr; i++) { +for (int i =0 ; i < check->all_attrs_nr; i++) {const char *name = check->all_attrs[i].attr->name;const char *value = check->all_attrs[i].value;struct attr_check_item *item;
base85.c +1 -2
@@ -29,10 +29,9 @@ static const char en85[] = {static char de85[256 ];static void prep_base85 (void ) { -int i;if (de85['Z' ])return ; -for (i =0 ; i <ARRAY_SIZE (en85); i++) { +for (int i =0 ; i <ARRAY_SIZE (en85); i++) {int ch = en85[i]; de85[ch] = i +1 ; }
bisect.c +9 -14
@@ -139,14 +139,12 @@ static inline int approx_halfway(struct commit_list *p, int nr)static void show_list (const char *debug,int counted,int nr,struct commit_list *list) { -struct commit_list *p; -if (!DEBUG_BISECT )return ;fprintf (stderr,"%s (%d/%d)\n" , debug, counted, nr); -for (p = list; p; p = p->next) { +for (struct commit_list *p = list; p; p = p->next) {struct commit_list *pp;struct commit *commit = p->item;unsigned commit_flags = commit->object.flags;
@@ -183,11 +181,11 @@ static void show_list(const char *debug, int counted, int nr,static struct commit_list *best_bisection (struct commit_list *list,int nr) { -struct commit_list *p, *best; +struct commit_list *best;int best_distance =-1 ; best = list; -for (p = list; p; p = p->next) { +for (struct commit_list *p = list; p; p = p->next) {int distance;unsigned commit_flags = p->item->object.flags;
@@ -500,9 +498,7 @@ static void read_bisect_paths(struct strvec *array)static char *join_oid_array_hex (struct oid_array *array,char delim) {struct strbuf joined_hexs =STRBUF_INIT ; -int i; - -for (i =0 ; i < array->nr; i++) { +for (int i =0 ; i < array->nr; i++) {strbuf_addstr (&joined_hexs,oid_to_hex (array->oid + i));if (i +1 < array->nr)strbuf_addch (&joined_hexs, delim);
@@ -611,7 +607,7 @@ static int sqrti(int val)static struct commit_list *skip_away (struct commit_list *list,int count) {struct commit_list *cur, *previous; -int prn, index, i; +int prn, index; prn =get_prn (count); index = (count * prn /PRN_MODULO ) *sqrti (prn) /sqrti (PRN_MODULO );
@@ -619,7 +615,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count) cur = list; previous =NULL ; -for (i =0 ; cur; cur = cur->next, i++) { +for (int i =0 ; cur; cur = cur->next, i++) {if (i == index) {if (!oideq (&cur->item->object.oid, current_bad_oid))return cur;
@@ -660,7 +656,6 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,struct setup_revision_opt opt = { .free_removed_argv_elements =1 , }; -int i;repo_init_revisions (r, revs, prefix); revs->abbrev =0 ;
@@ -669,7 +664,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,/* rev_argv.argv[0] will be ignored by setup_revisions */ strvec_push (rev_argv,"bisect_rev_setup" );strvec_pushf (rev_argv, bad_format,oid_to_hex (current_bad_oid)); -for (i =0 ; i < good_revs.nr; i++) +for (int i =0 ; i < good_revs.nr; i++)strvec_pushf (rev_argv, good_format,oid_to_hex (good_revs.oid + i));strvec_push (rev_argv,"--" );
@@ -763,11 +758,11 @@ static struct commit **get_bad_and_good_commits(struct repository *r, int *rev_nr) {struct commit **rev; -int i, n =0 ; +int n =0 ;ALLOC_ARRAY (rev,1 + good_revs.nr); rev[n++] =get_commit_reference (r, current_bad_oid); -for (i =0 ; i < good_revs.nr; i++) +for (int i =0 ; i < good_revs.nr; i++) rev[n++] =get_commit_reference (r, good_revs.oid + i); *rev_nr = n;
blame.c +34 -58
322 lines not on this page · raw message
bloom.c +6 -11
@@ -107,14 +107,13 @@ uint32_t murmur3_seeded(uint32_t seed, const char *data, size_t len)const uint32_t r2 =13 ;const uint32_t m =5 ;const uint32_t n =0xe6546b64 ; -int i;uint32_t k1 =0 ;const char *tail;int len4 = len /sizeof (uint32_t );uint32_t k; -for (i =0 ; i < len4; i++) { +for (int i =0 ; i < len4; i++) {uint32_t byte1 = (uint32_t )data[4 *i];uint32_t byte2 = ((uint32_t )data[4 *i +1 ]) <<8 ;uint32_t byte3 = ((uint32_t )data[4 *i +2 ]) <<16 ;
@@ -161,14 +160,13 @@ void fill_bloom_key(const char *data,struct bloom_key *key, const struct bloom_filter_settings *settings) { - int i; const uint32_t seed0 = 0x293ae76f;const uint32_t seed1 =0x7e646e2c ;const uint32_t hash0 =murmur3_seeded (seed0, data, len);const uint32_t hash1 =murmur3_seeded (seed1, data, len); key->hashes = (uint32_t *)xcalloc (settings->num_hashes,sizeof (uint32_t )); -for (i =0 ; i < settings->num_hashes; i++) +for (int i =0 ; i < settings->num_hashes; i++) key->hashes[i] = hash0 + i * hash1; }
@@ -181,10 +179,9 @@ void add_key_to_filter(const struct bloom_key *key,struct bloom_filter *filter, const struct bloom_filter_settings *settings) { - int i; uint64_t mod = filter->len * BITS_PER_WORD; -for (i =0 ; i < settings->num_hashes; i++) { +for (int i =0 ; i < settings->num_hashes; i++) {uint64_t hash_mod = key->hashes[i] % mod;uint64_t block_pos = hash_mod /BITS_PER_WORD ;
@@ -224,7 +221,6 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, enum bloom_filter_computed *computed) {struct bloom_filter *filter; -int i;struct diff_options diffopt;if (computed)
@@ -267,7 +263,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,struct pathmap_hash_entry *e;struct hashmap_iter iter; -for (i =0 ; i < diff_queued_diff.nr; i++) { +for (int i =0 ; i < diff_queued_diff.nr; i++) {const char *path = diff_queued_diff.queue[i]->two->path;/*
@@ -323,7 +319,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, cleanup: hashmap_clear_and_free(&pathmap, struct pathmap_hash_entry, entry); }else { -for (i =0 ; i < diff_queued_diff.nr; i++) +for (int i =0 ; i < diff_queued_diff.nr; i++)diff_free_filepair (diff_queued_diff.queue[i]);init_truncated_large_filter (filter);
@@ -344,13 +340,12 @@ int bloom_filter_contains(const struct bloom_filter *filter,const struct bloom_key *key, const struct bloom_filter_settings *settings) { - int i; uint64_t mod = filter->len * BITS_PER_WORD;if (!mod)return -1 ; -for (i =0 ; i < settings->num_hashes; i++) { +for (int i =0 ; i < settings->num_hashes; i++) {uint64_t hash_mod = key->hashes[i] % mod;uint64_t block_pos = hash_mod /BITS_PER_WORD ;if (!(filter->data[block_pos] &get_bitmask (hash_mod)))
branch.c +1 -2
@@ -216,7 +216,6 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref) {const char *bare_ref;struct branch *branch; -int i; bare_ref = orig_ref;skip_prefix (orig_ref,"refs/heads/" , &bare_ref);
@@ -235,7 +234,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref) } tracking->remote = branch->remote_name; -for (i =0 ; i < branch->merge_nr; i++) +for (int i =0 ; i < branch->merge_nr; i++)string_list_append (tracking->srcs, branch->merge_name[i]);return 0 ; }
builtin/add.c +7 -8
@@ -38,9 +38,9 @@ static const char *pathspec_from_file;static int chmod_pathspec (struct pathspec *pathspec,char flip,int show_only) { -int i, ret =0 ; +int ret =0 ; -for (i =0 ; i < the_index.cache_nr; i++) { +for (int i =0 ; i < the_index.cache_nr; i++) {struct cache_entry *ce = the_index.cache[i];int err;
@@ -66,9 +66,9 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)static int renormalize_tracked_files (const struct pathspec *pathspec,int flags) { -int i, retval =0 ; +int retval =0 ; -for (i =0 ; i < the_index.cache_nr; i++) { +for (int i =0 ; i < the_index.cache_nr; i++) {struct cache_entry *ce = the_index.cache[i]; if (!include_sparse &&
@@ -112,7 +112,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,static int refresh (int verbose,const struct pathspec *pathspec) {char *seen; -int i, ret =0 ; +int ret =0 ;char *skip_worktree_seen =NULL ;struct string_list only_match_skip_worktree =STRING_LIST_INIT_NODUP ; int flags = REFRESH_IGNORE_SKIP_WORKTREE |
@@ -121,7 +121,7 @@ static int refresh(int verbose, const struct pathspec *pathspec) seen =xcalloc (pathspec->nr,1 );refresh_index (&the_index, flags, pathspec, seen,_ ("Unstaged changes after refreshing the index:" )); -for (i =0 ; i < pathspec->nr; i++) { +for (int i =0 ; i < pathspec->nr; i++) {if (!seen[i]) {const char *path = pathspec->items[i].original;
@@ -485,7 +485,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) }if (pathspec.nr) { -int i;char *skip_worktree_seen =NULL ;struct string_list only_match_skip_worktree =STRING_LIST_INIT_NODUP ;
@@ -504,7 +503,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)PATHSPEC_EXCLUDE | PATHSPEC_ATTR); -for (i =0 ; i < pathspec.nr; i++) { +for (int i =0 ; i < pathspec.nr; i++) {const char *path = pathspec.items[i].match;if (pathspec.items[i].magic &PATHSPEC_EXCLUDE )
builtin/am.c +1 -2
@@ -2445,7 +2445,6 @@ int cmd_am(int argc, const char **argv, const char *prefix)am_append_signoff (&state); }else {struct strvec paths =STRVEC_INIT ; -int i;/* * Handle stray state directory in the independent-run case. In
@@ -2467,7 +2466,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)if (resume_mode)die (_ ("Resolve operation not in progress, we are not resuming." )); -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {if (is_absolute_path (argv[i]) || !prefix)strvec_push (&paths, argv[i]);else
builtin/annotate.c +1 -2
@@ -10,11 +10,10 @@int cmd_annotate (int argc,const char **argv,const char *prefix) {struct strvec args =STRVEC_INIT ; -int i;strvec_pushl (&args,"annotate" ,"-c" ,NULL ); -for (i =1 ; i < argc; i++) { +for (int i =1 ; i < argc; i++) {strvec_push (&args, argv[i]); }
builtin/archive.c +2 -2
@@ -25,7 +25,7 @@ static int run_remote_archiver(int argc, const char **argv, const char *remote, const char *exec, const char *name_hint) { - int fd[2], i, rv; + int fd[2], rv;struct transport *transport;struct remote *_remote;struct packet_reader reader;
@@ -47,7 +47,7 @@ static int run_remote_archiver(int argc, const char **argv,if (format)packet_write_fmt (fd[1 ],"argument --format=%s\n" , format); } -for (i =1 ; i < argc; i++) +for (int i =1 ; i < argc; i++)packet_write_fmt (fd[1 ],"argument %s\n" , argv[i]);packet_flush (fd[1 ]);
builtin/bisect.c +3 -4
@@ -916,7 +916,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc, const char **argv) {const char *state; -int i, verify_expected =1 ; +int verify_expected =1 ;struct object_id oid, expected;struct oid_array revs =OID_ARRAY_INIT ;
@@ -975,7 +975,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,if (read_ref ("BISECT_EXPECTED_REV" , &expected)) verify_expected =0 ;/* Ignore invalid file contents */ -for (i =0 ; i < revs.nr; i++) { +for (int i =0 ; i < revs.nr; i++) {if (bisect_write (state,oid_to_hex (&revs.oid[i]), terms,0 )) {oid_array_clear (&revs);return BISECT_FAILED ;
@@ -1083,13 +1083,12 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *fstatic enum bisect_error bisect_skip (struct bisect_terms *terms,int argc,const char **argv) { -int i;enum bisect_error res;struct strvec argv_state =STRVEC_INIT ;strvec_push (&argv_state,"skip" ); -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {const char *dotdot =strstr (argv[i],".." );if (dotdot) {
builtin/blame.c +4 -10
@@ -313,7 +313,6 @@ static const char *format_time(timestamp_t time, const char *tz_str, }else {const char *time_str; -size_t time_width;int tz; tz =atoi (tz_str); time_str =show_date (time, tz, &blame_date_mode);
@@ -322,9 +321,7 @@ static const char *format_time(timestamp_t time, const char *tz_str,* Add space paddings to time_buf to display a fixed width * string, and use time_width for display width calibration. */ -for (time_width =utf8_strwidth (time_str); - time_width < blame_date_width; - time_width++) +for (size_t time_width =utf8_strwidth (time_str); time_width < blame_date_width; time_width++)strbuf_addch (&time_buf,' ' ); }return time_buf.buf;
@@ -354,7 +351,6 @@ static void emit_porcelain(struct blame_scoreboard *sb, struct blame_entry *ent, int opt) {int repeat = opt &OUTPUT_LINE_PORCELAIN ; -int cnt;const char *cp;struct blame_origin *suspect = ent->suspect;char hex[GIT_MAX_HEXSZ +1 ];
@@ -368,7 +364,7 @@ static void emit_porcelain(struct blame_scoreboard *sb, struct blame_entry *ent,emit_porcelain_details (suspect, repeat); cp =blame_nth_line (sb, ent->lno); -for (cnt =0 ; cnt < ent->num_lines; cnt++) { +for (int cnt =0 ; cnt < ent->num_lines; cnt++) {char ch;if (cnt) { printf("%s %d %d\n", hex,
@@ -447,7 +443,6 @@ static void determine_line_heat(struct commit_info *ci, const char **dest_color)static void emit_other (struct blame_scoreboard *sb,struct blame_entry *ent,int opt) { -int cnt;const char *cp;struct blame_origin *suspect = ent->suspect;struct commit_info ci =COMMIT_INFO_INIT ;
@@ -466,7 +461,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int reset =GIT_COLOR_RESET ; } -for (cnt =0 ; cnt < ent->num_lines; cnt++) { +for (int cnt =0 ; cnt < ent->num_lines; cnt++) {char ch;int length = (opt &OUTPUT_LONG_OBJECT_NAME ) ? the_hash_algo->hexsz : abbrev;
@@ -625,11 +620,10 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)int longest_src_lines =0 ;int longest_dst_lines =0 ;unsigned largest_score =0 ; -struct blame_entry *e;int compute_auto_abbrev = (abbrev <0 );int auto_abbrev =DEFAULT_ABBREV ; -for (e = sb->ent; e; e = e->next) { +for (struct blame_entry *e = sb->ent; e; e = e->next) {struct blame_origin *suspect = e->suspect;int num;
builtin/branch.c +5 -10
@@ -216,7 +216,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,struct object_id oid;char *name =NULL ;const char *fmt; -int i;int ret =0 ;int remote_branch =0 ;struct strbuf bname =STRBUF_INIT ;
@@ -247,7 +246,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,if (!force) head_rev =lookup_commit_reference (the_repository, &head_oid); -for (i =0 ; i < argc; i++,strbuf_reset (&bname)) { +for (int i =0 ; i < argc; i++,strbuf_reset (&bname)) {char *target =NULL ;int flags =0 ;
@@ -339,8 +338,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,static int calc_maxwidth (struct ref_array *refs,int remote_bonus) { -int i, max =0 ; -for (i =0 ; i < refs->nr; i++) { +int max =0 ; +for (int i =0 ; i < refs->nr; i++) {struct ref_array_item *it = refs->items[i];const char *desc = it->refname;int w;
@@ -508,9 +507,7 @@ static void print_current_branch_name(void)static void reject_rebase_or_bisect_branch (struct worktree **worktrees,const char *target) { -int i; - -for (i =0 ; worktrees[i]; i++) { +for (int i =0 ; worktrees[i]; i++) {struct worktree *wt = worktrees[i];if (!wt->is_detached)
@@ -536,9 +533,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees, const char *logmsg) {int ret =0 ; -int i; - -for (i =0 ; worktrees[i]; i++) { +for (int i =0 ; worktrees[i]; i++) {struct ref_store *refs;if (worktrees[i]->is_detached)
builtin/bugreport.c +1 -3
@@ -47,15 +47,13 @@ static void get_system_info(struct strbuf *sys_info)static void get_populated_hooks (struct strbuf *hook_info,int nongit) { -const char **p; -if (nongit) {strbuf_addstr (hook_info,_ ("not run from a git repository - no hooks to show\n" ));return ; } -for (p = hook_name_list; *p; p++) { +for (const char **p = hook_name_list; *p; p++) {const char *hook = *p;if (hook_exists (hook))
builtin/cat-file.c +2 -6
@@ -662,12 +662,10 @@ static void dispatch_calls(struct batch_options *opt, struct queued_cmd *cmd, int nr) { - int i; -if (!opt->buffer_output)die (_ ("flush is only for --buffer mode" )); -for (i =0 ; i < nr; i++) +for (int i =0 ; i < nr; i++) cmd[i].fn (opt, cmd[i].line, output, data);fflush (stdout);
@@ -675,9 +673,7 @@ static void dispatch_calls(struct batch_options *opt,static void free_cmds (struct queued_cmd *cmd,size_t *nr) { -size_t i; - -for (i =0 ; i < *nr; i++) +for (size_t i =0 ; i < *nr; i++)FREE_AND_NULL (cmd[i].line); *nr =0 ;
builtin/check-attr.c +1 -2
@@ -35,10 +35,9 @@ static const struct option check_attr_options[] = {static void output_attr (struct attr_check *check,const char *file) { -int j;int cnt = check->nr; -for (j =0 ; j < cnt; j++) { +for (int j =0 ; j < cnt; j++) {const char *value = check->items[j].value;if (ATTR_TRUE (value))
builtin/check-ignore.c +2 -2
@@ -75,7 +75,7 @@ static int check_ignore(struct dir_struct *dir, {const char *full_path;char *seen; -int num_ignored =0 , i; +int num_ignored =0 ;struct path_pattern *pattern;struct pathspec pathspec;
@@ -104,7 +104,7 @@ static int check_ignore(struct dir_struct *dir,*/ seen =find_pathspecs_matching_against_index (&pathspec, &the_index,PS_HEED_SKIP_WORKTREE ); -for (i =0 ; i < pathspec.nr; i++) { +for (int i =0 ; i < pathspec.nr; i++) { full_path = pathspec.items[i].match; pattern =NULL ;if (!seen[i]) {
builtin/check-mailmap.c +1 -2
@@ -42,7 +42,6 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)int cmd_check_mailmap (int argc,const char **argv,const char *prefix) { -int i;struct string_list mailmap =STRING_LIST_INIT_NODUP ;git_config (git_default_config,NULL );
@@ -53,7 +52,7 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)read_mailmap (&mailmap); -for (i =0 ; i < argc; ++i) +for (int i =0 ; i < argc; ++i)check_mailmap (&mailmap, argv[i]);maybe_flush_or_die (stdout,"stdout" );
builtin/checkout--worker.c +2 -2
@@ -81,7 +81,7 @@ static void release_pc_item_data(struct parallel_checkout_item *pc_item)static void worker_loop (struct checkout *state) {struct parallel_checkout_item *items =NULL ; -size_t i, nr =0 , alloc =0 ; +size_t nr =0 , alloc =0 ;while (1 ) { int len = packet_read(0, packet_buffer, sizeof(packet_buffer),
@@ -96,7 +96,7 @@ static void worker_loop(struct checkout *state)packet_to_pc_item (packet_buffer, len, &items[nr++]); } -for (i =0 ; i < nr; i++) { +for (size_t i =0 ; i < nr; i++) {struct parallel_checkout_item *pc_item = &items[i];write_pc_item (pc_item, state);report_result (pc_item);
builtin/checkout-index.c +3 -4
@@ -137,10 +137,10 @@ static int checkout_file(const char *name, const char *prefix)static int checkout_all (const char *prefix,int prefix_length) { -int i, errs =0 ; +int errs =0 ;struct cache_entry *last_ce =NULL ; -for (i =0 ; i < the_index.cache_nr ; i++) { +for (int i =0 ; i < the_index.cache_nr; i++) {struct cache_entry *ce = the_index.cache[i];if (S_ISSPARSEDIR (ce->ce_mode)) {
@@ -210,7 +210,6 @@ static int option_parse_stage(const struct option *opt,int cmd_checkout_index (int argc,const char **argv,const char *prefix) { -int i;struct lock_file lock_file =LOCK_INIT ;int all =0 ;int read_from_stdin =0 ;
@@ -290,7 +289,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)init_parallel_checkout ();/* Check out named files first */ -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {const char *arg = argv[i];char *p;
builtin/checkout.c +2 -4
@@ -382,7 +382,6 @@ static int checkout_worktree(const struct checkout_opts *opts,struct checkout state =CHECKOUT_INIT ;int nr_checkouts =0 , nr_unmerged =0 ;int errs =0 ; -int pos;int pc_workers, pc_threshold;struct mem_pool ce_mem_pool;
@@ -401,7 +400,7 @@ static int checkout_worktree(const struct checkout_opts *opts,if (pc_workers >1 )init_parallel_checkout (); -for (pos =0 ; pos < the_index.cache_nr; pos++) { +for (int pos =0 ; pos < the_index.cache_nr; pos++) {struct cache_entry *ce = the_index.cache[pos];if (ce->ce_flags &CE_MATCHED ) {if (!ce_stage (ce)) {
@@ -1290,7 +1289,6 @@ static int parse_branchname_arg(int argc, const char **argv,const char *arg;int dash_dash_pos;int has_dash_dash =0 ; -int i;/* * case 1: git checkout <ref> -- [<paths>]
@@ -1344,7 +1342,7 @@ static int parse_branchname_arg(int argc, const char **argv, arg = argv[0 ]; dash_dash_pos =-1 ; -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {if (opts->accept_pathspec && !strcmp (argv[i],"--" )) { dash_dash_pos = i;break ;
builtin/clean.c +8 -9
@@ -277,8 +277,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, }if (!*dir_gone && !quiet) { -int i; -for (i =0 ; i < dels.nr; i++) +for (int i =0 ; i < dels.nr; i++)printf (dry_run ?_ (msg_would_remove) :_ (msg_remove), dels.items[i].string); } out:
@@ -408,7 +407,7 @@ static int find_unique(const char *choice, struct menu_stuff *menu_stuff) {struct menu_item *menu_item;struct string_list_item *string_list_item; -int i, len, found =0 ; +int len, found =0 ; len =strlen (choice);switch (menu_stuff->type) {
@@ -417,7 +416,7 @@ static int find_unique(const char *choice, struct menu_stuff *menu_stuff)case MENU_STUFF_TYPE_MENU_ITEM : menu_item = (struct menu_item *)menu_stuff->stuff; -for (i =0 ; i < menu_stuff->nr; i++, menu_item++) { +for (int i =0 ; i < menu_stuff->nr; i++, menu_item++) {if (len ==1 && *choice == menu_item->hotkey) { found = i +1 ;break ;
@@ -439,7 +438,7 @@ static int find_unique(const char *choice, struct menu_stuff *menu_stuff)break ;case MENU_STUFF_TYPE_STRING_LIST : string_list_item = ((struct string_list *)menu_stuff->stuff)->items; -for (i =0 ; i < menu_stuff->nr; i++, string_list_item++) { +for (int i =0 ; i < menu_stuff->nr; i++, string_list_item++) {if (!strncasecmp (choice, string_list_item->string, len)) {if (found) { found =0 ;
@@ -479,7 +478,7 @@ static int parse_choice(struct menu_stuff *menu_stuff,struct strbuf input, int **chosen) { - struct strbuf **choice_list, **ptr; + struct strbuf **choice_list;int nr =0 ;int i;
@@ -494,7 +493,7 @@ static int parse_choice(struct menu_stuff *menu_stuff, choice_list =strbuf_split_max (&input,' ' ,0 ); } -for (ptr = choice_list; *ptr; ptr++) { +for (struct strbuf **ptr = choice_list; *ptr; ptr++) {char *p;int choose =1 ;int bottom =0 , top =0 ;
@@ -886,9 +885,9 @@ static void interactive_main_loop(void)static void correct_untracked_entries (struct dir_struct *dir) { -int src, dst, ign; +int dst, ign; -for (src = dst = ign =0 ; src < dir->nr; src++) { +for (int src = dst = ign =0 ; src < dir->nr; src++) {/* skip paths in ignored[] that cannot be inside entries[src] */ while (ign < dir->ignored_nr &&0 <=cmp_dir_entry (&dir->entries[src], &dir->ignored[ign]))
builtin/clone.c +5 -12
@@ -511,8 +511,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,warning (_ ("Could not find remote branch %s to clone." ), option_branch); else { -int i; -for (i =0 ; i < refspec->nr; i++) +for (int i =0 ; i < refspec->nr; i++)get_fetch_map (remote_head, &refspec->items[i], &tail,0 );
@@ -521,8 +520,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs, }free_refs (remote_head); }else { -int i; -for (i =0 ; i < refspec->nr; i++) +for (int i =0 ; i < refspec->nr; i++)get_fetch_map (refs, &refspec->items[i], &tail,0 ); }
@@ -534,8 +532,6 @@ static struct ref *wanted_peer_refs(const struct ref *refs,static void write_remote_refs (const struct ref *local_refs) { -const struct ref *r; -struct ref_transaction *t;struct strbuf err =STRBUF_INIT ;
@@ -543,7 +539,7 @@ static void write_remote_refs(const struct ref *local_refs)if (!t)die ("%s" , err.buf); -for (r = local_refs; r; r = r->next) { +for (const struct ref *r = local_refs; r; r = r->next) {if (!r->peer_ref)continue ; if (ref_transaction_create(t, r->peer_ref->name, &r->old_oid,
@@ -560,8 +556,7 @@ static void write_remote_refs(const struct ref *local_refs)static void write_followtags (const struct ref *refs,const char *msg) { -const struct ref *ref; -for (ref = refs; ref; ref = ref->next) { +for (const struct ref *ref = refs; ref; ref = ref->next) {if (!starts_with (ref->name,"refs/tags/" ))continue ;if (ends_with (ref->name,"^{}" ))
@@ -826,9 +821,7 @@ static int write_one_config(const char *key, const char *value,static void write_config (struct string_list *config) { -int i; - -for (i =0 ; i < config->nr; i++) { +for (int i =0 ; i < config->nr; i++) {if (git_config_parse_parameter (config->items[i].string, write_one_config,NULL ) <0 )die (_ ("unable to write parameters to config file" ));
builtin/commit-tree.c +1 -2
@@ -25,8 +25,7 @@ static const char *sign_commit;static void new_parent (struct commit *parent,struct commit_list **parents_p) {struct object_id *oid = &parent->object.oid; -struct commit_list *parents; -for (parents = *parents_p; parents; parents = parents->next) { +for (struct commit_list *parents = *parents_p; parents; parents = parents->next) {if (parents->item == parent) {error (_ ("duplicate parent %s ignored" ),oid_to_hex (oid));return ;
builtin/commit.c +5 -6
@@ -256,7 +256,7 @@ static int commit_index_files(void)static int list_paths (struct string_list *list,const char *with_tree,const struct pathspec *pattern) { -int i, ret; +int ret;char *m;if (!pattern->nr)
@@ -272,7 +272,7 @@ static int list_paths(struct string_list *list, const char *with_tree,/* TODO: audit for interaction with sparse-index. */ ensure_full_index (&the_index); -for (i =0 ; i < the_index.cache_nr; i++) { +for (int i =0 ; i < the_index.cache_nr; i++) {const struct cache_entry *ce = the_index.cache[i];struct string_list_item *item;
@@ -292,8 +292,7 @@ static int list_paths(struct string_list *list, const char *with_tree,static void add_remove_files (struct string_list *list) { -int i; -for (i =0 ; i < list->nr; i++) { +for (int i =0 ; i < list->nr; i++) {struct stat st;struct string_list_item *p = &(list->items[i]);
@@ -1001,11 +1000,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix, parent ="HEAD^1" ;if (repo_get_oid (the_repository, parent, &oid)) { -int i, ita_nr =0 ; +int ita_nr =0 ;/* TODO: audit for interaction with sparse-index. */ ensure_full_index (&the_index); -for (i =0 ; i < the_index.cache_nr; i++) +for (int i =0 ; i < the_index.cache_nr; i++)if (ce_intent_to_add (the_index.cache[i])) ita_nr++; committable = the_index.cache_nr - ita_nr >0 ;
builtin/config.c +1 -2
@@ -333,7 +333,6 @@ static int get_value(const char *key_, const char *regex_, unsigned flags) {int ret =CONFIG_GENERIC_ERROR ;struct strbuf_list values = {NULL }; -int i;if (use_key_regexp) {char *tl;
@@ -402,7 +401,7 @@ static int get_value(const char *key_, const char *regex_, unsigned flags) ret = !values.nr; -for (i =0 ; i < values.nr; i++) { +for (int i =0 ; i < values.nr; i++) {struct strbuf *buf = values.items + i;if (do_all || i == values.nr -1 )fwrite (buf->buf,1 , buf->len, stdout);
builtin/count-objects.c +1 -2
@@ -120,14 +120,13 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) count_loose, count_cruft, NULL, NULL);if (verbose) { -struct packed_git *p;unsigned long num_pack =0 ;off_t size_pack =0 ;struct strbuf loose_buf =STRBUF_INIT ;struct strbuf pack_buf =STRBUF_INIT ;struct strbuf garbage_buf =STRBUF_INIT ; -for (p =get_all_packs (the_repository); p; p = p->next) { +for (struct packed_git *p =get_all_packs (the_repository); p; p = p->next) {if (!p->pack_local)continue ;if (open_pack_index (p))
builtin/credential-cache--daemon.c +2 -6
@@ -34,8 +34,7 @@ static void cache_credential(struct credential *c, int timeout)static struct credential_cache_entry *lookup_credential (const struct credential *c) { -int i; -for (i =0 ; i < entries_nr; i++) { +for (int i =0 ; i < entries_nr; i++) {struct credential *e = &entries[i].item;if (credential_match (c, e,0 ))return &entries[i];
@@ -45,10 +44,7 @@ static struct credential_cache_entry *lookup_credential(const struct credentialstatic void remove_credential (const struct credential *c,int match_password) { -struct credential_cache_entry *e; - -int i; -for (i =0 ; i < entries_nr; i++) { +struct credential_cache_entry *e;for (int i =0 ; i < entries_nr; i++) { e = &entries[i];if (credential_match (c, &e->item, match_password)) e->expiration =0 ;
builtin/describe.c +2 -2
@@ -450,8 +450,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)if (debug) {static int label_width =-1 ;if (label_width <0 ) { -int i, w; -for (i =0 ; i <ARRAY_SIZE (prio_names); i++) { +int w; +for (int i =0 ; i <ARRAY_SIZE (prio_names); i++) { w =strlen (_ (prio_names[i]));if (label_width < w) label_width = w;
builtin/diff-index.c +1 -2
@@ -18,7 +18,6 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) {struct rev_info rev;unsigned int option =0 ; -int i;int result;if (argc ==2 && !strcmp (argv[1 ],"-h" ))
@@ -36,7 +35,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)diff_merges_suppress_m_parsing (); argc =setup_revisions (argc, argv, &rev,NULL ); -for (i =1 ; i < argc; i++) { +for (int i =1 ; i < argc; i++) {const char *arg = argv[i];if (!strcmp (arg,"--cached" ))
builtin/diff.c +3 -4
@@ -211,7 +211,6 @@ static void builtin_diff_combined(struct rev_info *revs, int ents, int first_non_parent) {struct oid_array parents =OID_ARRAY_INIT ; -int i;if (argc >1 )usage (builtin_diff_usage);
@@ -223,7 +222,7 @@ static void builtin_diff_combined(struct rev_info *revs,diff_merges_set_dense_combined_if_unset (revs); -for (i =0 ; i < ents; i++) { +for (int i =0 ; i < ents; i++) {if (i != first_non_parent)oid_array_append (&parents, &ent[i].item->oid); }
@@ -313,7 +312,7 @@ struct symdiff {*/ static void symdiff_prepare (struct rev_info *rev,struct symdiff *sym) { -int i, is_symdiff =0 , basecount =0 , othercount =0 ; +int is_symdiff =0 , basecount =0 , othercount =0 ;int lpos =-1 , rpos =-1 , basepos =-1 ;struct bitmap *map =NULL ;
@@ -332,7 +331,7 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym)* so we must check for SYMMETRIC_LEFT too. The two arrays * rev->pending.objects and rev->cmdline.rev are parallel. */ -for (i =0 ; i < rev->cmdline.nr; i++) { +for (int i =0 ; i < rev->cmdline.nr; i++) {struct object *obj = rev->pending.objects[i].item;switch (rev->cmdline.rev[i].whence) {case REV_CMD_MERGE_BASE :
builtin/fast-export.c +7 -17
@@ -430,7 +430,6 @@ static const char *anonymize_oid(const char *oid_hex)static void show_filemodify (struct diff_queue_struct *q, struct diff_options *options UNUSED, void *data) { -int i;struct string_list *changed = data;/*
@@ -439,7 +438,7 @@ static void show_filemodify(struct diff_queue_struct *q,*/ QSORT (q->queue, q->nr, depth_first); -for (i =0 ; i < q->nr; i++) { +for (int i =0 ; i < q->nr; i++) {struct diff_filespec *ospec = q->queue[i]->one;struct diff_filespec *spec = q->queue[i]->two;
@@ -543,10 +542,9 @@ static const char *anonymize_refname(const char *refname) };static struct hashmap refs;static struct strbuf anon =STRBUF_INIT ; -int i;strbuf_reset (&anon); -for (i =0 ; i <ARRAY_SIZE (prefixes); i++) { +for (int i =0 ; i <ARRAY_SIZE (prefixes); i++) {if (skip_prefix (refname, prefixes[i], &refname)) {strbuf_addstr (&anon, prefixes[i]);break ;
@@ -926,9 +924,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)static void get_tags_and_duplicates (struct rev_cmdline_info *info) { -int i; - -for (i =0 ; i < info->nr; i++) { +for (int i =0 ; i < info->nr; i++) {struct rev_cmdline_entry *e = info->rev + i;struct object_id oid;struct commit *commit;
@@ -988,9 +984,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)static void handle_tags_and_duplicates (struct string_list *extras) {struct commit *commit; -int i; - -for (i = extras->nr -1 ; i >=0 ; i--) { +for (int i = extras->nr -1 ; i >=0 ; i--) {const char *name = extras->items[i].string;struct object *object = extras->items[i].util;int mark;
@@ -1050,7 +1044,6 @@ static void handle_tags_and_duplicates(struct string_list *extras)static void export_marks (char *file) { -unsigned int i;uint32_t mark;struct decoration_entry *deco = idnums.entries;FILE *f;
@@ -1060,7 +1053,7 @@ static void export_marks(char *file)if (!f)die_errno ("Unable to open marks file %s for writing." , file); -for (i =0 ; i < idnums.size; i++) { +for (unsigned int i =0 ; i < idnums.size; i++) {if (deco->base && deco->base->type ==1 ) { mark =ptr_to_mark (deco->decoration); if (fprintf(f, ":%"PRIu32" %s\n", mark,
@@ -1135,8 +1128,7 @@ static void import_marks(char *input_file, int check_exists)static void handle_deletes (void ) { -int i; -for (i =0 ; i < refspecs.nr; i++) { +for (int i =0 ; i < refspecs.nr; i++) {struct refspec_item *refspec = &refspecs.items[i];if (*refspec->src)continue ;
@@ -1247,9 +1239,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)die (_ ("the option '%s' requires '%s'" ),"--anonymize-map" ,"--anonymize" );if (refspecs_list.nr) { -int i; - -for (i =0 ; i < refspecs_list.nr; i++) +for (int i =0 ; i < refspecs_list.nr; i++)refspec_append (&refspecs, refspecs_list.items[i].string);string_list_clear (&refspecs_list,1 );
builtin/fast-import.c +21 -35
212 lines not on this page · raw message
builtin/fetch-pack.c +1 -3
@@ -242,11 +242,9 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) ref =fetch_pack (&args, fd, ref, sought, nr_sought, &shallow, pack_lockfiles_ptr, version);if (pack_lockfiles.nr) { -int i; -printf ("lock %s\n" , pack_lockfiles.items[0 ].string);fflush (stdout); -for (i =1 ; i < pack_lockfiles.nr; i++) +for (int i =1 ; i < pack_lockfiles.nr; i++)warning (_ ("Lockfile created but not reported: %s" ), pack_lockfiles.items[i].string); }
builtin/fetch.c +11 -28
@@ -210,9 +210,7 @@ static void add_merge_config(struct ref **head, struct branch *branch, struct ref ***tail) { - int i; - -for (i =0 ; i < branch->merge_nr; i++) { +for (int i =0 ; i < branch->merge_nr; i++) {struct ref *rm, **old_tail = *tail;struct refspec_item refspec;
@@ -331,7 +329,6 @@ static void find_non_local_tags(const struct ref *refs,struct oidset fetch_oids =OIDSET_INIT ;struct string_list remote_refs_list =STRING_LIST_INIT_NODUP ;struct string_list_item *remote_ref_item; -const struct ref *ref;struct refname_hash_entry *item =NULL ;const int quick_flags =OBJECT_INFO_QUICK |OBJECT_INFO_SKIP_FETCH_OBJECT ;
@@ -350,7 +347,7 @@ static void find_non_local_tags(const struct ref *refs, add_already_queued_tags, &existing_refs); -for (ref = refs; ref; ref = ref->next) { +for (const struct ref *ref = refs; ref; ref = ref->next) {if (!starts_with (ref->name,"refs/tags/" ))continue ;
@@ -434,12 +431,10 @@ static void find_non_local_tags(const struct ref *refs,static void filter_prefetch_refspec (struct refspec *rs) { -int i; -if (!prefetch)return ; -for (i =0 ; i < rs->nr; i++) { +for (int i =0 ; i < rs->nr; i++) {struct strbuf new_dst =STRBUF_INIT ;char *old_dst;const char *sub =NULL ;
@@ -698,14 +693,13 @@ static int s_update_ref(const char *action,static int refcol_width (const struct ref *ref_map,int compact_format) { -const struct ref *ref;int max, width =10 ; max =term_columns ();if (compact_format) max = max *2 /3 ; -for (ref = ref_map; ref; ref = ref->next) { +for (const struct ref *ref = ref_map; ref; ref = ref->next) {int rlen, llen =0 , len; if (ref->status == REF_STATUS_REJECT_SHALLOW ||
@@ -1138,7 +1132,6 @@ static int store_updated_refs(struct display_state *display_state,struct strbuf note =STRBUF_INIT ;const char *what, *kind;struct ref *rm; -int want_status;int summary_width =0 ;if (verbosity >=0 )
@@ -1161,9 +1154,7 @@ static int store_updated_refs(struct display_state *display_state,* merged entries are written before not-for-merge. That lets readers * use FETCH_HEAD as a refname to refer to the ref to be merged. */ -for (want_status =FETCH_HEAD_MERGE ; - want_status <=FETCH_HEAD_IGNORE ; - want_status++) { +for (int want_status =FETCH_HEAD_MERGE ; want_status <=FETCH_HEAD_IGNORE ; want_status++) {for (rm = ref_map; rm; rm = rm->next) {struct ref *ref =NULL ;
@@ -1294,7 +1285,6 @@ static int check_exist_and_connected(struct ref *ref_map) {struct ref *rm = ref_map;struct check_connected_options opt =CHECK_CONNECTED_INIT ; -struct ref *r;/* * If we are deepening a shallow clone we already have these
@@ -1318,7 +1308,7 @@ static int check_exist_and_connected(struct ref *ref_map)* check_connected() allows objects to merely be promised, but * we need all direct targets to exist. */ -for (r = rm; r; r = r->next) { +for (struct ref *r = rm; r; r = r->next) {if (!repo_has_object_file_with_flags (the_repository, &r->old_oid,OBJECT_INFO_SKIP_FETCH_OBJECT ))return -1 ;
@@ -1462,9 +1452,7 @@ static int add_oid(const char *refname UNUSED,static void add_negotiation_tips (struct git_transport_options *smart_options) {struct oid_array *oids =xcalloc (1 ,sizeof (*oids)); -int i; - -for (i =0 ; i < negotiation_tip.nr; i++) { +for (int i =0 ; i < negotiation_tip.nr; i++) {const char *s = negotiation_tip.items[i].string;int old_nr;if (!has_glob_specials (s)) {
@@ -1592,8 +1580,6 @@ static int do_fetch(struct transport *transport, }if (rs->nr) { -int i; -refspec_ref_prefixes (rs, &transport_ls_refs_options.ref_prefixes);/*
@@ -1601,7 +1587,7 @@ static int do_fetch(struct transport *transport,* OIDs */ must_list_refs =0 ; -for (i =0 ; i < rs->nr; i++) { +for (int i =0 ; i < rs->nr; i++) {if (!rs->items[i].exact_sha1) { must_list_refs =1 ;break ;
@@ -1615,8 +1601,7 @@ static int do_fetch(struct transport *transport, &transport_ls_refs_options.ref_prefixes);if (branch_has_merge_config (branch) && !strcmp (branch->remote_name, transport->remote->name)) { -int i; -for (i =0 ; i < branch->merge_nr; i++) { +for (int i =0 ; i < branch->merge_nr; i++) {strvec_push (&transport_ls_refs_options.ref_prefixes, branch->merge[i]->src); }
@@ -1725,7 +1710,6 @@ static int do_fetch(struct transport *transport,if (set_upstream) {struct branch *branch =branch_get ("HEAD" ); -struct ref *rm;struct ref *source_ref =NULL ;/*
@@ -1738,7 +1722,7 @@ static int do_fetch(struct transport *transport,* request ambiguous and err on the safe side by doing * nothing and just emit a warning. */ -for (rm = ref_map; rm; rm = rm->next) { +for (struct ref *rm = ref_map; rm; rm = rm->next) {if (!rm->peer_ref) {if (source_ref) {warning (_ ("multiple branches detected, incompatible with --set-upstream" ));
@@ -2049,7 +2033,6 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, const struct fetch_config *config) {struct refspec rs =REFSPEC_INIT_FETCH ; -int i;int exit_code;int maybe_prune_tags;int remote_via_config =remote_is_configured (remote,0 );
@@ -2087,7 +2070,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,if (maybe_prune_tags && (argc || !remote_via_config))refspec_append (&rs,TAG_REFSPEC ); -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {if (!strcmp (argv[i],"tag" )) { i++;if (i >= argc)
builtin/for-each-repo.c +3 -4
@@ -14,14 +14,13 @@ static const char * const for_each_repo_usage[] = {static int run_command_on_repo (const char *path,int argc,const char ** argv) { -int i;struct child_process child =CHILD_PROCESS_INIT ;char *abspath =interpolate_path (path,0 ); child.git_cmd =1 ;strvec_pushl (&child.args,"-C" , abspath,NULL ); -for (i =0 ; i < argc; i++) +for (int i =0 ; i < argc; i++)strvec_push (&child.args, argv[i]);free (abspath);
@@ -32,7 +31,7 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)int cmd_for_each_repo (int argc,const char **argv,const char *prefix) {static const char *config_key =NULL ; -int i, result =0 ; +int result =0 ;const struct string_list *values;int err;
@@ -55,7 +54,7 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)else if (err)return 0 ; -for (i =0 ; !result && i < values->nr; i++) +for (int i =0 ; !result && i < values->nr; i++) result =run_command_on_repo (values->items[i].string, argc, argv);return result;
builtin/fsck.c +9 -13
@@ -366,7 +366,7 @@ static void check_object(struct object *obj)static void check_connectivity (void ) { -int i, max; +int max;/* Traverse the pending reachable objects */ traverse_reachable ();
@@ -396,7 +396,7 @@ static void check_connectivity(void)if (verbose)fprintf_ln (stderr,_ ("Checking connectivity (%d objects)" ), max); -for (i =0 ; i < max; i++) { +for (int i =0 ; i < max; i++) {struct object *obj =get_indexed_object (i);if (obj)
@@ -561,14 +561,14 @@ static int fsck_head_link(const char *head_ref_name,static void get_default_heads (void ) { -struct worktree **worktrees, **p; +struct worktree **worktrees;const char *head_points_at;struct object_id head_oid;for_each_rawref (fsck_handle_ref,NULL ); worktrees =get_worktrees (); -for (p = worktrees; *p; p++) { +for (struct worktree **p = worktrees; *p; p++) {struct worktree *wt = *p;struct strbuf ref =STRBUF_INIT ;
@@ -742,7 +742,6 @@ static int fsck_head_link(const char *head_ref_name,static int fsck_cache_tree (struct cache_tree *it,const char *index_path) { -int i;int err =0 ;if (verbose)
@@ -762,7 +761,7 @@ static int fsck_cache_tree(struct cache_tree *it, const char *index_path)if (obj->type !=OBJ_TREE ) err |=objerror (obj,_ ("non-tree in cache-tree" )); } -for (i =0 ; i < it->subtree_nr; i++) +for (int i =0 ; i < it->subtree_nr; i++) err |=fsck_cache_tree (it->down[i]->cache_tree, index_path);return err; }
@@ -809,11 +808,9 @@ static int fsck_resolve_undo(struct index_state *istate,static void fsck_index (struct index_state *istate,const char *index_path,int is_current_worktree) { -unsigned int i; -/* TODO: audit for interaction with sparse-index. */ ensure_full_index (istate); -for (i =0 ; i < istate->cache_nr; i++) { +for (unsigned int i =0 ; i < istate->cache_nr; i++) {unsigned int mode;struct blob *blob;struct object *obj;
@@ -921,7 +918,6 @@ static struct option fsck_opts[] = {int cmd_fsck (int argc,const char **argv,const char *prefix) { -int i;struct object_directory *odb;/* fsck knows how to handle missing promisor objects */
@@ -994,7 +990,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) errors_found |=ERROR_OBJECT ; } -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {const char *arg = argv[i];struct object_id oid;if (!repo_get_oid (the_repository, arg, &oid)) {
@@ -1030,13 +1026,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) }if (keep_cache_objects) { -struct worktree **worktrees, **p; +struct worktree **worktrees; verify_index_checksum =1 ; verify_ce_order =1 ; worktrees =get_worktrees (); -for (p = worktrees; *p; p++) { +for (struct worktree **p = worktrees; *p; p++) {struct worktree *wt = *p;struct index_state istate =INDEX_STATE_INIT (the_repository);
builtin/fsmonitor--daemon.c +3 -11
@@ -227,12 +227,9 @@ static enum fsmonitor_cookie_item_result with_lock__wait_for_cookie(static void with_lock__mark_cookies_seen (struct fsmonitor_daemon_state *state,const struct string_list *cookie_names) { -/* assert current thread holding state->main_lock */ - -int k;int nr_seen =0 ; -for (k =0 ; k < cookie_names->nr; k++) { +for (int k =0 ; k < cookie_names->nr; k++) {struct fsmonitor_cookie_item key;struct fsmonitor_cookie_item *cookie;
@@ -468,13 +465,11 @@ void fsmonitor_batch__add_path(struct fsmonitor_batch *batch,static void fsmonitor_batch__combine (struct fsmonitor_batch *batch_dest,const struct fsmonitor_batch *batch_src) { -size_t k; -ALLOC_GROW (batch_dest->interned_paths, batch_dest->nr + batch_src->nr +1 , batch_dest->alloc); -for (k =0 ; k < batch_src->nr; k++) +for (size_t k =0 ; k < batch_src->nr; k++) batch_dest->interned_paths[batch_dest->nr++] = batch_src->interned_paths[k]; }
@@ -512,9 +507,6 @@ static struct fsmonitor_batch *with_lock__truncate_old_batches(struct fsmonitor_daemon_state *state, const struct fsmonitor_batch *batch_marker) { -/* assert current thread holding state->main_lock */ - -const struct fsmonitor_batch *batch; struct fsmonitor_batch *remainder;if (!batch_marker)
@@ -524,7 +516,7 @@ static struct fsmonitor_batch *with_lock__truncate_old_batches( batch_marker->batch_seq_nr, (uint64_t)batch_marker->pinned_time); -for (batch = batch_marker; batch; batch = batch->next) { +for (const struct fsmonitor_batch *batch = batch_marker; batch; batch = batch->next) {time_t t;if (!batch->pinned_time)/* an overflow batch */
builtin/gc.c +10 -18
@@ -80,8 +80,7 @@ static struct string_list pack_garbage = STRING_LIST_INIT_DUP;static void clean_pack_garbage (void ) { -int i; -for (i =0 ; i < pack_garbage.nr; i++) +for (int i =0 ; i < pack_garbage.nr; i++)unlink_or_warn (pack_garbage.items[i].string);string_list_clear (&pack_garbage,0 ); }
@@ -226,9 +225,9 @@ static int too_many_loose_objects(void)static struct packed_git *find_base_packs (struct string_list *packs,unsigned long limit) { -struct packed_git *p, *base =NULL ; +struct packed_git *base =NULL ; -for (p =get_all_packs (the_repository); p; p = p->next) { +for (struct packed_git *p =get_all_packs (the_repository); p; p = p->next) {if (!p->pack_local || p->is_cruft)continue ;if (limit) {
@@ -1100,7 +1099,6 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts)static int incremental_repack_auto_condition (void ) { -struct packed_git *p;int incremental_repack_auto_limit =10 ;int count =0 ;
@@ -1116,9 +1114,7 @@ static int incremental_repack_auto_condition(void)if (incremental_repack_auto_limit <0 )return 1 ; -for (p =get_packed_git (the_repository); - count < incremental_repack_auto_limit && p; - p = p->next) { +for (struct packed_git *p =get_packed_git (the_repository); count < incremental_repack_auto_limit && p; p = p->next) {if (!p->multi_pack_index) count++; }
@@ -1177,11 +1173,10 @@ static off_t get_auto_pack_size(void)off_t max_size =0 ;off_t second_largest_size =0 ;off_t result_size; -struct packed_git *p;struct repository *r = the_repository;reprepare_packed_git (r); -for (p =get_all_packs (r); p; p = p->next) { +for (struct packed_git *p =get_all_packs (r); p; p = p->next) {if (p->pack_size > max_size) { second_largest_size = max_size; max_size = p->pack_size;
@@ -1389,14 +1384,13 @@ static void initialize_maintenance_strategy(void)static void initialize_task_config (int schedule) { -int i;struct strbuf config_name =STRBUF_INIT ;gc_config ();if (schedule)initialize_maintenance_strategy (); -for (i =0 ; i <TASK__COUNT ; i++) { +for (int i =0 ; i <TASK__COUNT ; i++) {int config_value;char *config_str;
@@ -1423,12 +1417,12 @@ static void initialize_task_config(int schedule) static int task_option_parse(const struct option *opt UNUSED,const char *arg,int unset) { -int i, num_selected =0 ; +int num_selected =0 ;struct maintenance_task *task =NULL ;BUG_ON_OPT_NEG (unset); -for (i =0 ; i <TASK__COUNT ; i++) { +for (int i =0 ; i <TASK__COUNT ; i++) {if (tasks[i].selected_order >=0 ) num_selected++;if (!strcasecmp (tasks[i].name, arg)) {
@@ -1453,7 +1447,6 @@ static int task_option_parse(const struct option *opt UNUSED, static int maintenance_run(int argc, const char **argv, const char *prefix) { - int i; struct maintenance_run_opts opts; struct option builtin_maintenance_run_options[] = { OPT_BOOL(0, "auto", &opts.auto_flag,
@@ -1472,7 +1465,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix) opts.quiet = !isatty (2 ); -for (i =0 ; i <TASK__COUNT ; i++) +for (int i =0 ; i <TASK__COUNT ; i++) tasks[i].selected_order =-1 ; argc = parse_options(argc, argv, prefix,
@@ -2691,7 +2684,6 @@ static void validate_scheduler(enum scheduler scheduler)static int update_background_schedule (const struct maintenance_start_opts *opts,int enable) { -unsigned int i;int result =0 ;struct lock_file lk;char *lock_path =xstrfmt ("%s/schedule" , the_repository->objects->odb->path);
@@ -2701,7 +2693,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,return error (_ ("another process is scheduling background maintenance" )); } -for (i =1 ; i <ARRAY_SIZE (scheduler_fn); i++) { +for (unsigned int i =1 ; i <ARRAY_SIZE (scheduler_fn); i++) {if (enable && opts->scheduler == i)continue ;if (!scheduler_fn[i].is_available ())
builtin/grep.c +9 -15
@@ -179,9 +179,7 @@ static void work_done(struct work_item *w)static void free_repos (void ) { -int i; - -for (i =0 ; i < repos_to_free_nr; i++) { +for (int i =0 ; i < repos_to_free_nr; i++) {repo_clear (repos_to_free[i]);free (repos_to_free[i]); }
@@ -250,7 +248,6 @@ static void start_threads(struct grep_opt *opt)static int wait_all (void ) {int hit =0 ; -int i;if (!HAVE_THREADS )BUG ("Never call this function unless you have started threads" );
@@ -268,7 +265,7 @@ static int wait_all(void)pthread_cond_broadcast (&cond_add);grep_unlock (); -for (i =0 ; i < num_threads; i++) { +for (int i =0 ; i < num_threads; i++) {void *h;pthread_join (threads[i], &h); hit |= (int ) (intptr_t ) h;
@@ -418,9 +415,9 @@ static void run_pager(struct grep_opt *opt, const char *prefix) {struct string_list *path_list = opt->output_priv;struct child_process child =CHILD_PROCESS_INIT ; -int i, status; +int status; -for (i =0 ; i < path_list->nr; i++) +for (int i =0 ; i < path_list->nr; i++)strvec_push (&child.args, path_list->items[i].string); child.dir = prefix; child.use_shell =1 ;
@@ -544,7 +541,6 @@ static int grep_cache(struct grep_opt *opt, {struct repository *repo = opt->repo;int hit =0 ; -int nr;struct strbuf name =STRBUF_INIT ;int name_base_len =0 ;if (repo->submodule_prefix) {
@@ -555,7 +551,7 @@ static int grep_cache(struct grep_opt *opt,if (repo_read_index (repo) <0 )die (_ ("index file corrupt" )); -for (nr =0 ; nr < repo->index->cache_nr; nr++) { +for (int nr =0 ; nr < repo->index->cache_nr; nr++) {const struct cache_entry *ce = repo->index->cache[nr];if (!cached &&ce_skip_worktree (ce))
@@ -726,11 +722,10 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,static int grep_objects (struct grep_opt *opt,const struct pathspec *pathspec,const struct object_array *list) { -unsigned int i;int hit =0 ;const unsigned int nr = list->nr; -for (i =0 ; i < nr; i++) { +for (unsigned int i =0 ; i < nr; i++) {struct object *real_obj;obj_read_lock ();
@@ -770,7 +765,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec, int exc_std, int use_index) {struct dir_struct dir =DIR_INIT ; -int i, hit =0 ; +int hit =0 ;if (!use_index) dir.flags |=DIR_NO_GITLINKS ;
@@ -778,7 +773,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,setup_standard_excludes (&dir);fill_directory (&dir, opt->repo->index, pathspec); -for (i =0 ; i < dir.nr; i++) { +for (int i =0 ; i < dir.nr; i++) { hit |=grep_file (opt, dir.entries[i]->name);if (hit && opt->status_only)break ;
@@ -1148,8 +1143,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)* "do what I mean" case, we verify and complain when that isn't true. */ if (!seen_dashdash) { -int j; -for (j = i; j < argc; j++) +for (int j = i; j < argc; j++)verify_filename (prefix, argv[j], j == i && allow_revs); }
builtin/hash-object.c +1 -2
@@ -112,7 +112,6 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"path" , &vpath,N_ ("file" ),N_ ("process file as it were from this path" )),OPT_END () }; -int i;const char *errstr =NULL ; argc = parse_options(argc, argv, prefix, hash_object_options,
@@ -153,7 +152,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)if (hashstdin)hash_fd (0 , type, vpath, flags, literally); -for (i =0 ; i < argc; i++) { +for (int i =0 ; i < argc; i++) {const char *arg = argv[i];char *to_free =NULL ;
builtin/help.c +4 -10
@@ -122,14 +122,11 @@ static void list_config_help(enum show_config_type type) { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids }, { NULL, NULL, NULL } }; -const char **p;struct slot_expansion *e;struct string_list keys =STRING_LIST_INIT_DUP ;struct string_list keys_uniq =STRING_LIST_INIT_DUP ;struct string_list_item *item; -int i; - -for (p = config_name_list; *p; p++) { +for (const char **p = config_name_list; *p; p++) {const char *var = *p;struct strbuf sb =STRBUF_INIT ;
@@ -154,7 +151,7 @@ static void list_config_help(enum show_config_type type) e->prefix, e->placeholder);string_list_sort (&keys); -for (i =0 ; i < keys.nr; i++) { +for (int i =0 ; i < keys.nr; i++) {const char *var = keys.items[i].string;const char *wildcard, *tag, *cut;const char *dot =NULL ;
@@ -216,9 +213,7 @@ static enum help_format parse_help_format(const char *format)static const char *get_man_viewer_info (const char *name) { -struct man_viewer_info_list *viewer; - -for (viewer = man_viewer_info_list; viewer; viewer = viewer->next) +for (struct man_viewer_info_list *viewer = man_viewer_info_list; viewer; viewer = viewer->next) {if (!strcasecmp (name, viewer->name))return viewer->info;
@@ -489,11 +484,10 @@ static void exec_viewer(const char *name, const char *page)static void show_man_page (const char *page) { -struct man_viewer_list *viewer;const char *fallback =getenv ("GIT_MAN_VIEWER" );setup_man_path (); -for (viewer = man_viewer_list; viewer; viewer = viewer->next) +for (struct man_viewer_list *viewer = man_viewer_list; viewer; viewer = viewer->next) {exec_viewer (viewer->name, page);/* will return when unable */ }
builtin/hook.c +1 -2
@@ -20,7 +20,6 @@ static const char * const builtin_hook_run_usage[] = {static int run (int argc,const char **argv,const char *prefix) { -int i;struct run_hooks_opt opt =RUN_HOOKS_OPT_INIT ;int ignore_missing =0 ;const char *hook_name;
@@ -49,7 +48,7 @@ static int run(int argc, const char **argv, const char *prefix) goto usage;/* Add our arguments, start after -- */ -for (i =2 ; i < argc; i++) +for (int i =2 ; i < argc; i++)strvec_push (&opt.args, argv[i]);/* Need to take into account core.hooksPath */
builtin/index-pack.c +5 -8
@@ -186,7 +186,6 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)*/ static void init_thread (void ) { -int i;init_recursive_mutex (&read_mutex);pthread_mutex_init (&counter_mutex,NULL );pthread_mutex_init (&work_mutex,NULL );
@@ -194,7 +193,7 @@ static void init_thread(void)pthread_mutex_init (&deepest_delta_mutex,NULL );pthread_key_create (&key,NULL );CALLOC_ARRAY (thread_data, nr_threads); -for (i =0 ; i < nr_threads; i++) { +for (int i =0 ; i < nr_threads; i++) { thread_data[i].pack_fd =xopen (curr_pack,O_RDONLY ); }
@@ -203,7 +202,6 @@ static void init_thread(void)static void cleanup_thread (void ) { -int i;if (!threads_active)return ; threads_active =0 ;
@@ -212,7 +210,7 @@ static void cleanup_thread(void)pthread_mutex_destroy (&work_mutex);if (show_stat)pthread_mutex_destroy (&deepest_delta_mutex); -for (i =0 ; i < nr_threads; i++) +for (int i =0 ; i < nr_threads; i++)close (thread_data[i].pack_fd);pthread_key_delete (key);free (thread_data);
@@ -261,14 +259,14 @@ static unsigned check_object(struct object *obj)static unsigned check_objects (void ) { -unsigned i, max, foreign_nr =0 ; +unsigned max, foreign_nr =0 ; max =get_max_object_index ();if (verbose) progress =start_delayed_progress (_ ("Checking objects" ), max); -for (i =0 ; i < max; i++) { +for (unsigned i =0 ; i < max; i++) { foreign_nr +=check_object (get_indexed_object (i));display_progress (progress, i +1 ); }
@@ -1627,7 +1625,6 @@ static void read_v2_anomalous_offsets(struct packed_git *p, struct pack_idx_option *opts) {const uint32_t *idx1, *idx2; -uint32_t i;/* The address of the 4-byte offset table */ idx1 = (((const uint32_t *)((const uint8_t *)p->index_data + p->crc_offset))
@@ -1637,7 +1634,7 @@ static void read_v2_anomalous_offsets(struct packed_git *p,/* The address of the 8-byte offset table */ idx2 = idx1 + p->num_objects; -for (i =0 ; i < p->num_objects; i++) { +for (uint32_t i =0 ; i < p->num_objects; i++) {uint32_t off =ntohl (idx1[i]);if (!(off &0x80000000 ))continue ;
builtin/interpret-trailers.c +1 -2
@@ -130,8 +130,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) options);if (argc) { -int i; -for (i =0 ; i < argc; i++) +for (int i =0 ; i < argc; i++)process_trailers (argv[i], &opts, &trailers); }else {if (opts.in_place)
builtin/log.c +6 -11
@@ -190,7 +190,6 @@ static void cmd_log_init_defaults(struct rev_info *rev)static void set_default_decoration_filter (struct decoration_filter *decoration_filter) { -int i;char *value =NULL ;struct string_list *include = decoration_filter->include_ref_pattern;const struct string_list *config_exclude;
@@ -224,7 +223,7 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f* No command-line or config options were given, so * populate with sensible defaults. */ -for (i =0 ; i <ARRAY_SIZE (ref_namespace); i++) { +for (int i =0 ; i <ARRAY_SIZE (ref_namespace); i++) {if (!ref_namespace[i].decoration)continue ;
@@ -734,7 +733,6 @@ static void show_setup_revisions_tweak(struct rev_info *rev)int cmd_show (int argc,const char **argv,const char *prefix) {struct rev_info rev; -unsigned int i;struct setup_revision_opt opt;struct pathspec match_all;int ret =0 ;
@@ -765,7 +763,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)return cmd_log_deinit (cmd_log_walk (&rev), &rev); rev.diffopt.no_free =1 ; -for (i =0 ; i < rev.pending.nr && !ret; i++) { +for (unsigned int i =0 ; i < rev.pending.nr && !ret; i++) {struct object *o = rev.pending.objects[i].item;const char *name = rev.pending.objects[i].name;switch (o->type) {
@@ -1211,13 +1209,13 @@ static void print_signature(FILE *file)static char *find_branch_name (struct rev_info *rev) { -int i, positive =-1 ; +int positive =-1 ;struct object_id branch_oid;const struct object_id *tip_oid;const char *ref, *v;char *full_ref, *branch =NULL ; -for (i =0 ; i < rev->cmdline.nr; i++) { +for (int i =0 ; i < rev->cmdline.nr; i++) {if (rev->cmdline.rev[i].flags &UNINTERESTING )continue ;if (positive <0 )
@@ -1760,7 +1758,6 @@ static void prepare_bases(struct base_tree_info *bases,struct rev_info revs;struct diff_options diffopt;struct commit_base commit_base; -int i;if (!base)return ;
@@ -1775,7 +1772,7 @@ static void prepare_bases(struct base_tree_info *bases,repo_init_revisions (the_repository, &revs,NULL ); revs.max_parents =1 ; revs.topo_order =1 ; -for (i =0 ; i < total; i++) { +for (int i =0 ; i < total; i++) { list[i]->object.flags &= ~UNINTERESTING ;add_pending_object (&revs, &list[i]->object,"rev_list" ); *commit_base_at (&commit_base, list[i]) =1 ;
@@ -1806,8 +1803,6 @@ static void prepare_bases(struct base_tree_info *bases,static void print_bases (struct base_tree_info *bases,FILE *file) { -int i; -/* Only do this once, either for the cover or for the first one */ if (is_null_oid (&bases->base_commit))return ;
@@ -1816,7 +1811,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)fprintf (file,"\nbase-commit: %s\n" ,oid_to_hex (&bases->base_commit));/* Show the prerequisite patches */ -for (i = bases->nr_patch_id -1 ; i >=0 ; i--) +for (int i = bases->nr_patch_id -1 ; i >=0 ; i--)fprintf (file,"prerequisite-patch-id: %s\n" ,oid_to_hex (&bases->patch_id[i]));free (bases->patch_id);
builtin/ls-files.c +5 -9
@@ -163,9 +163,7 @@ static void show_dir_entry(struct index_state *istate,static void show_other_files (struct index_state *istate,const struct dir_struct *dir) { -int i; - -for (i =0 ; i < dir->nr; i++) { +for (int i =0 ; i < dir->nr; i++) {struct dir_entry *ent = dir->entries[i];if (!index_name_is_other (istate, ent->name, ent->len))continue ;
@@ -176,8 +174,7 @@ static void show_other_files(struct index_state *istate,static void show_killed_files (struct index_state *istate,const struct dir_struct *dir) { -int i; -for (i =0 ; i < dir->nr; i++) { +for (int i =0 ; i < dir->nr; i++) {struct dir_entry *ent = dir->entries[i];char *cp, *sp;int pos, len, killed =0 ;
@@ -400,7 +397,6 @@ static void construct_fullname(struct strbuf *out, const struct repository *repostatic void show_files (struct repository *repo,struct dir_struct *dir) { -int i;struct strbuf fullname =STRBUF_INIT ;/* For cached/deleted files we don't need to even do the readdir */
@@ -420,7 +416,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)if (!show_sparse_dirs)ensure_full_index (repo->index); -for (i =0 ; i < repo->index->cache_nr; i++) { +for (int i =0 ; i < repo->index->cache_nr; i++) {const struct cache_entry *ce = repo->index->cache[i];struct stat st;int stat_err;
@@ -571,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt,int cmd_ls_files (int argc,const char **argv,const char *cmd_prefix) { -int require_work_tree =0 , show_tag =0 , i; +int require_work_tree =0 , show_tag =0 ;char *max_prefix;struct dir_struct dir =DIR_INIT ;struct pattern_list *pl;
@@ -663,7 +659,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) argc =parse_options (argc, argv, prefix, builtin_ls_files_options, ls_files_usage,0 ); pl =add_pattern_list (&dir,EXC_CMDL ,"--exclude option" ); -for (i =0 ; i < exclude_list.nr; i++) { +for (int i =0 ; i < exclude_list.nr; i++) {add_pattern (exclude_list.items[i].string,"" ,0 , pl, --exclude_args); }
builtin/ls-tree.c +3 -5
@@ -55,15 +55,13 @@ struct ls_tree_options {static int show_recursive (struct ls_tree_options *options,const char *base,size_t baselen,const char *pathname) { -int i; -if (options->ls_options &LS_RECURSIVE )return 1 ;if (!options->pathspec.nr)return 0 ; -for (i =0 ; i < options->pathspec.nr; i++) { +for (int i =0 ; i < options->pathspec.nr; i++) {const char *spec = options->pathspec.items[i].match;size_t len, speclen;
@@ -341,7 +339,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) {struct object_id oid;struct tree *tree; -int i, full_tree =0 ; +int full_tree =0 ;int full_name = !prefix || !*prefix;read_tree_fn_t fn =NULL ;enum ls_tree_cmdmode cmdmode =MODE_DEFAULT ;
@@ -419,7 +417,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) ~(PATHSPEC_FROMTOP |PATHSPEC_LITERAL ),PATHSPEC_PREFER_CWD , prefix, argv + 1); -for (i =0 ; i < options.pathspec.nr; i++) +for (int i =0 ; i < options.pathspec.nr; i++) options.pathspec.items[i].nowildcard_len = options.pathspec.items[i].len; options.pathspec.has_wildcard =0 ; tree =parse_tree_indirect (&oid);
builtin/mailsplit.c +2 -4
@@ -114,10 +114,9 @@ static int populate_maildir_list(struct string_list *list, const char *path)struct dirent *dent;char *name =NULL ;char *subs[] = {"cur" ,"new" ,NULL }; -char **sub;int ret =-1 ; -for (sub = subs; *sub; ++sub) { +for (char **sub = subs; *sub; ++sub) {free (name); name =xstrfmt ("%s/%s" , path, *sub);if (!(dir =opendir (name))) {
@@ -172,7 +171,6 @@ static int split_maildir(const char *maildir, const char *dir,char *file =NULL ;FILE *f =NULL ;int ret =-1 ; -int i;struct string_list list =STRING_LIST_INIT_DUP ; list.cmp = maildir_filename_cmp;
@@ -180,7 +178,7 @@ static int split_maildir(const char *maildir, const char *dir,if (populate_maildir_list (&list, maildir) <0 ) goto out; -for (i =0 ; i < list.nr; i++) { +for (int i =0 ; i < list.nr; i++) {char *name;free (file);
builtin/merge-base.c +8 -12
@@ -10,7 +10,7 @@static int show_merge_base (struct commit **rev,int rev_nr,int show_all) { -struct commit_list *result, *r; +struct commit_list *result; result =repo_get_merge_bases_many_dirty (the_repository, rev[0 ], rev_nr -1 , rev +1 );
@@ -18,7 +18,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)if (!result)return 1 ; -for (r = result; r; r = r->next) { +for (struct commit_list *r = result; r; r = r->next) {printf ("%s\n" ,oid_to_hex (&r->item->object.oid));if (!show_all)break ;
@@ -53,10 +53,8 @@ static struct commit *get_commit_reference(const char *arg)static int handle_independent (int count,const char **args) { -struct commit_list *revs =NULL , *rev; -int i; - -for (i = count -1 ; i >=0 ; i--) +struct commit_list *revs =NULL ; +for (int i = count -1 ; i >=0 ; i--)commit_list_insert (get_commit_reference (args[i]), &revs);reduce_heads_replace (&revs);
@@ -64,7 +62,7 @@ static int handle_independent(int count, const char **args)if (!revs)return 1 ; -for (rev = revs; rev; rev = rev->next) +for (struct commit_list *rev = revs; rev; rev = rev->next)printf ("%s\n" ,oid_to_hex (&rev->item->object.oid));free_commit_list (revs);
@@ -74,10 +72,8 @@ static int handle_independent(int count, const char **args)static int handle_octopus (int count,const char **args,int show_all) {struct commit_list *revs =NULL ; -struct commit_list *result, *rev; -int i; - -for (i = count -1 ; i >=0 ; i--) +struct commit_list *result; +for (int i = count -1 ; i >=0 ; i--)commit_list_insert (get_commit_reference (args[i]), &revs); result =get_octopus_merge_bases (revs);
@@ -87,7 +83,7 @@ static int handle_octopus(int count, const char **args, int show_all)if (!result)return 1 ; -for (rev = result; rev; rev = rev->next) { +for (struct commit_list *rev = result; rev; rev = rev->next) {printf ("%s\n" ,oid_to_hex (&rev->item->object.oid));if (!show_all)break ;
builtin/merge-index.c +1 -2
@@ -63,10 +63,9 @@ static void merge_one_path(const char *path)static void merge_all (void ) { -int i;/* TODO: audit for interaction with sparse-index. */ ensure_full_index (&the_index); -for (i =0 ; i < the_index.cache_nr; i++) { +for (int i =0 ; i < the_index.cache_nr; i++) {const struct cache_entry *ce = the_index.cache[i];if (!ce_stage (ce))continue ;
builtin/merge-tree.c +3 -6
@@ -109,8 +109,7 @@ static void *origin(struct merge_list *entry, unsigned long *size) static int show_outf(void *priv UNUSED, mmbuffer_t *mb, int nbuf) { -int i; -for (i =0 ; i < nbuf; i++) +for (int i =0 ; i < nbuf; i++)printf ("%.*s" , (int ) mb[i].size, mb[i].ptr);return 0 ; }
@@ -267,10 +266,9 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_infostatic void unresolved (const struct traverse_info *info,struct name_entry n[3 ]) {struct merge_list *entry =NULL ; -int i;unsigned dirmask =0 , mask =0 ; -for (i =0 ; i <3 ; i++) { +for (int i =0 ; i <3 ; i++) { mask |= (1 << i);/* * Treat missing entries as directories so that we return
@@ -490,10 +488,9 @@ static int real_merge(struct merge_tree_options *o,if (!result.clean) {struct string_list conflicted_files =STRING_LIST_INIT_NODUP ;const char *last =NULL ; -int i;merge_get_conflicted_files (&result, &conflicted_files); -for (i =0 ; i < conflicted_files.nr; i++) { +for (int i =0 ; i < conflicted_files.nr; i++) {const char *name = conflicted_files.items[i].string;struct stage_info *c = conflicted_files.items[i].util;if (!o->name_only)
builtin/merge.c +14 -22
@@ -393,7 +393,6 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead {struct rev_info rev;struct strbuf out =STRBUF_INIT ; -struct commit_list *j;struct pretty_print_context ctx = {0 };printf (_ ("Squash commit -- not updating HEAD\n" ));
@@ -405,7 +404,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead commit->object.flags |=UNINTERESTING ;add_pending_object (&rev, &commit->object,NULL ); -for (j = remoteheads; j; j = j->next) +for (struct commit_list *j = remoteheads; j; j = j->next)add_pending_object (&rev, &j->item->object,NULL );setup_revisions (0 ,NULL , &rev,NULL );
@@ -650,7 +649,7 @@ static int git_merge_config(const char *k, const char *v,static int read_tree_trivial (struct object_id *common,struct object_id *head,struct object_id *one) { -int i, nr_trees =0 ; +int nr_trees =0 ;struct tree *trees[MAX_UNPACK_TREES ];struct tree_desc t[MAX_UNPACK_TREES ];struct unpack_trees_options opts;
@@ -675,7 +674,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,return -1 ; opts.fn = threeway_merge;cache_tree_free (&the_index.cache_tree); -for (i =0 ; i < nr_trees; i++) { +for (int i =0 ; i < nr_trees; i++) {parse_tree (trees[i]);init_tree_desc (t+i, trees[i]->buffer, trees[i]->size); }
@@ -704,11 +703,10 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,if (!strcmp (strategy,"recursive" ) || !strcmp (strategy,"subtree" ) || !strcmp (strategy,"ort" )) {struct lock_file lock =LOCK_INIT ; -int clean, x; +int clean;struct commit *result;struct commit_list *reversed =NULL ;struct merge_options o; -struct commit_list *j;if (remoteheads->next) {error (_ ("Not handling anything other than two heads merge." ));
@@ -722,14 +720,14 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, o.show_rename_progress = show_progress ==-1 ?isatty (2 ) : show_progress; -for (x =0 ; x < xopts.nr; x++) +for (int x =0 ; x < xopts.nr; x++)if (parse_merge_opt (&o, xopts.v[x]))die (_ ("unknown strategy option: -X%s" ), xopts.v[x]); o.branch1 = head_arg; o.branch2 =merge_remote_util (remoteheads->item)->name; -for (j = common; j; j = j->next) +for (struct commit_list *j = common; j; j = j->next)commit_list_insert (j->item, &reversed); repo_hold_locked_index(the_repository, &lock,
@@ -765,9 +763,9 @@ static void count_diff_files(struct diff_queue_struct *q,static int count_unmerged_entries (void ) { -int i, ret =0 ; +int ret =0 ; -for (i =0 ; i < the_index.cache_nr; i++) +for (int i =0 ; i < the_index.cache_nr; i++)if (ce_stage (the_index.cache[i]))
Lines of this file are not shown. View the raw message.
builtin/pack-objects.c +15 -34
49 lines not on this page · raw message
builtin/receive-pack.c +14 -32
46 lines not on this page · raw message
commit-graph.c +19 -33
52 lines not on this page · raw message
diff.c +32 -61
93 lines not on this page · raw message
dir.c +21 -36
57 lines not on this page · raw message
graph.c +14 -37
51 lines not on this page · raw message
line-log.c +17 -26
43 lines not on this page · raw message
merge-ort.c +23 -39
62 lines not on this page · raw message
midx.c +19 -43
62 lines not on this page · raw message
object-name.c +17 -38
55 lines not on this page · raw message
object.c +12 -30
42 lines not on this page · raw message
pack-bitmap.c +18 -33
51 lines not on this page · raw message
packfile.c +25 -57
82 lines not on this page · raw message
read-cache.c +18 -44
62 lines not on this page · raw message
ref-filter.c +15 -35
50 lines not on this page · raw message
refs.c +19 -39
58 lines not on this page · raw message
remote.c +29 -55
84 lines not on this page · raw message
revision.c +24 -45
69 lines not on this page · raw message
unpack-trees.c +14 -34
48 lines not on this page · raw message
wt-status.c +18 -33
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0.522.g2a540e432f
Part of the diff is not shown here. View the raw message.
Quoted 5 lines · Elia Pinto
With the exception of
cbtree.c, which would need initial reworking to remove the usage of goto, it expands the use of variable scope reduction in for loops as permitted by the C99 standard, which was first introduced in the git codebase with commit44ba10d6.
Thanks, but ...
Our test balloon may have proven that nobody will be inconvenienced, and it does mean we can be liberal using it when we add new code or update existing loops "while at it", but I personally do not think such a code churn is very welcome.
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Elia Pinto
With the exception of
cbtree.c, which would need initial reworking to remove the usage of goto, it expands the use of variable scope reduction in for loops as permitted by the C99 standard, which was first introduced in the git codebase with commit44ba10d6.
Quoted 6 lines
Thanks, but ...
Our test balloon may have proven that nobody will be inconvenienced, and it does mean we can be liberal using it when we add new code or update existing loops "while at it", but I personally do not think such a code churn is very welcome.
Perhaps such changes could be accepted when they are made in only one file as part of a microproject though?
Quoted 2 lines · Christian Couder
Perhaps such changes could be accepted when they are made in only one file as part of a microproject though?
Yes, a microproject is not about helping this project, but is about us investing our cycles in helping aspiring developers with small practice material. Even though we may not want to see massive code churn, we can view the cost of reviewing and accepting small changes as a part of the cost to onboard new folks.
Il giorno gio 15 feb 2024 alle ore 18:33 Junio C Hamano <[email protected]> ha scritto:
Quoted 9 lines
Quoted 5 lines · Elia Pinto
With the exception of
cbtree.c, which would need initial reworking to remove the usage of goto, it expands the use of variable scope reduction in for loops as permitted by the C99 standard, which was first introduced in the git codebase with commit44ba10d6.
Quoted 6 lines
Thanks, but ...
Our test balloon may have proven that nobody will be inconvenienced, and it does mean we can be liberal using it when we add new code or update existing loops "while at it", but I personally do not think such a code churn is very welcome.
Thank you for your reply. I can understand that, clearly. However, this means that extensive code
refactoring contributions are never welcome. I am not saying this is a problem, but just an observation.
Best
Quoted 4 lines · Elia Pinto
Thank you for your reply. I can understand that, clearly. However, this means that extensive code
refactoring contributions are never welcome. I am not saying this is a problem, but just an observation.
Such changes can happen and have happened when the benefit of such code churn outweighs the cost of reviewing *and* cost of updating or adjusting in-flight topics that may already or may not yet be in my tree. Coccinelle-driven patches that can be mechanically reproduced and whose validity can be trusted can be one way to reduce the review and maintenance cost for such a tree-wide change.
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Elia Pinto
With the exception of
cbtree.c, which would need initial reworking to remove the usage of goto, it expands the use of variable scope reduction in for loops as permitted by the C99 standard, which was first introduced in the git codebase with commit44ba10d6.
Quoted 6 lines
Thanks, but ...
Our test balloon may have proven that nobody will be inconvenienced, and it does mean we can be liberal using it when we add new code or update existing loops "while at it", but I personally do not think such a code churn is very welcome.
I will also say that sending one giant patch for this may be a bit hard to review. While I will defer to Junio's opinion as the maintainer, I would be more inclined to review this kind of series if it came in in smaller patches, a few at a time, in which case I would find it a welcome improvement.
Since my time to work on Git is relatively limited, having, say, a five-patch series where we each update a single file would let me review these changes in a relatively short amount of time, which I would be more likely to be able to find time for. Looking at the large patch, I'd be worried that I wouldn't be able to get through the entire thing in one sitting.
Of course, if you bring in a nice Coccinelle patch for it, then that may make a longer (but still one-file-per-commit) series more viable, since it will help reviewers have more confidence in your change.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Quoted 5 lines · brian m. carlson
I will also say that sending one giant patch for this may be a bit hard to review. While I will defer to Junio's opinion as the maintainer, I would be more inclined to review this kind of series if it came in in smaller patches, a few at a time, in which case I would find it a welcome improvement.
True. As to the specific topic of using "for (int i = 0; ...)", it is tedious to review for mistakes and 17000+ lines of patch is not a way to do so. I do not think I would be able to spot a change in behaviour caused by a hunk like this
int i = 3; ... after some operations ... - for (i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) if (condition_on_i(i)) break; ... after some operations ... return i;
after scanning similar changes for 1000+ times in a single huge patch.