Permalink
Browse files

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.
  • Loading branch information...
arrbee committed Feb 4, 2014
1 parent 40e1063 commit 4075e060b45a73834a24684ed835d52f7176d58b
Showing with 143 additions and 300 deletions.
  1. +1 −74 COPYING
  2. +3 −3 src/commit_list.c
  3. +1 −1 src/commit_list.h
  4. +15 −20 src/graph.c
  5. +8 −7 src/merge.c
  6. +59 −125 src/pqueue.c
  7. +43 −68 src/pqueue.h
  8. +3 −2 src/revwalk.c
  9. +10 −0 src/vector.h
View
75 COPYING
@@ -388,19 +388,7 @@ Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
----------------------------------------------------------------------
-The priority queue implementation is based on code licensed under the
-Apache 2.0 license:
-
- Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com>
- Copyright 2006-2010 The Apache Software Foundation
-
-The full text of the Apache 2.0 license is available at:
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-----------------------------------------------------------------------
-
-The Clay framework is licensed under the MIT license:
+The Clar framework is licensed under the MIT license:
Copyright (C) 2011 by Vicent Marti
@@ -930,64 +918,3 @@ necessary. Here is a sample; alter the names:
That's all there is to it!
----------------------------------------------------------------------
-
-Portions of src/win32/posix_w32.c are derrived from link_win32.c in PHP:
-
---------------------------------------------------------------------
- The PHP License, version 3.01
-Copyright (c) 1999 - 2012 The PHP Group. All rights reserved.
---------------------------------------------------------------------
-
-Redistribution and use in source and binary forms, with or without
-modification, is permitted provided that the following conditions
-are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- 3. The name "PHP" must not be used to endorse or promote products
- derived from this software without prior written permission. For
- written permission, please contact group@php.net.
-
- 4. Products derived from this software may not be called "PHP", nor
- may "PHP" appear in their name, without prior written permission
- from group@php.net. You may indicate that your software works in
- conjunction with PHP by saying "Foo for PHP" instead of calling
- it "PHP Foo" or "phpfoo"
-
- 5. The PHP Group may publish revised and/or new versions of the
- license from time to time. Each version will be given a
- distinguishing version number.
- Once covered code has been published under a particular version
- of the license, you may always continue to use it under the terms
- of that version. You may also choose to use such covered code
- under the terms of any subsequent version of the license
- published by the PHP Group. No one other than the PHP Group has
- the right to modify the terms applicable to covered code created
- under this License.
-
- 6. Redistributions of any form whatsoever must retain the following
- acknowledgment:
- "This product includes PHP software, freely available from
- <http://www.php.net/software/>".
-
-THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
-ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
-DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-OF THE POSSIBILITY OF SUCH DAMAGE.
-
---------------------------------------------------------------------
-
View
@@ -11,10 +11,10 @@
#include "pool.h"
#include "odb.h"
-int git_commit_list_time_cmp(void *a, void *b)
+int git_commit_list_time_cmp(const void *a, const void *b)
{
- git_commit_list_node *commit_a = (git_commit_list_node *)a;
- git_commit_list_node *commit_b = (git_commit_list_node *)b;
+ const git_commit_list_node *commit_a = a;
+ const git_commit_list_node *commit_b = b;
return (commit_a->time < commit_b->time);
}
View
@@ -39,7 +39,7 @@ typedef struct git_commit_list {
} git_commit_list;
git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk);
-int git_commit_list_time_cmp(void *a, void *b);
+int git_commit_list_time_cmp(const void *a, const void *b);
void git_commit_list_free(git_commit_list **list_p);
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p);
git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p);
View
@@ -1,4 +1,3 @@
-
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
@@ -13,9 +12,9 @@
static int interesting(git_pqueue *list, git_commit_list *roots)
{
unsigned int i;
- /* element 0 isn't used - we need to start at 1 */
- for (i = 1; i < list->size; i++) {
- git_commit_list_node *commit = list->d[i];
+
+ for (i = 0; i < git_pqueue_size(list); i++) {
+ git_commit_list_node *commit = git_pqueue_get(list, i);
if ((commit->flags & STALE) == 0)
return 1;
}
@@ -42,7 +41,7 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
return 0;
}
- if (git_pqueue_init(&list, 2, git_commit_list_time_cmp) < 0)
+ if (git_pqueue_init(&list, 0, 2, git_commit_list_time_cmp) < 0)
return -1;
if (git_commit_list_parse(walk, one) < 0)
@@ -59,10 +58,9 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
/* as long as there are non-STALE commits */
while (interesting(&list, roots)) {
- git_commit_list_node *commit;
+ git_commit_list_node *commit = git_pqueue_pop(&list);
int flags;
- commit = git_pqueue_pop(&list);
if (commit == NULL)
break;
@@ -110,16 +108,16 @@ static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
{
git_commit_list_node *commit;
git_pqueue pq;
- int i;
+ int error = 0, i;
*ahead = 0;
*behind = 0;
- if (git_pqueue_init(&pq, 2, git_commit_list_time_cmp) < 0)
+ if (git_pqueue_init(&pq, 0, 2, git_commit_list_time_cmp) < 0)
return -1;
- if (git_pqueue_insert(&pq, one) < 0)
- goto on_error;
- if (git_pqueue_insert(&pq, two) < 0)
- goto on_error;
+
+ if ((error = git_pqueue_insert(&pq, one)) < 0 ||
+ (error = git_pqueue_insert(&pq, two)) < 0)
+ goto done;
while ((commit = git_pqueue_pop(&pq)) != NULL) {
if (commit->flags & RESULT ||
@@ -132,18 +130,15 @@ static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
for (i = 0; i < commit->out_degree; i++) {
git_commit_list_node *p = commit->parents[i];
- if (git_pqueue_insert(&pq, p) < 0)
- return -1;
+ if ((error = git_pqueue_insert(&pq, p)) < 0)
+ goto done;
}
commit->flags |= RESULT;
}
+done:
git_pqueue_free(&pq);
- return 0;
-
-on_error:
- git_pqueue_free(&pq);
- return -1;
+ return error;
}
int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo,
View
@@ -161,10 +161,10 @@ int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const
static int interesting(git_pqueue *list)
{
- unsigned int i;
- /* element 0 isn't used - we need to start at 1 */
- for (i = 1; i < list->size; i++) {
- git_commit_list_node *commit = list->d[i];
+ size_t i;
+
+ for (i = 0; i < git_pqueue_size(list); i++) {
+ git_commit_list_node *commit = git_pqueue_get(list, i);
if ((commit->flags & STALE) == 0)
return 1;
}
@@ -186,7 +186,7 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l
return git_commit_list_insert(one, out) ? 0 : -1;
}
- if (git_pqueue_init(&list, twos->length * 2, git_commit_list_time_cmp) < 0)
+ if (git_pqueue_init(&list, 0, twos->length * 2, git_commit_list_time_cmp) < 0)
return -1;
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
/* as long as there are non-STALE commits */
while (interesting(&list)) {
- git_commit_list_node *commit;
+ git_commit_list_node *commit = git_pqueue_pop(&list);
int flags;
- commit = git_pqueue_pop(&list);
+ if (commit == NULL)
+ break;
flags = commit->flags & (PARENT1 | PARENT2 | STALE);
if (flags == (PARENT1 | PARENT2)) {
Oops, something went wrong.

0 comments on commit 4075e06

Please sign in to comment.