Skip to content

Commit 4075e06

Browse files
committed
Replace pqueue with code from hashsig heap
I accidentally wrote a separate priority queue implementation when I was working on file rename detection as part of the file hash signature calculation code. To simplify licensing terms, I just adapted that to a general purpose priority queue and replace the old priority queue implementation that was borrowed from elsewhere. This also removes parts of the COPYING document that no longer apply to libgit2.
1 parent 40e1063 commit 4075e06

File tree

9 files changed

+143
-300
lines changed

9 files changed

+143
-300
lines changed

COPYING

+1-74
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,7 @@ Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
388388

389389
----------------------------------------------------------------------
390390

391-
The priority queue implementation is based on code licensed under the
392-
Apache 2.0 license:
393-
394-
Copyright 2010 Volkan Yazıcı <[email protected]>
395-
Copyright 2006-2010 The Apache Software Foundation
396-
397-
The full text of the Apache 2.0 license is available at:
398-
399-
http://www.apache.org/licenses/LICENSE-2.0
400-
401-
----------------------------------------------------------------------
402-
403-
The Clay framework is licensed under the MIT license:
391+
The Clar framework is licensed under the MIT license:
404392

405393
Copyright (C) 2011 by Vicent Marti
406394

@@ -930,64 +918,3 @@ necessary. Here is a sample; alter the names:
930918
That's all there is to it!
931919

932920
----------------------------------------------------------------------
933-
934-
Portions of src/win32/posix_w32.c are derrived from link_win32.c in PHP:
935-
936-
--------------------------------------------------------------------
937-
The PHP License, version 3.01
938-
Copyright (c) 1999 - 2012 The PHP Group. All rights reserved.
939-
--------------------------------------------------------------------
940-
941-
Redistribution and use in source and binary forms, with or without
942-
modification, is permitted provided that the following conditions
943-
are met:
944-
945-
1. Redistributions of source code must retain the above copyright
946-
notice, this list of conditions and the following disclaimer.
947-
948-
2. Redistributions in binary form must reproduce the above copyright
949-
notice, this list of conditions and the following disclaimer in
950-
the documentation and/or other materials provided with the
951-
distribution.
952-
953-
3. The name "PHP" must not be used to endorse or promote products
954-
derived from this software without prior written permission. For
955-
written permission, please contact [email protected].
956-
957-
4. Products derived from this software may not be called "PHP", nor
958-
may "PHP" appear in their name, without prior written permission
959-
from [email protected]. You may indicate that your software works in
960-
conjunction with PHP by saying "Foo for PHP" instead of calling
961-
it "PHP Foo" or "phpfoo"
962-
963-
5. The PHP Group may publish revised and/or new versions of the
964-
license from time to time. Each version will be given a
965-
distinguishing version number.
966-
Once covered code has been published under a particular version
967-
of the license, you may always continue to use it under the terms
968-
of that version. You may also choose to use such covered code
969-
under the terms of any subsequent version of the license
970-
published by the PHP Group. No one other than the PHP Group has
971-
the right to modify the terms applicable to covered code created
972-
under this License.
973-
974-
6. Redistributions of any form whatsoever must retain the following
975-
acknowledgment:
976-
"This product includes PHP software, freely available from
977-
<http://www.php.net/software/>".
978-
979-
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
980-
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
981-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
982-
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
983-
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
984-
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
985-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
986-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
987-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
988-
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
989-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
990-
OF THE POSSIBILITY OF SUCH DAMAGE.
991-
992-
--------------------------------------------------------------------
993-

src/commit_list.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#include "pool.h"
1212
#include "odb.h"
1313

14-
int git_commit_list_time_cmp(void *a, void *b)
14+
int git_commit_list_time_cmp(const void *a, const void *b)
1515
{
16-
git_commit_list_node *commit_a = (git_commit_list_node *)a;
17-
git_commit_list_node *commit_b = (git_commit_list_node *)b;
16+
const git_commit_list_node *commit_a = a;
17+
const git_commit_list_node *commit_b = b;
1818

1919
return (commit_a->time < commit_b->time);
2020
}

src/commit_list.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct git_commit_list {
3939
} git_commit_list;
4040

4141
git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk);
42-
int git_commit_list_time_cmp(void *a, void *b);
42+
int git_commit_list_time_cmp(const void *a, const void *b);
4343
void git_commit_list_free(git_commit_list **list_p);
4444
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p);
4545
git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p);

