Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prune only branch #1127

Closed
wants to merge 5 commits into from
Closed

Conversation

cgwalters
Copy link
Member

No description provided.

@cgwalters
Copy link
Member Author

Depends: #1124

@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably 75f24b3) made this pull request unmergeable. Please resolve the merge conflicts.

@jlebon
Copy link
Member

jlebon commented Sep 5, 2017

This needs a rebase.

@cgwalters
Copy link
Member Author

Rebased! 🏄


find ${repo}/objects -name '*.commit' | wc -l > commitcount
assert_file_has_content commitcount '^'${count}'$'
rm -f commitcount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

[[ $(find ... | wc -l) == ${count} ]]

?

* if the ref isn't in --only-branch set.
*/
g_hash_table_iter_init (&hash_iter, all_refs);
while (g_hash_table_iter_next (&hash_iter, &key, &value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GLNX_HASH_TABLE_FOREACH ?

/* Ensure the specified branch exists */
if (!ostree_repo_resolve_rev (repo, ref, FALSE, &commit, error))
return FALSE;
g_hash_table_add (only_branches_set, *iter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/*iter/ref/ ?

for (char **iter = opt_only_branches; iter && *iter; iter++)
{
const char *ref = *iter;
g_autofree char *commit = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just pass NULL right?

@@ -49,6 +50,7 @@ static GOptionEntry options[] = {
{ "keep-younger-than", 0, 0, G_OPTION_ARG_STRING, &opt_keep_younger_than, "Prune all commits older than the specified date", "DATE" },
{ "static-deltas-only", 0, 0, G_OPTION_ARG_NONE, &opt_static_deltas_only, "Change the behavior of delete-commit and keep-younger-than to prune only static deltas" },
{ "retain-branch-depth", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_retain_branch_depth, "Additionally retain BRANCH=DEPTH commits", "BRANCH=DEPTH" },
{ "only-branch", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_only_branches, "Only prune BRANCH (may be specified multiple times)", "BRANCH" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about making these positional args, e.g. just ostree prune foo bar? Seems more natural.

Hmm, although git prune foo bar has the opposite meaning:

<head>...
    In addition to objects reachable from any of our references, keep objects reachable from listed <head>s.

which I find odd, but if in case people are used to that, I'm fine with leaving it as a switch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm...not sure about promoting this to the toplevel quite yet.

{
const char *ref = key;
if (!g_hash_table_contains (only_branches_set, ref))
g_hash_table_insert (retain_branch_depth, g_strdup (ref), GINT_TO_POINTER ((int)-1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be erroring in case the ref is already in the hash table? E.g. someone typing --only-branch foo --retain-branch-depth=bar=5 might not understand what the command is doing.

We had lots of duplicates; prep for adding more tests.
In 5c94098 / ostreedev#646 we
added `--retain-branch-depth`; this adds a symmetric
`--only-branch` for the case where a repo owner just
wants to prune a specific branch.

The implementation here is pretty straightforward; we
just walk all refs and inject the equivalent of
`--retain-branch-depth=$ref=-1` if they're *not* in
`--only-branch`.

Closes: ostreedev#1115
@cgwalters
Copy link
Member Author

Fixups ⬆️

return FALSE;
g_hash_table_add (only_branches_set, *iter);
if (g_hash_table_contains (retain_branch_depth, ref))
return glnx_throw (error, "--retain-branch-depth conflicts with --only-branch");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want this bit down there no? I.e. we do want to be able to specify --retain-branch-depth=my-ref=0 --only-branch my-ref, right?

I was targeting the g_hash_table_insert below instead:

GLNX_HASH_TABLE_FOREACH (all_refs, const char *, ref)
  {
    if (!g_hash_table_contains (only_branches_set, ref))
      {
        if (!g_hash_table_insert (retain_branch_depth, g_strdup (ref), GINT_TO_POINTER ((int)-1)))
          return glnx_throw (error, "--retain-branch-depth conflicts with --only-branch");
      }
  }

Copy link
Member Author

@cgwalters cgwalters Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum...so a high level design I had here was that with --only-branch one just uses the global --depth. In other words: --retain-branch-depth=my-ref=0 --only-branch my-ref is equivalent to --refs-only --only-branch my-ref right?

I'm not quite sure when one would want to combine --only-branch with different depths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to support e.g. --only-branch foo --only-branch bar ? So then you have to resort to --retain-branch-depth if you want them pruned at different depths, no? Well, they can just use separate invocations I suppose (or use the API directly). Though it seems easy enough to support. Otherwise, we should just error out if any --retain-branch-depth is passed at all when --only-branch is given I'd say. And also, remove the related comment block:

+      /* Process --only-branch. Note this combines with --retain-branch-depth; one
+       * could do e.g.:
+       *  * --only-branch exampleos/x86_64/foo
+       *  * --retain-branch-depth exampleos/x86_64/foo=0
+       * to prune exampleos/x86_64/foo to just the latest commit.
+       */

Copy link
Member Author

@cgwalters cgwalters Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think your original comment here was right - I don't see a reason not to support combining the two, even with different branches. Thanks for sticking with this...another fixup ⬇️

@jlebon
Copy link
Member

jlebon commented Sep 18, 2017

@rh-atomic-bot r+ 03aeae7

@rh-atomic-bot
Copy link

⌛ Testing commit 03aeae7 with merge ab20049...

rh-atomic-bot pushed a commit that referenced this pull request Sep 18, 2017
In 5c94098 / #646 we
added `--retain-branch-depth`; this adds a symmetric
`--only-branch` for the case where a repo owner just
wants to prune a specific branch.

The implementation here is pretty straightforward; we
just walk all refs and inject the equivalent of
`--retain-branch-depth=$ref=-1` if they're *not* in
`--only-branch`.

Closes: #1115

Closes: #1127
Approved by: jlebon
@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing ab20049 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants