Skip to content

Commit

Permalink
Export rewrite_parents() for 'log -L'
Browse files Browse the repository at this point in the history
The function rewrite_one is used to rewrite a single
parent of the current commit, and is used by rewrite_parents
to rewrite all the parents.

Decouple the dependence between them by making rewrite_one
a callback function that is passed to rewrite_parents. Then
export rewrite_parents for reuse by the line history browser.

We will use this function in line-log.c.

Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Bo Yang authored and Junio C Hamano committed Mar 28, 2013
1 parent 25ed341 commit c7edcae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 4 additions & 9 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -2173,12 +2173,6 @@ int prepare_revision_walk(struct rev_info *revs)
return 0;
}

enum rewrite_result {
rewrite_one_ok,
rewrite_one_noparents,
rewrite_one_error
};

static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp)
{
struct commit_list *cache = NULL;
Expand All @@ -2200,12 +2194,13 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
}
}

static int rewrite_parents(struct rev_info *revs, struct commit *commit)
int rewrite_parents(struct rev_info *revs, struct commit *commit,
rewrite_parent_fn_t rewrite_parent)
{
struct commit_list **pp = &commit->parents;
while (*pp) {
struct commit_list *parent = *pp;
switch (rewrite_one(revs, &parent->item)) {
switch (rewrite_parent(revs, &parent->item)) {
case rewrite_one_ok:
break;
case rewrite_one_noparents:
Expand Down Expand Up @@ -2371,7 +2366,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
if (action == commit_show &&
!revs->show_all &&
revs->prune && revs->dense && want_ancestry(revs)) {
if (rewrite_parents(revs, commit) < 0)
if (rewrite_parents(revs, commit, rewrite_one) < 0)
return commit_error;
}
return action;
Expand Down
10 changes: 10 additions & 0 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,14 @@ enum commit_action {
extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);

enum rewrite_result {
rewrite_one_ok,
rewrite_one_noparents,
rewrite_one_error
};

typedef enum rewrite_result (*rewrite_parent_fn_t)(struct rev_info *revs, struct commit **pp);

extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
rewrite_parent_fn_t rewrite_parent);
#endif

0 comments on commit c7edcae

Please sign in to comment.