Skip to content

Commit

Permalink
fixup! bin/prune: Add --only-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Sep 15, 2017
1 parent 8ec80eb commit 03aeae7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/ostree/ot-builtin-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
/* Process --only-branch. Note this combines with --retain-branch-depth; one
* could do e.g.:
* * --only-branch exampleos/x86_64/foo
* * --only-branch exampleos/x86_64/bar
* * --retain-branch-depth exampleos/x86_64/foo=0
* to prune exampleos/x86_64/foo to just the latest commit.
* * --depth 5
* to prune exampleos/x86_64/foo to just the latest commit, and
* exampleos/x86_64/bar to a depth of 5.
*/
if (opt_only_branches)
{
Expand All @@ -258,18 +261,20 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
/* Ensure the specified branch exists */
if (!ostree_repo_resolve_rev (repo, ref, FALSE, NULL, error))
return FALSE;
if (g_hash_table_contains (retain_branch_depth, ref))
return glnx_throw (error, "--retain-branch-depth conflicts with --only-branch");
g_hash_table_add (only_branches_set, (char*)ref);
}

/* Iterate over all refs, add equivalent of --retain-branch-depth=$ref=-1
* if the ref isn't in --only-branch set.
* if the ref isn't in --only-branch set and there wasn't already a
* --retain-branch-depth specified for it.
*/
GLNX_HASH_TABLE_FOREACH (all_refs, const char *, ref)
{
if (!g_hash_table_contains (only_branches_set, ref))
g_hash_table_insert (retain_branch_depth, g_strdup (ref), GINT_TO_POINTER ((int)-1));
if (!g_hash_table_contains (only_branches_set, ref) &&
!g_hash_table_contains (retain_branch_depth, ref))
{
g_hash_table_insert (retain_branch_depth, g_strdup (ref), GINT_TO_POINTER ((int)-1));
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion tests/test-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ skip_without_user_xattrs

setup_fake_remote_repo1 "archive"

echo '1..10'
echo '1..12'

cd ${test_tmpdir}
mkdir repo
Expand Down Expand Up @@ -259,6 +259,19 @@ ${CMD_PREFIX} ostree --repo=repo prune --only-branch=dev --only-branch=stable --
assert_repo_has_n_commits repo 4
echo "ok --only-branch (all) --depth=1"

# Test --only-branch and --retain-branch-depth overlap
reinitialize_datesnap_repo
${CMD_PREFIX} ostree --repo=repo prune --only-branch=dev --only-branch=stable --depth=0 \
--retain-branch-depth=stable=2
assert_repo_has_n_commits repo 4
echo "ok --only-branch and --retain-branch-depth overlap"

# Test --only-branch and --retain-branch-depth together
reinitialize_datesnap_repo
${CMD_PREFIX} ostree --repo=repo prune --only-branch=dev --depth=0 --retain-branch-depth=stable=2
assert_repo_has_n_commits repo 4
echo "ok --only-branch and --retain-branch-depth together"

# Test --only-branch with --keep-younger-than; this should be identical to the test
# above for --retain-branch-depth=stable=-1
reinitialize_datesnap_repo
Expand Down

0 comments on commit 03aeae7

Please sign in to comment.