Hash :
655d381a
Author :
Date :
2010-05-23T16:51:31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "common.h"
#include "commit.h"
#include "revwalk.h"
static const int default_table_size = 32;
git_revpool *gitrp_alloc(git_odb *db)
{
git_revpool *walk = git__malloc(sizeof(*walk));
if (!walk)
return NULL;
memset(walk, 0x0, sizeof(git_revpool));
walk->commits = git_revpool_table_create(default_table_size);
walk->db = db;
return walk;
}
void gitrp_free(git_revpool *walk)
{
git_commit_list_clear(&(walk->iterator), 0);
git_commit_list_clear(&(walk->roots), 0);
git_revpool_table_free(walk->commits);
free(walk);
}
void gitrp_push(git_revpool *pool, git_commit *commit)
{
if (commit->object.pool != pool)
return;
if (commit->seen)
return;
if (!commit->parsed)
{
if (git_commit_parse_existing(commit) < 0)
return;
}
// Sanity check: make sure that if the commit
// has been manually marked as uninteresting,
// all the parent commits are too.
if (commit->uninteresting)
git_commit__mark_uninteresting(commit);
git_commit_list_push_back(&pool->roots, commit);
}
void gitrp_hide(git_revpool *pool, git_commit *commit)
{
git_commit__mark_uninteresting(commit);
gitrp_push(pool, commit);
}
void gitrp__enroot(git_revpool *pool, git_commit *commit)
{
git_commit_node *parents;
if (commit->seen)
return;
if (commit->parsed == 0)
git_commit_parse_existing(commit);
commit->seen = 1;
for (parents = commit->parents.head; parents != NULL; parents = parents->next)
{
parents->commit->in_degree++;
gitrp__enroot(pool, parents->commit);
}
git_commit_list_push_back(&pool->iterator, commit);
}
void gitrp_prepare_walk(git_revpool *pool)
{
git_commit_node *it;
for (it = pool->roots.head; it != NULL; it = it->next)
gitrp__enroot(pool, it->commit);
if (pool->sorting & GIT_REVPOOL_SORT_TIME)
git_commit_list_timesort(&pool->iterator);
if (pool->sorting & GIT_REVPOOL_SORT_TOPO)
git_commit_list_toposort(&pool->iterator);
if (pool->sorting & GIT_REVPOOL_SORT_REVERSE)
pool->next_commit = &git_commit_list_pop_back;
else
pool->next_commit = &git_commit_list_pop_front;
pool->walking = 1;
}
git_commit *gitrp_next(git_revpool *pool)
{
git_commit *next;
if (!pool->walking)
gitrp_prepare_walk(pool);
while ((next = pool->next_commit(&pool->iterator)) != NULL)
{
if (!next->uninteresting)
return next;
}
// No commits left to iterate
gitrp_reset(pool);
return NULL;
}
void gitrp_reset(git_revpool *pool)
{
git_commit_list_clear(&pool->iterator, 0);
pool->walking = 0;
}