Skip to content

Commit 74520b9

Browse files
authored
Merge pull request libgit2#5552 from libgit2/pks/small-fixes
Random code cleanups and fixes
2 parents 79d0e0c + 46637b5 commit 74520b9

File tree

3 files changed

+17
-63
lines changed

3 files changed

+17
-63
lines changed

src/checkout.c

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ enum {
4444
CHECKOUT_ACTION__REMOVE_CONFLICT = 16,
4545
CHECKOUT_ACTION__UPDATE_CONFLICT = 32,
4646
CHECKOUT_ACTION__MAX = 32,
47-
CHECKOUT_ACTION__DEFER_REMOVE = 64,
4847
CHECKOUT_ACTION__REMOVE_AND_UPDATE =
4948
(CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE),
5049
};
@@ -196,7 +195,7 @@ static bool checkout_is_workdir_modified(
196195
}
197196

198197
if (git_submodule_status(&sm_status, data->repo, wditem->path, GIT_SUBMODULE_IGNORE_UNSPECIFIED) < 0 ||
199-
GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
198+
GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
200199
rval = true;
201200
else if ((sm_oid = git_submodule_wd_id(sm)) == NULL)
202201
rval = false;
@@ -274,9 +273,8 @@ static int checkout_action_common(
274273

275274
/* if the file is on disk and doesn't match our mode, force update */
276275
if (wd &&
277-
GIT_PERMS_IS_EXEC(wd->mode) !=
278-
GIT_PERMS_IS_EXEC(delta->new_file.mode))
279-
*action |= CHECKOUT_ACTION__REMOVE;
276+
GIT_PERMS_IS_EXEC(wd->mode) != GIT_PERMS_IS_EXEC(delta->new_file.mode))
277+
*action |= CHECKOUT_ACTION__REMOVE;
280278

281279
notify = GIT_CHECKOUT_NOTIFY_UPDATED;
282280
}
@@ -800,7 +798,7 @@ static int checkout_conflictdata_cmp(const void *a, const void *b)
800798
int diff;
801799

802800
if ((diff = checkout_idxentry_cmp(ca->ancestor, cb->ancestor)) == 0 &&
803-
(diff = checkout_idxentry_cmp(ca->ours, cb->theirs)) == 0)
801+
(diff = checkout_idxentry_cmp(ca->ours, cb->theirs)) == 0)
804802
diff = checkout_idxentry_cmp(ca->theirs, cb->theirs);
805803

