{"thread":{"id":"929","subject":"[PATCH 4/7] Move two general purpose commit-related functions into commit.[ch]","startedAt":"2005-06-14T02:04:40Z","lastAt":"2005-06-14T02:04:40Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"4932","messageId":"20050614020440.23311.qmail@blackcubes.dyndns.org","threadId":"929","inReplyTo":null,"subject":"[PATCH 4/7] Move two general purpose commit-related functions into commit.[ch]","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-14T02:04:40Z","receivedAt":"2005-06-14T02:04:40Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nMoved is_parent_of and move_commit from epoch.c into commit.c\n\nis_parent_of returns a non-zero value if the left argument\nis a parent of the right argument. \n\nmove_commit implements the slightly complicated pointer\narithmetic required to remove an element from the middle\nof a singly-linked list. It is moved into commit.c\nbecause a future change to rev-list.c will need to\nuse logic originally implemented in epoch.c\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n commit.c |   23 +++++++++++++++++++++++\n commit.h |   31 +++++++++++++++++++++++++++++++\n epoch.c  |   31 ++-----------------------------\n 3 files changed, 56 insertions(+), 29 deletions(-)\n\ndiff --git a/commit.c b/commit.c\n--- a/commit.c\n+++ b/commit.c\n@@ -374,3 +374,26 @@ struct commit_list * copy_parents_in_hea\n \t}\n \treturn result;\n }\n+\n+int is_parent_of(struct commit *parent, struct commit *child)\n+{\n+\tstruct commit_list *parents;\n+\n+\tfor (parents = child->parents; parents; parents = parents->next)\n+\t\tif (parent==parents->item)\n+\t\t\treturn 1;\n+\treturn 0;\n+}\n+\n+/**\n+ * pre-condition: src && dst && *src && !(*dst)\n+ * post-condition: result && !(*result) && src && dst && *dst\n+ */\n+struct commit_list ** move_commit(struct commit_list ** dst, struct commit_list ** src)\n+{\n+\t*dst = *src;\n+\t*src = (*src)->next;\n+\t(*dst)->next = NULL;\n+\treturn &(*dst)->next;\n+}\n+\ndiff --git a/commit.h b/commit.h\n--- a/commit.h\n+++ b/commit.h\n@@ -84,4 +84,35 @@ int copy_author(struct commit * commit, \n  * they are finished with it.\n  */\n struct commit_list * copy_parents_in_header_order(struct commit * commit);\n+\n+/*\n+ * Return a non-zero value if \"commit\" is a parent of \"child\", zero otherwise.\n+ */\n+int is_parent_of(struct commit *commit, struct commit *child);\n+\n+\n+/**\n+ * Move an item pointed to by *src_ptr onto the tail of a list pointed \n+ * to by dst_tail and return the updated tail pointer. *src_ptr is \n+ * updated to refer to the next element on the source list \n+ * or NULL if there is no such element.\n+ *\n+ * Example:\n+ * \n+ * struct commit_list * src = ...;\n+ * struct commit_list * dst = NULL;\n+ * struct commit_list ** dst_tail = &dst;\n+ * struct commit_list ** src_ptr = &src;\n+ * \n+ * while (*src_ptr) {\n+ *       if (is_moveable(*src_ptr)) {\n+ *                dst_tail = move_commit(dst_tail, src_ptr);\n+ *       else {\n+ *                src_ptr=&(*src_ptr)->next;\n+ *       }\n+ * }\n+ */\n+struct commit_list ** move_commit(struct commit_list ** dst_tail, struct commit_list ** src_ptr);\n+\n #endif /* COMMIT_H */\n+\ndiff --git a/epoch.c b/epoch.c\n--- a/epoch.c\n+++ b/epoch.c\n@@ -417,19 +417,6 @@ static int find_next_epoch_boundary(stru\n }\n \n /*\n- * Returns non-zero if parent is known to be a parent of child.\n- */\n-static int is_parent_of(struct commit *parent, struct commit *child)\n-{\n-\tstruct commit_list *parents;\n-\n-\tfor (parents = child->parents; parents; parents = parents->next)\n-\t\tif (parent==parents->item)\n-\t\t\treturn 1;\n-\treturn 0;\n-}\n-\n-/*\n  * Marks all interesting, visited commits reachable from this commit\n  * as uninteresting. We stop recursing when we reach the epoch boundary,\n  * an unvisited node or a node that has already been marked uninteresting.\n@@ -544,21 +531,6 @@ static struct commit_list ** copy_and_st\n \treturn (struct commit_list **)&commit->object.util;\n }\n \n-/**\n- * Move an item pointed to by *src onto the tail of a list pointed to by dst\n- * and return the updated tail pointer. *src is updated to refer to the\n- * next element on the source list or NULL if there is no such element.\n- */\n-static struct commit_list ** move(struct commit_list ** dst, struct commit_list ** src)\n-{\n-        ASSERT(*src, \"*src is never NULL\", NULL);\n-\tASSERT(!*dst || !(*dst)->next, \"*dst is NULL or (*dst)->next is NULL\", NULL);\n-\t*dst = *src;\n-\t*src = (*src)->next;\n-\t(*dst)->next = NULL;\n-\treturn &(*dst)->next;\n-}\n-\n /*\n  * Sort a list of commits in local first order. A commit is \"local\" \n  * if any of its ancestors (except the base) causes (*local_test)() to \n@@ -603,7 +575,7 @@ static unsigned int sort_local_branches_\n \t\t * Move local items onto their own list.\n                  */\n \t\tif (IS_LOCAL(item))\n-\t\t\tlocal_tail = move(local_tail, non_local_ptr);\n+\t\t\tlocal_tail = move_commit(local_tail, non_local_ptr);\n \t\telse\n \t\t\tnon_local_ptr = &(*non_local_ptr)->next;\n \t}\n@@ -790,3 +762,4 @@ int traverse_from_list(struct commit_lis\n \t\tret = traverse_from_head(base, traversal);\n \treturn ret;\n }\n+\n------------\n"}]}