Skip to content

Commit 0434783

Browse files
committed
Merge branch 'ep/varscope'
Shrink lifetime of variables by moving their definitions to an inner scope where appropriate. * ep/varscope: builtin/gc.c: reduce scope of variables builtin/fetch.c: reduce scope of variable builtin/commit.c: reduce scope of variables builtin/clean.c: reduce scope of variable builtin/blame.c: reduce scope of variables builtin/apply.c: reduce scope of variables bisect.c: reduce scope of variable
2 parents a06f23c + 4f1c0b2 commit 0434783

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ static void mark_expected_rev(char *bisect_rev_hex)
685685

686686
static int bisect_checkout(char *bisect_rev_hex, int no_checkout)
687687
{
688-
int res;
689688

690689
mark_expected_rev(bisect_rev_hex);
691690

@@ -696,6 +695,7 @@ static int bisect_checkout(char *bisect_rev_hex, int no_checkout)
696695
die("update-ref --no-deref HEAD failed on %s",
697696
bisect_rev_hex);
698697
} else {
698+
int res;
699699
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
700700
if (res)
701701
exit(res);

builtin/apply.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,13 +1943,7 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
19431943
size - offset - hdrsize, patch);
19441944

19451945
if (!patchsize) {
1946-
static const char *binhdr[] = {
1947-
"Binary files ",
1948-
"Files ",
1949-
NULL,
1950-
};
19511946
static const char git_binary[] = "GIT binary patch\n";
1952-
int i;
19531947
int hd = hdrsize + offset;
19541948
unsigned long llen = linelen(buffer + hd, size - hd);
19551949

@@ -1965,6 +1959,12 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
19651959
patchsize = 0;
19661960
}
19671961
else if (!memcmp(" differ\n", buffer + hd + llen - 8, 8)) {
1962+
static const char *binhdr[] = {
1963+
"Binary files ",
1964+
"Files ",
1965+
NULL,
1966+
};
1967+
int i;
19681968
for (i = 0; binhdr[i]; i++) {
19691969
int len = strlen(binhdr[i]);
19701970
if (len < size - hd &&

builtin/blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,14 +1580,14 @@ static const char *format_time(unsigned long time, const char *tz_str,
15801580
int show_raw_time)
15811581
{
15821582
static char time_buf[128];
1583-
const char *time_str;
1584-
int time_len;
1585-
int tz;
15861583

15871584
if (show_raw_time) {
15881585
snprintf(time_buf, sizeof(time_buf), "%lu %s", time, tz_str);
15891586
}
15901587
else {
1588+
const char *time_str;
1589+
int time_len;
1590+
int tz;
15911591
tz = atoi(tz_str);
15921592
time_str = show_date(time, tz, blame_date_mode);
15931593
time_len = strlen(time_str);

builtin/clean.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
154154
DIR *dir;
155155
struct strbuf quoted = STRBUF_INIT;
156156
struct dirent *e;
157-
int res = 0, ret = 0, gone = 1, original_len = path->len, len, i;
157+
int res = 0, ret = 0, gone = 1, original_len = path->len, len;
158158
unsigned char submodule_head[20];
159159
struct string_list dels = STRING_LIST_INIT_DUP;
160160

@@ -242,6 +242,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
242242
}
243243

244244
if (!*dir_gone && !quiet) {
245+
int i;
245246
for (i = 0; i < dels.nr; i++)
246247
printf(dry_run ? _(msg_would_remove) : _(msg_remove), dels.items[i].string);
247248
}

builtin/commit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
307307
int fd;
308308
struct string_list partial;
309309
struct pathspec pathspec;
310-
char *old_index_env = NULL;
311310
int refresh_flags = REFRESH_QUIET;
312311

313312
if (is_status)
@@ -320,6 +319,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
320319
die(_("index file corrupt"));
321320

322321
if (interactive) {
322+
char *old_index_env = NULL;
323323
fd = hold_locked_index(&index_lock, 1);
324324

325325
refresh_cache_or_die(refresh_flags);
@@ -600,12 +600,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
600600
{
601601
struct stat statbuf;
602602
struct strbuf committer_ident = STRBUF_INIT;
603-
int commitable, saved_color_setting;
603+
int commitable;
604604
struct strbuf sb = STRBUF_INIT;
605-
char *buffer;
606605
const char *hook_arg1 = NULL;
607606
const char *hook_arg2 = NULL;
608-
int ident_shown = 0;
609607
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
610608
int old_display_comment_prefix;
611609

@@ -649,6 +647,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
649647
logfile);
650648
hook_arg1 = "message";
651649
} else if (use_message) {
650+
char *buffer;
652651
buffer = strstr(use_message_buffer, "\n\n");
653652
if (!use_editor && (!buffer || buffer[2] == '\0'))
654653
die(_("commit has empty message"));
@@ -753,6 +752,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
753752
/* This checks if committer ident is explicitly given */
754753
strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
755754
if (use_editor && include_status) {
755+
int ident_shown = 0;
756+
int saved_color_setting;
756757
char *ai_tmp, *ci_tmp;
757758
if (whence != FROM_COMMIT)
758759
status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1514,7 +1515,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
15141515
struct ref_lock *ref_lock;
15151516
struct commit_list *parents = NULL, **pptr = &parents;
15161517
struct stat statbuf;
1517-
int allow_fast_forward = 1;
15181518
struct commit *current_head = NULL;
15191519
struct commit_extra_header *extra = NULL;
15201520

@@ -1562,6 +1562,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
15621562
} else if (whence == FROM_MERGE) {
15631563
struct strbuf m = STRBUF_INIT;
15641564
FILE *fp;
1565+
int allow_fast_forward = 1;
15651566

15661567
if (!reflog_msg)
15671568
reflog_msg = "commit (merge)";

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ static int fetch_multiple(struct string_list *list)
10261026

10271027
static int fetch_one(struct remote *remote, int argc, const char **argv)
10281028
{
1029-
int i;
10301029
static const char **refs = NULL;
10311030
struct refspec *refspec;
10321031
int ref_nr = 0;
@@ -1050,6 +1049,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
10501049

10511050
if (argc > 0) {
10521051
int j = 0;
1052+
int i;
10531053
refs = xcalloc(argc + 1, sizeof(const char *));
10541054
for (i = 0; i < argc; i++) {
10551055
if (!strcmp(argv[i], "tag")) {

builtin/gc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,12 @@ static int need_to_gc(void)
188188
static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
189189
{
190190
static struct lock_file lock;
191-
static char locking_host[128];
192191
char my_host[128];
193192
struct strbuf sb = STRBUF_INIT;
194193
struct stat st;
195194
uintmax_t pid;
196195
FILE *fp;
197-
int fd, should_exit;
196+
int fd;
198197

199198
if (pidfile)
200199
/* already locked */
@@ -206,6 +205,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
206205
fd = hold_lock_file_for_update(&lock, git_path("gc.pid"),
207206
LOCK_DIE_ON_ERROR);
208207
if (!force) {
208+
static char locking_host[128];
209+
int should_exit;
209210
fp = fopen(git_path("gc.pid"), "r");
210211
memset(locking_host, 0, sizeof(locking_host));
211212
should_exit =

0 commit comments

Comments
 (0)