Thanks to visit codestin.com
Credit goes to github.com

Skip to content

revwalk: introduce tests that hide old commits #3838

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 28 additions & 38 deletions src/revwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
tmp = git_array_pop(pending);
commit = tmp ? *tmp : NULL;

} while (commit != NULL && !interesting_arr(pending));
} while (commit != NULL && interesting_arr(pending));

git_array_clear(pending);

Expand Down Expand Up @@ -425,48 +425,36 @@ static int contains(git_pqueue *list, git_commit_list_node *node)
return 0;
}

static int premark_uninteresting(git_revwalk *walk)
static void mark_parents_uninteresting(git_commit_list_node *commit)
{
int error = 0;
unsigned short i;
git_pqueue q;
git_commit_list *list;
git_commit_list_node *commit, *parent;

if ((error = git_pqueue_init(&q, 0, 8, git_commit_list_time_cmp)) < 0)
return error;

for (list = walk->user_input; list; list = list->next) {
if ((error = git_commit_list_parse(walk, list->item)) < 0)
goto cleanup;
git_commit_list *parents = NULL;

if ((error = git_pqueue_insert(&q, list->item)) < 0)
goto cleanup;
}
for (i = 0; i < commit->out_degree; i++)
git_commit_list_insert(commit->parents[i], &parents);

while (interesting(&q)) {
commit = git_pqueue_pop(&q);

for (i = 0; i < commit->out_degree; i++) {
parent = commit->parents[i];

if ((error = git_commit_list_parse(walk, parent)) < 0)
goto cleanup;
while (parents) {
git_commit_list_node *commit = git_commit_list_pop(&parents);

while (commit) {
if (commit->uninteresting)
parent->uninteresting = 1;

if (contains(&q, parent))
continue;

if ((error = git_pqueue_insert(&q, parent)) < 0)
goto cleanup;
break;

commit->uninteresting = 1;
/*
* If we've reached this commit some other way
* already, we need to mark its parents uninteresting
* as well.
*/
if (!commit->parents)
break;

for (i = 0; i < commit->out_degree; i++)
git_commit_list_insert(commit->parents[i], &parents);
commit = commit->parents[0];
}
}

cleanup:
git_pqueue_free(&q);
return error;
}

static int prepare_walk(git_revwalk *walk)
Expand All @@ -481,15 +469,17 @@ static int prepare_walk(git_revwalk *walk)
return GIT_ITEROVER;
}

if (walk->did_hide && (error = premark_uninteresting(walk)) < 0)
return error;

for (list = walk->user_input; list; list = list->next) {
if ((error = git_commit_list_parse(walk, list->item)) < 0)
return error;

if (list->item->uninteresting)
mark_parents_uninteresting(list->item);

if (process_commit(walk, list->item, list->item->uninteresting) < 0)
return -1;
}


if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
unsigned short i;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x-�]jC!F��*f)�]��@�
��8� �Z��ۯi�v��>����Os0�B%s)f���M�l�h�V4�5������ �&4ѕ@:�D�)oIr`���$�L����Y��w�s¥F��������g������`�$��b����o�;� �����U|����zO��u}��/�._���ׁ~����J
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x��K
1]�}%�N'7�� ��� 8����
���\�u�5zc���6��8�b,��D�2�0�'�Q�b㭃�@ҩ�R��Q�[��94�)��q�smp+��
�纾�g�G����=�r]/��3�((��tR�a������>���E�
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x���j�0�S�)��*a���㚔��+��l8[A�������33������y�M$�m�*�� �$q��G?Y�A�5<��t����8r���5�����7nD#.d��)~�N�0˄�)R,�|,h��jQ*t������C~� |�u���zҧ�ݗ>����
ƒ�d����8��\�����S�]!7�� ����s� ,[�P2�fw^�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x-�]��0 �}�)t�.�Q J),{���-7��^\�^�ҷA�7(���F�W�"��A%�ɣy���g�iTI��d�?_�����#��[��(-�D�0wdp����R*\Bi~�����[���;�|m�a�djRj���a�
���k��R�s���t��m��G"7��{�~��LD�
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x-�QJ1P�s����Iz2= � �@/�tz7f"�,^߬�W���պp�FW�gk���ѭ�`�$�8J��0c���������5
�I҈�J>!+��N�U���(�û�1�Di<_�7�.5�O�� X�[��#��f����o�;� ���]�\���e��=��[@t���&�xH��h���YJn
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions tests/revwalk/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,51 @@ void test_revwalk_basic__big_timestamp(void)
git_signature_free(sig);

}

/* Ensure that we correctly hide a commit that is (timewise) older
* than the commits that we are showing.
*
* % git rev-list 8e73b76..bd75801
* bd758010071961f28336333bc41e9c64c9a64866
*/
void test_revwalk_basic__old_hidden_commit_one(void)
{
git_oid new_id, old_id, oid;

revwalk_basic_setup_walk("testrepo.git");

cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866"));
cl_git_pass(git_revwalk_push(_walk, &new_id));

cl_git_pass(git_oid_fromstr(&old_id, "8e73b769e97678d684b809b163bebdae2911720f"));
cl_git_pass(git_revwalk_hide(_walk, &old_id));

cl_git_pass(git_revwalk_next(&oid, _walk));
cl_assert(!git_oid_streq(&oid, "bd758010071961f28336333bc41e9c64c9a64866"));

cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
}

/* Ensure that we correctly hide a commit that is (timewise) older
* than the commits that we are showing.
*
* % git rev-list bd75801 ^b91e763
* bd758010071961f28336333bc41e9c64c9a64866
*/
void test_revwalk_basic__old_hidden_commit_two(void)
{
git_oid new_id, old_id, oid;

revwalk_basic_setup_walk("testrepo.git");

cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866"));
cl_git_pass(git_revwalk_push(_walk, &new_id));

cl_git_pass(git_oid_fromstr(&old_id, "b91e763008b10db366442469339f90a2b8400d0a"));
cl_git_pass(git_revwalk_hide(_walk, &old_id));

cl_git_pass(git_revwalk_next(&oid, _walk));
cl_assert(!git_oid_streq(&oid, "bd758010071961f28336333bc41e9c64c9a64866"));

cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid, _walk));
}