mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 21:56:44 +00:00
Add external API for revision sorting.
The GIT_RPSORT_XXX flags have been moved to the external API, and a new method 'gitrp_sorting(...)' has been added to safely change the sorting method of a revision pool. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
This commit is contained in:
parent
9bdb759471
commit
e5d1faefab
@ -14,6 +14,35 @@
|
|||||||
*/
|
*/
|
||||||
GIT_BEGIN_DECL
|
GIT_BEGIN_DECL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the revpool contents in no particular ordering;
|
||||||
|
* this sorting is arbritary, implementation-specific
|
||||||
|
* and subject to change at any time.
|
||||||
|
* This is the default sorting for new revision pools.
|
||||||
|
*/
|
||||||
|
#define GIT_RPSORT_NONE (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the revpool contents in topological order
|
||||||
|
* (parents before children); this sorting mode
|
||||||
|
* can be combined with time sorting.
|
||||||
|
*/
|
||||||
|
#define GIT_RPSORT_TOPOLOGICAL (1 << 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the revpool contents by commit time;
|
||||||
|
* this sorting mode can be combined with
|
||||||
|
* topological sorting.
|
||||||
|
*/
|
||||||
|
#define GIT_RPSORT_TIME (1 << 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate through the revpool contents in reverse
|
||||||
|
* order; this sorting mode can be combined with
|
||||||
|
* any of the above.
|
||||||
|
*/
|
||||||
|
#define GIT_RPSORT_REVERSE (1 << 2)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a new revision traversal pool.
|
* Allocate a new revision traversal pool.
|
||||||
*
|
*
|
||||||
@ -54,6 +83,13 @@ GIT_EXTERN(void) gitrp_hide(git_revpool *pool, git_commit *commit);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(git_commit *) gitrp_next(git_revpool *pool);
|
GIT_EXTERN(git_commit *) gitrp_next(git_revpool *pool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the sorting mode when iterating through the
|
||||||
|
* revision pool's contents.
|
||||||
|
* @param sort_mode combination of GIT_RPSORT_XXX flags
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(void) gitrp_sorting(git_revpool *pool, unsigned int sort_mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a revwalk previously allocated.
|
* Free a revwalk previously allocated.
|
||||||
* @param pool traversal handle to close. If NULL nothing occurs.
|
* @param pool traversal handle to close. If NULL nothing occurs.
|
||||||
|
@ -53,9 +53,18 @@ void gitrp_free(git_revpool *walk)
|
|||||||
free(walk);
|
free(walk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gitrp_sorting(git_revpool *pool, unsigned int sort_mode)
|
||||||
|
{
|
||||||
|
if (pool->walking)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pool->sorting = sort_mode;
|
||||||
|
gitrp_reset(pool);
|
||||||
|
}
|
||||||
|
|
||||||
void gitrp_push(git_revpool *pool, git_commit *commit)
|
void gitrp_push(git_revpool *pool, git_commit *commit)
|
||||||
{
|
{
|
||||||
if (commit->object.pool != pool)
|
if (commit->object.pool != pool || pool->walking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (commit->seen)
|
if (commit->seen)
|
||||||
@ -78,6 +87,9 @@ void gitrp_push(git_revpool *pool, git_commit *commit)
|
|||||||
|
|
||||||
void gitrp_hide(git_revpool *pool, git_commit *commit)
|
void gitrp_hide(git_revpool *pool, git_commit *commit)
|
||||||
{
|
{
|
||||||
|
if (pool->walking)
|
||||||
|
return;
|
||||||
|
|
||||||
git_commit__mark_uninteresting(commit);
|
git_commit__mark_uninteresting(commit);
|
||||||
gitrp_push(pool, commit);
|
gitrp_push(pool, commit);
|
||||||
}
|
}
|
||||||
@ -103,20 +115,20 @@ void gitrp__enroot(git_revpool *pool, git_commit *commit)
|
|||||||
git_commit_list_push_back(&pool->iterator, commit);
|
git_commit_list_push_back(&pool->iterator, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gitrp_prepare_walk(git_revpool *pool)
|
void gitrp__prepare_walk(git_revpool *pool)
|
||||||
{
|
{
|
||||||
git_commit_node *it;
|
git_commit_node *it;
|
||||||
|
|
||||||
for (it = pool->roots.head; it != NULL; it = it->next)
|
for (it = pool->roots.head; it != NULL; it = it->next)
|
||||||
gitrp__enroot(pool, it->commit);
|
gitrp__enroot(pool, it->commit);
|
||||||
|
|
||||||
if (pool->sorting & GIT_REVPOOL_SORT_TIME)
|
if (pool->sorting & GIT_RPSORT_TIME)
|
||||||
git_commit_list_timesort(&pool->iterator);
|
git_commit_list_timesort(&pool->iterator);
|
||||||
|
|
||||||
if (pool->sorting & GIT_REVPOOL_SORT_TOPO)
|
if (pool->sorting & GIT_RPSORT_TOPOLOGICAL)
|
||||||
git_commit_list_toposort(&pool->iterator);
|
git_commit_list_toposort(&pool->iterator);
|
||||||
|
|
||||||
if (pool->sorting & GIT_REVPOOL_SORT_REVERSE)
|
if (pool->sorting & GIT_RPSORT_REVERSE)
|
||||||
pool->next_commit = &git_commit_list_pop_back;
|
pool->next_commit = &git_commit_list_pop_back;
|
||||||
else
|
else
|
||||||
pool->next_commit = &git_commit_list_pop_front;
|
pool->next_commit = &git_commit_list_pop_front;
|
||||||
@ -129,7 +141,7 @@ git_commit *gitrp_next(git_revpool *pool)
|
|||||||
git_commit *next;
|
git_commit *next;
|
||||||
|
|
||||||
if (!pool->walking)
|
if (!pool->walking)
|
||||||
gitrp_prepare_walk(pool);
|
gitrp__prepare_walk(pool);
|
||||||
|
|
||||||
while ((next = pool->next_commit(&pool->iterator)) != NULL)
|
while ((next = pool->next_commit(&pool->iterator)) != NULL)
|
||||||
{
|
{
|
||||||
|
@ -4,11 +4,6 @@
|
|||||||
#include "git/common.h"
|
#include "git/common.h"
|
||||||
#include "git/revwalk.h"
|
#include "git/revwalk.h"
|
||||||
|
|
||||||
#define GIT_REVPOOL_SORT_NONE (0)
|
|
||||||
#define GIT_REVPOOL_SORT_TOPO (1 << 0)
|
|
||||||
#define GIT_REVPOOL_SORT_TIME (1 << 1)
|
|
||||||
#define GIT_REVPOOL_SORT_REVERSE (1 << 2)
|
|
||||||
|
|
||||||
struct git_revpool {
|
struct git_revpool {
|
||||||
git_odb *db;
|
git_odb *db;
|
||||||
|
|
||||||
@ -22,4 +17,7 @@ struct git_revpool {
|
|||||||
unsigned char sorting;
|
unsigned char sorting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void gitrp__prepare_walk(git_revpool *pool);
|
||||||
|
void gitrp__enroot(git_revpool *pool, git_commit *commit);
|
||||||
|
|
||||||
#endif /* INCLUDE_revwalk_h__ */
|
#endif /* INCLUDE_revwalk_h__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user