Skip to content

Commit 7a76a33

Browse files
implausiblezawata
authored andcommitted
checkout: cleanup duplication in checkout_create_the_new
1 parent b7bad55 commit 7a76a33

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/checkout.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,35 @@ static int checkout_remove_the_old(
18601860
return 0;
18611861
}
18621862

1863+
enum {
1864+
NO_SYMLINKS = 0,
1865+
SYMLINKS_ONLY = 1
1866+
};
1867+
1868+
static int checkout_create_the_new_perform(
1869+
checkout_data *data,
1870+
unsigned int action,
1871+
git_diff_delta *delta,
1872+
unsigned int checkout_option)
1873+
{
1874+
int error = 0;
1875+
if (action & CHECKOUT_ACTION__UPDATE_BLOB) {
1876+
if (checkout_option == NO_SYMLINKS && S_ISLNK(delta->new_file.mode))
1877+
return 0;
1878+
1879+
if (checkout_option == SYMLINKS_ONLY && !S_ISLNK(delta->new_file.mode))
1880+
return 0;
1881+
1882+
if ((error = checkout_blob(data, &delta->new_file)) < 0)
1883+
return error;
1884+
1885+
data->completed_steps++;
1886+
report_progress(data, delta->new_file.path);
1887+
}
1888+
1889+
return 0;
1890+
}
1891+
18631892
static int checkout_create_the_new(
18641893
unsigned int *actions,
18651894
checkout_data *data)
@@ -1869,21 +1898,15 @@ static int checkout_create_the_new(
18691898
size_t i;
18701899

18711900
git_vector_foreach(&data->diff->deltas, i, delta) {
1872-
if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && !S_ISLNK(delta->new_file.mode)) {
1873-
if ((error = checkout_blob(data, &delta->new_file)) < 0)
1874-
return error;
1875-
data->completed_steps++;
1876-
report_progress(data, delta->new_file.path);
1877-
}
1901+
if ((error = checkout_create_the_new_perform(data, actions[i], delta,
1902+
NO_SYMLINKS)) < 0)
1903+
return error;
18781904
}
18791905

18801906
git_vector_foreach(&data->diff->deltas, i, delta) {
1881-
if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && S_ISLNK(delta->new_file.mode)) {
1882-
if ((error = checkout_blob(data, &delta->new_file)) < 0)
1883-
return error;
1884-
data->completed_steps++;
1885-
report_progress(data, delta->new_file.path);
1886-
}
1907+
if ((error = checkout_create_the_new_perform(data, actions[i], delta,
1908+
SYMLINKS_ONLY)) < 0)
1909+
return error;
18871910
}
18881911

18891912
return 0;

0 commit comments

Comments
 (0)