git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: jon.seymour@gmail.com
Subject: [PATCH 4/7] Move two general purpose commit-related functions into commit.[ch]
Date: Tue, 14 Jun 2005 12:04:40 +1000	[thread overview]
Message-ID: <20050614020440.23311.qmail@blackcubes.dyndns.org> (raw)


Moved is_parent_of and move_commit from epoch.c into commit.c

is_parent_of returns a non-zero value if the left argument
is a parent of the right argument. 

move_commit implements the slightly complicated pointer
arithmetic required to remove an element from the middle
of a singly-linked list. It is moved into commit.c
because a future change to rev-list.c will need to
use logic originally implemented in epoch.c

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---

 commit.c |   23 +++++++++++++++++++++++
 commit.h |   31 +++++++++++++++++++++++++++++++
 epoch.c  |   31 ++-----------------------------
 3 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/commit.c b/commit.c
--- a/commit.c
+++ b/commit.c
@@ -374,3 +374,26 @@ struct commit_list * copy_parents_in_hea
 	}
 	return result;
 }
+
+int is_parent_of(struct commit *parent, struct commit *child)
+{
+	struct commit_list *parents;
+
+	for (parents = child->parents; parents; parents = parents->next)
+		if (parent==parents->item)
+			return 1;
+	return 0;
+}
+
+/**
+ * pre-condition: src && dst && *src && !(*dst)
+ * post-condition: result && !(*result) && src && dst && *dst
+ */
+struct commit_list ** move_commit(struct commit_list ** dst, struct commit_list ** src)
+{
+	*dst = *src;
+	*src = (*src)->next;
+	(*dst)->next = NULL;
+	return &(*dst)->next;
+}
+
diff --git a/commit.h b/commit.h
--- a/commit.h
+++ b/commit.h
@@ -84,4 +84,35 @@ int copy_author(struct commit * commit, 
  * they are finished with it.
  */
 struct commit_list * copy_parents_in_header_order(struct commit * commit);
+
+/*
+ * Return a non-zero value if "commit" is a parent of "child", zero otherwise.
+ */
+int is_parent_of(struct commit *commit, struct commit *child);
+
+
+/**
+ * Move an item pointed to by *src_ptr onto the tail of a list pointed 
+ * to by dst_tail and return the updated tail pointer. *src_ptr is 
+ * updated to refer to the next element on the source list 
+ * or NULL if there is no such element.
+ *
+ * Example:
+ * 
+ * struct commit_list * src = ...;
+ * struct commit_list * dst = NULL;
+ * struct commit_list ** dst_tail = &dst;
+ * struct commit_list ** src_ptr = &src;
+ * 
+ * while (*src_ptr) {
+ *       if (is_moveable(*src_ptr)) {
+ *                dst_tail = move_commit(dst_tail, src_ptr);
+ *       else {
+ *                src_ptr=&(*src_ptr)->next;
+ *       }
+ * }
+ */
+struct commit_list ** move_commit(struct commit_list ** dst_tail, struct commit_list ** src_ptr);
+
 #endif /* COMMIT_H */
+
diff --git a/epoch.c b/epoch.c
--- a/epoch.c
+++ b/epoch.c
@@ -417,19 +417,6 @@ static int find_next_epoch_boundary(stru
 }
 
 /*
- * Returns non-zero if parent is known to be a parent of child.
- */
-static int is_parent_of(struct commit *parent, struct commit *child)
-{
-	struct commit_list *parents;
-
-	for (parents = child->parents; parents; parents = parents->next)
-		if (parent==parents->item)
-			return 1;
-	return 0;
-}
-
-/*
  * Marks all interesting, visited commits reachable from this commit
  * as uninteresting. We stop recursing when we reach the epoch boundary,
  * an unvisited node or a node that has already been marked uninteresting.
@@ -544,21 +531,6 @@ static struct commit_list ** copy_and_st
 	return (struct commit_list **)&commit->object.util;
 }
 
-/**
- * Move an item pointed to by *src onto the tail of a list pointed to by dst
- * and return the updated tail pointer. *src is updated to refer to the
- * next element on the source list or NULL if there is no such element.
- */
-static struct commit_list ** move(struct commit_list ** dst, struct commit_list ** src)
-{
-        ASSERT(*src, "*src is never NULL", NULL);
-	ASSERT(!*dst || !(*dst)->next, "*dst is NULL or (*dst)->next is NULL", NULL);
-	*dst = *src;
-	*src = (*src)->next;
-	(*dst)->next = NULL;
-	return &(*dst)->next;
-}
-
 /*
  * Sort a list of commits in local first order. A commit is "local" 
  * if any of its ancestors (except the base) causes (*local_test)() to 
@@ -603,7 +575,7 @@ static unsigned int sort_local_branches_
 		 * Move local items onto their own list.
                  */
 		if (IS_LOCAL(item))
-			local_tail = move(local_tail, non_local_ptr);
+			local_tail = move_commit(local_tail, non_local_ptr);
 		else
 			non_local_ptr = &(*non_local_ptr)->next;
 	}
@@ -790,3 +762,4 @@ int traverse_from_list(struct commit_lis
 		ret = traverse_from_head(base, traversal);
 	return ret;
 }
+
------------

                 reply	other threads:[~2005-06-14  2:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050614020440.23311.qmail@blackcubes.dyndns.org \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).