Skip to content

Commit

Permalink
lib/repo-pull: Prefer object pull over from-scratch delta if ref exists
Browse files Browse the repository at this point in the history
If a ref already exists, we are likely only a few commits behind the
current head of the ref, so it is probably better for bandwidth
consumption to pull the individual objects rather than the from-scratch
delta.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: ostreedev#1709
Approved by: cgwalters
  • Loading branch information
pwithnall authored and rh-atomic-bot committed Aug 20, 2018
1 parent 2b19869 commit e7305bb
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/libostree/ostree-repo-pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -3348,6 +3348,19 @@ initiate_request (OtPullData *pull_data,
return TRUE;
}

/* If doing a delta from a ref, look up the from-revision, since we need it
* on most paths below. */
if (ref != NULL)
{
g_autofree char *refspec = NULL;
if (pull_data->remote_name != NULL)
refspec = g_strdup_printf ("%s:%s", pull_data->remote_name, ref->ref_name);
if (!ostree_repo_resolve_rev (pull_data->repo,
refspec ?: ref->ref_name, TRUE,
&delta_from_revision, error))
return FALSE;
}

/* If we have a summary, we can use the newer logic */
if (pull_data->summary)
{
Expand Down Expand Up @@ -3375,7 +3388,16 @@ initiate_request (OtPullData *pull_data,
enqueue_one_static_delta_superblock_request (pull_data, deltares.from_revision, to_revision, ref);
break;
case DELTA_SEARCH_RESULT_SCRATCH:
enqueue_one_static_delta_superblock_request (pull_data, NULL, to_revision, ref);
{
/* If a from-scratch delta is available, we don’t want to use it if
* the ref already exists locally, since we are likely only a few
* commits out of date; so doing an object pull is likely more
* bandwidth efficient. */
if (delta_from_revision != NULL)
queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref);
else
enqueue_one_static_delta_superblock_request (pull_data, NULL, to_revision, ref);
}
break;
case DELTA_SEARCH_RESULT_UNCHANGED:
{
Expand All @@ -3395,13 +3417,6 @@ initiate_request (OtPullData *pull_data,
{
/* Are we doing a delta via a ref? In that case we can fall back to the older
* logic of just using the current tip of the ref as a delta FROM source. */
g_autofree char *refspec = NULL;
if (pull_data->remote_name != NULL)
refspec = g_strdup_printf ("%s:%s", pull_data->remote_name, ref->ref_name);
if (!ostree_repo_resolve_rev (pull_data->repo,
refspec ?: ref->ref_name, TRUE,
&delta_from_revision, error))
return FALSE;

/* Determine whether the from revision we have is partial; this
* can happen if e.g. one uses `ostree pull --commit-metadata-only`.
Expand Down

0 comments on commit e7305bb

Please sign in to comment.