diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-10-09 05:01:00 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-10-09 05:01:00 (GMT) |
commit | 6e12570822a904e2be554b05755c08f4d24be7e9 (patch) | |
tree | b6d276fd5205c5adb7a02c7bac6ba201b3ab3ac3 | |
parent | 772cad0afb834b9af8ee56511dc3df4d6e2f011d (diff) | |
parent | 53d687bf5f8008abd52b92120c7e22d4d81bdc71 (diff) | |
download | git-6e12570822a904e2be554b05755c08f4d24be7e9.zip git-6e12570822a904e2be554b05755c08f4d24be7e9.tar.gz git-6e12570822a904e2be554b05755c08f4d24be7e9.tar.bz2 |
Merge branch 'ah/cleanups'
Miscellaneous code clean-ups.
* ah/cleanups:
git_mkstemps_mode(): replace magic numbers with computed value
wrapper: use a loop instead of repetitive statements
diffcore-break: use a goto instead of a redundant if statement
commit-graph: remove a duplicate assignment
-rw-r--r-- | commit-graph.c | 5 | ||||
-rw-r--r-- | diffcore-break.c | 12 | ||||
-rw-r--r-- | wrapper.c | 21 |
3 files changed, 20 insertions, 18 deletions
diff --git a/commit-graph.c b/commit-graph.c index 6ae2009..fc4a43b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1533,8 +1533,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx) static void split_graph_merge_strategy(struct write_commit_graph_context *ctx) { - struct commit_graph *g = ctx->r->objects->commit_graph; - uint32_t num_commits = ctx->commits.nr; + struct commit_graph *g; + uint32_t num_commits; uint32_t i; int max_commits = 0; @@ -1546,6 +1546,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx) } g = ctx->r->objects->commit_graph; + num_commits = ctx->commits.nr; ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1; while (g && (g->num_commits <= size_mult * num_commits || diff --git a/diffcore-break.c b/diffcore-break.c index 875aefd..9d20a6a 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -286,17 +286,17 @@ void diffcore_merge_broken(void) /* Peer survived. Merge them */ merge_broken(p, pp, &outq); q->queue[j] = NULL; - break; + goto next; } } - if (q->nr <= j) - /* The peer did not survive, so we keep - * it in the output. - */ - diff_q(&outq, p); + /* The peer did not survive, so we keep + * it in the output. + */ + diff_q(&outq, p); } else diff_q(&outq, p); +next:; } free(q->queue); *q = outq; @@ -441,7 +441,9 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; - static const int num_letters = 62; + static const int num_letters = ARRAY_SIZE(letters) - 1; + static const char x_pattern[] = "XXXXXX"; + static const int num_x = ARRAY_SIZE(x_pattern) - 1; uint64_t value; struct timeval tv; char *filename_template; @@ -450,12 +452,12 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) len = strlen(pattern); - if (len < 6 + suffix_len) { + if (len < num_x + suffix_len) { errno = EINVAL; return -1; } - if (strncmp(&pattern[len - 6 - suffix_len], "XXXXXX", 6)) { + if (strncmp(&pattern[len - num_x - suffix_len], x_pattern, num_x)) { errno = EINVAL; return -1; } @@ -466,16 +468,15 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) */ gettimeofday(&tv, NULL); value = ((uint64_t)tv.tv_usec << 16) ^ tv.tv_sec ^ getpid(); - filename_template = &pattern[len - 6 - suffix_len]; + filename_template = &pattern[len - num_x - suffix_len]; for (count = 0; count < TMP_MAX; ++count) { uint64_t v = value; + int i; /* Fill in the random bits. */ - filename_template[0] = letters[v % num_letters]; v /= num_letters; - filename_template[1] = letters[v % num_letters]; v /= num_letters; - filename_template[2] = letters[v % num_letters]; v /= num_letters; - filename_template[3] = letters[v % num_letters]; v /= num_letters; - filename_template[4] = letters[v % num_letters]; v /= num_letters; - filename_template[5] = letters[v % num_letters]; v /= num_letters; + for (i = 0; i < num_x; i++) { + filename_template[i] = letters[v % num_letters]; + v /= num_letters; + } fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode); if (fd >= 0) |