src/graph.c

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright (C) the libgit2 contributors. All rights reserved.
43
*
@@ -13,9 +12,9 @@
1312
static int interesting(git_pqueue *list, git_commit_list *roots)
1413
{
1514
unsigned int i;
16-
/* element 0 isn't used - we need to start at 1 */
17-
for (i = 1; i < list->size; i++) {
18-
git_commit_list_node *commit = list->d[i];
15+
16+
for (i = 0; i < git_pqueue_size(list); i++) {
17+
git_commit_list_node *commit = git_pqueue_get(list, i);
1918
if ((commit->flags & STALE) == 0)
2019
return 1;
2120
}
@@ -42,7 +41,7 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
4241
return 0;
4342
}
4443

45-
if (git_pqueue_init(&list, 2, git_commit_list_time_cmp) < 0)
44+
if (git_pqueue_init(&list, 0, 2, git_commit_list_time_cmp) < 0)
4645
return -1;
4746

4847
if (git_commit_list_parse(walk, one) < 0)
@@ -59,10 +58,9 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
5958

6059
/* as long as there are non-STALE commits */
6160
while (interesting(&list, roots)) {
62-
git_commit_list_node *commit;
61+
git_commit_list_node *commit = git_pqueue_pop(&list);
6362
int flags;
6463

65-
commit = git_pqueue_pop(&list);
6664
if (commit == NULL)
6765
break;
6866

@@ -110,16 +108,16 @@ static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
110108
{
111109
git_commit_list_node *commit;
112110
git_pqueue pq;
113-
int i;
111+
int error = 0, i;
114112
*ahead = 0;
115113
*behind = 0;
116114

117-
if (git_pqueue_init(&pq, 2, git_commit_list_time_cmp) < 0)
115+
if (git_pqueue_init(&pq, 0, 2, git_commit_list_time_cmp) < 0)
118116
return -1;
119-
if (git_pqueue_insert(&pq, one) < 0)
120-
goto on_error;
121-
if (git_pqueue_insert(&pq, two) < 0)
122-
goto on_error;
117+
118+
if ((error = git_pqueue_insert(&pq, one)) < 0 ||
119+
(error = git_pqueue_insert(&pq, two)) < 0)
120+
goto done;
123121

124122
while ((commit = git_pqueue_pop(&pq)) != NULL) {
125123
if (commit->flags & RESULT ||
@@ -132,18 +130,15 @@ static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
132130

133131
for (i = 0; i < commit->out_degree; i++) {
134132
git_commit_list_node *p = commit->parents[i];
135-
if (git_pqueue_insert(&pq, p) < 0)
136-
return -1;
133+
if ((error = git_pqueue_insert(&pq, p)) < 0)
134+
goto done;
137135
}
138136
commit->flags |= RESULT;
139137
}
140138

139+
done:
141140
git_pqueue_free(&pq);
142-
return 0;
143-
144-
on_error:
145-
git_pqueue_free(&pq);
146-
return -1;
141+
return error;
147142
}
148143

149144
int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo,

src/merge.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const
161161

162162
static int interesting(git_pqueue *list)
163163
{
164-
unsigned int i;
165-
/* element 0 isn't used - we need to start at 1 */
166-
for (i = 1; i < list->size; i++) {
167-
git_commit_list_node *commit = list->d[i];
164+
size_t i;
165+
166+
for (i = 0; i < git_pqueue_size(list); i++) {
167+
git_commit_list_node *commit = git_pqueue_get(list, i);
168168
if ((commit->flags & STALE) == 0)
169169
return 1;
170170
}
@@ -186,7 +186,7 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l
186186
return git_commit_list_insert(one, out) ? 0 : -1;
187187
}
188188

189-
if (git_pqueue_init(&list, twos->length * 2, git_commit_list_time_cmp) < 0)
189+
if (git_pqueue_init(&list, 0, twos->length * 2, git_commit_list_time_cmp) < 0)
190190
return -1;
191191

192192
if (git_commit_list_parse(walk, one) < 0)
@@ -205,10 +205,11 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l
205205

206206
/* as long as there are non-STALE commits */
207207
while (interesting(&list)) {
208-
git_commit_list_node *commit;
208+
git_commit_list_node *commit = git_pqueue_pop(&list);
209209
int flags;
210210

211-
commit = git_pqueue_pop(&list);
211+
if (commit == NULL)
212+
break;
212213

213214
flags = commit->flags & (PARENT1 | PARENT2 | STALE);
214215
if (flags == (PARENT1 | PARENT2)) {

0 commit comments

Comments
 (0)