806804
return diff;
@@ -1179,7 +1177,7 @@ static int checkout_conflicts_mark_directoryfile(
11791177
/* Find d/f conflicts */
11801178
git_vector_foreach(&data->update_conflicts, i, conflict) {
11811179
if ((conflict->ours && conflict->theirs) ||
1182-
(!conflict->ours && !conflict->theirs))
1180+
(!conflict->ours && !conflict->theirs))
11831181
continue;
11841182

11851183
path = conflict->ours ?
@@ -1228,8 +1226,8 @@ static int checkout_get_update_conflicts(
12281226
return 0;
12291227

12301228
if ((error = checkout_conflicts_load(data, workdir, pathspec)) < 0 ||
1231-
(error = checkout_conflicts_coalesce_renames(data)) < 0 ||
1232-
(error = checkout_conflicts_mark_directoryfile(data)) < 0)
1229+
(error = checkout_conflicts_coalesce_renames(data)) < 0 ||
1230+
(error = checkout_conflicts_mark_directoryfile(data)) < 0)
12331231
goto done;
12341232

12351233
done:
@@ -1314,11 +1312,11 @@ static int checkout_get_actions(
13141312
return -1;
13151313

13161314
if (data->opts.paths.count > 0 &&
1317-
git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
1315+
git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
13181316
return -1;
13191317

13201318
if ((error = git_iterator_current(&wditem, workdir)) < 0 &&
1321-
error != GIT_ITEROVER)
1319+
error != GIT_ITEROVER)
13221320
goto fail;
13231321

13241322
deltas = &data->diff->deltas;
@@ -1357,8 +1355,7 @@ static int checkout_get_actions(
13571355
counts[CHECKOUT_ACTION__REMOVE] += data->removes.length;
13581356

13591357
if (counts[CHECKOUT_ACTION__CONFLICT] > 0 &&
1360-
(data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 0)
1361-
{
1358+
(data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 0) {
13621359
git_error_set(GIT_ERROR_CHECKOUT, "%"PRIuZ" %s checkout",
13631360
counts[CHECKOUT_ACTION__CONFLICT],
13641361
counts[CHECKOUT_ACTION__CONFLICT] == 1 ?
@@ -1369,7 +1366,7 @@ static int checkout_get_actions(
13691366

13701367

13711368
if ((error = checkout_get_remove_conflicts(data, workdir, &pathspec)) < 0 ||
1372-
(error = checkout_get_update_conflicts(data, workdir, &pathspec)) < 0)
1369+
(error = checkout_get_update_conflicts(data, workdir, &pathspec)) < 0)
13731370
goto fail;
13741371

13751372
counts[CHECKOUT_ACTION__REMOVE_CONFLICT] = git_vector_length(&data->remove_conflicts);
@@ -1860,26 +1857,6 @@ static int checkout_remove_the_old(
18601857
return 0;
18611858
}
18621859

1863-
static int checkout_deferred_remove(git_repository *repo, const char *path)
1864-
{
1865-
#if 0
1866-
int error = git_futils_rmdir_r(
1867-
path, data->opts.target_directory, GIT_RMDIR_EMPTY_PARENTS);
1868-
1869-
if (error == GIT_ENOTFOUND) {
1870-
error = 0;
1871-
git_error_clear();
1872-
}
1873-
1874-
return error;
1875-
#else
1876-
GIT_UNUSED(repo);
1877-
GIT_UNUSED(path);
1878-
assert(false);
1879-
return 0;
1880-
#endif
1881-
}
1882-
18831860
static int checkout_create_the_new(
18841861
unsigned int *actions,
18851862
checkout_data *data)
@@ -1889,15 +1866,6 @@ static int checkout_create_the_new(
18891866
size_t i;
18901867

18911868
git_vector_foreach(&data->diff->deltas, i, delta) {
1892-
if (actions[i] & CHECKOUT_ACTION__DEFER_REMOVE) {
1893-
/* this had a blocker directory that should only be removed iff
1894-
* all of the contents of the directory were safely removed
1895-
*/
1896-
if ((error = checkout_deferred_remove(
1897-
data->repo, delta->old_file.path)) < 0)
1898-
return error;
1899-
}
1900-
19011869
if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && !S_ISLNK(delta->new_file.mode)) {
19021870
if ((error = checkout_blob(data, &delta->new_file)) < 0)
19031871
return error;
@@ -1922,20 +1890,10 @@ static int checkout_create_submodules(
19221890
unsigned int *actions,
19231891
checkout_data *data)
19241892
{
1925-
int error = 0;
19261893
git_diff_delta *delta;
19271894
size_t i;
19281895

19291896
git_vector_foreach(&data->diff->deltas, i, delta) {
1930-
if (actions[i] & CHECKOUT_ACTION__DEFER_REMOVE) {
1931-
/* this has a blocker directory that should only be removed iff
1932-
* all of the contents of the directory were safely removed
1933-
*/
1934-
if ((error = checkout_deferred_remove(
1935-
data->repo, delta->old_file.path)) < 0)
1936-
return error;
1937-
}
1938-
19391897
if (actions[i] & CHECKOUT_ACTION__UPDATE_SUBMODULE) {
19401898
int error = checkout_submodule(data, &delta->new_file);
19411899
if (error < 0)

src/revparse.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
537537
if (spec[*pos] == '\0')
538538
return GIT_EINVALIDSPEC;
539539

540-
git_buf_putc(buf, spec[(*pos)++]);
540+
if (git_buf_putc(buf, spec[(*pos)++]) < 0)
541+
return -1;
541542
}
542543

543544
(*pos)++;
@@ -585,7 +586,7 @@ static int extract_how_many(int *n, const char *spec, size_t *pos)
585586
*pos = end_ptr - spec;
586587
}
587588

588-
} while (spec[(*pos)] == kind && kind == '~');
589+
} while (spec[(*pos)] == kind && kind == '~');
589590

590591
*n = accumulated;
591592

tests/refs/create.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,12 @@ void test_refs_create__oid_unknown_fails_by_default(void)
212212

213213
void test_refs_create__propagate_eexists(void)
214214
{
215-
int error;
216215
git_oid oid;
217-
git_reference *ref;
218216

219217
/* Make sure it works for oid and for symbolic both */
220-
git_oid_fromstr(&oid, current_master_tip);
221-
error = git_reference_create(&ref, g_repo, current_head_target, &oid, false, NULL);
222-
cl_assert(error == GIT_EEXISTS);
223-
224-
error = git_reference_symbolic_create(&ref, g_repo, "HEAD", current_head_target, false, NULL);
225-
cl_assert(error == GIT_EEXISTS);
218+
cl_git_pass(git_oid_fromstr(&oid, current_master_tip));
219+
cl_git_fail_with(GIT_EEXISTS, git_reference_create(NULL, g_repo, current_head_target, &oid, false, NULL));
220+
cl_git_fail_with(GIT_EEXISTS, git_reference_symbolic_create(NULL, g_repo, "HEAD", current_head_target, false, NULL));
226221
}
227222

228223
void test_refs_create__existing_dir_propagates_edirectory(void)

0 commit comments

Comments
 (0)