mirror of
https://github.com/git/git.git
synced 2025-01-22 07:24:10 +08:00
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
This commit is contained in:
commit
6e12570822
@ -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 ||
|
||||
|
@ -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;
|
||||
|
21
wrapper.c
21
wrapper.c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user