git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/13] refactor duplicated ref_newer() to remote.c

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 23, 2009, 06:28 UTC
Message-ID
<7f19e98ccc330d4094ffbb55ea06c35b91da9e55.1235368324.git.jaysoffian@gmail.com>
In-Reply-To
<cover.1235368324.git.jaysoffian@gmail.com>

ref_newer() appears to have been copied from builtin-send-pack.c to http-push.c via cut and paste. This patch moves the function and its helper unmark_and_free() to remote.c.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Hmm, I just noticed that the version in builtin-send-pack.c uses 1
whereas http-push.c uses TMP_MARK as the mark argument. I used the
version from builtin-send-pack.c. I don't know if this is signfificant.
 builtin-send-pack.c |   49 -------------------------------------------------
 http-push.c         |   49 -------------------------------------------------
 remote.c            |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 remote.h            |    1 +
 4 files changed, 50 insertions(+), 98 deletions(-)
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 2fbfc29..186cecb 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -84,55 +84,6 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
 	return 0;
 }
 
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
-{
-	while (list) {
-		struct commit_list *temp = list;
-		temp->item->object.flags &= ~mark;
-		list = temp->next;
-		free(temp);
-	}
-}
-
-static int ref_newer(const unsigned char *new_sha1,
-		     const unsigned char *old_sha1)
-{
-	struct object *o;
-	struct commit *old, *new;
-	struct commit_list *list, *used;
-	int found = 0;
-
-	/* Both new and old must be commit-ish and new is descendant of
-	 * old.  Otherwise we require --force.
-	 */
-	o = deref_tag(parse_object(old_sha1), NULL, 0);
-	if (!o || o->type != OBJ_COMMIT)
-		return 0;
-	old = (struct commit *) o;
-
-	o = deref_tag(parse_object(new_sha1), NULL, 0);
-	if (!o || o->type != OBJ_COMMIT)
-		return 0;
-	new = (struct commit *) o;
-
-	if (parse_commit(new) < 0)
-		return 0;
-
-	used = list = NULL;
-	commit_list_insert(new, &list);
-	while (list) {
-		new = pop_most_recent_commit(&list, 1);
-		commit_list_insert(new, &used);
-		if (new == old) {
-			found = 1;
-			break;
-		}
-	}
-	unmark_and_free(list, 1);
-	unmark_and_free(used, 1);
-	return found;
-}
-
 static struct ref *remote_refs, **remote_tail;
 
 static int receive_status(int in, struct ref *refs)
diff --git a/http-push.c b/http-push.c
index cfeed81..392533a 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1843,55 +1843,6 @@ static int is_zero_sha1(const unsigned char *sha1)
 	return 1;
 }
 
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
-{
-	while (list) {
-		struct commit_list *temp = list;
-		temp->item->object.flags &= ~mark;
-		list = temp->next;
-		free(temp);
-	}
-}
-
-static int ref_newer(const unsigned char *new_sha1,
-		     const unsigned char *old_sha1)
-{
-	struct object *o;
-	struct commit *old, *new;
-	struct commit_list *list, *used;
-	int found = 0;
-
-	/* Both new and old must be commit-ish and new is descendant of
-	 * old.  Otherwise we require --force.
-	 */
-	o = deref_tag(parse_object(old_sha1), NULL, 0);
-	if (!o || o->type != OBJ_COMMIT)
-		return 0;
-	old = (struct commit *) o;
-
-	o = deref_tag(parse_object(new_sha1), NULL, 0);
-	if (!o || o->type != OBJ_COMMIT)
-		return 0;
-	new = (struct commit *) o;
-
-	if (parse_commit(new) < 0)
-		return 0;
-
-	used = list = NULL;
-	commit_list_insert(new, &list);
-	while (list) {
-		new = pop_most_recent_commit(&list, TMP_MARK);
-		commit_list_insert(new, &used);
-		if (new == old) {
-			found = 1;
-			break;
-		}
-	}
-	unmark_and_free(list, TMP_MARK);
-	unmark_and_free(used, TMP_MARK);
-	return found;
-}
-
 static void add_remote_info_ref(struct remote_ls_ctx *ls)
 {
 	struct strbuf *buf = (struct strbuf *)ls->userData;
diff --git a/remote.c b/remote.c
index 2c010a1..5cb443f 100644
--- a/remote.c
+++ b/remote.c
@@ -5,6 +5,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "dir.h"
+#include "tag.h"
 
 static struct refspec s_tag_refspec = {
 	0,
@@ -1271,6 +1272,54 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
 	return 1;
 }
 
+static void unmark_and_free(struct commit_list *list, unsigned int mark)
+{
+	while (list) {
+		struct commit_list *temp = list;
+		temp->item->object.flags &= ~mark;
+		list = temp->next;
+		free(temp);
+	}
+}
+
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
+{
+	struct object *o;
+	struct commit *old, *new;
+	struct commit_list *list, *used;
+	int found = 0;
+
+	/* Both new and old must be commit-ish and new is descendant of
+	 * old.  Otherwise we require --force.
+	 */
+	o = deref_tag(parse_object(old_sha1), NULL, 0);
+	if (!o || o->type != OBJ_COMMIT)
+		return 0;
+	old = (struct commit *) o;
+
+	o = deref_tag(parse_object(new_sha1), NULL, 0);
+	if (!o || o->type != OBJ_COMMIT)
+		return 0;
+	new = (struct commit *) o;
+
+	if (parse_commit(new) < 0)
+		return 0;
+
+	used = list = NULL;
+	commit_list_insert(new, &list);
+	while (list) {
+		new = pop_most_recent_commit(&list, 1);
+		commit_list_insert(new, &used);
+		if (new == old) {
+			found = 1;
+			break;
+		}
+	}
+	unmark_and_free(list, 1);
+	unmark_and_free(used, 1);
+	return found;
+}
+
 /*
  * Return true if there is anything to report, otherwise false.
  */
diff --git a/remote.h b/remote.h
index 41b7ac2..e14d041 100644
--- a/remote.h
+++ b/remote.h
@@ -76,6 +76,7 @@ int check_ref_type(const struct ref *ref, int flags);
 void free_refs(struct ref *ref);
 
 int resolve_remote_symref(struct ref *ref, struct ref *list);
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
 
 /*
  * Removes and frees any duplicate refs in the map.
-- 
1.6.2.rc1.223.gfed32
Previous: Jay SoffianNext: Jeff King
Message 15 of 38 in “New output style for git remote show”
  1. 00/13 New output style for git remote showJay Soffian, Feb 23, 2009
  2. 01/13 remote: rename variable and eliminate redundant function callJay Soffian, Feb 23, 2009
  3. 02/13 remote: remove unused code in get_ref_statesJay Soffian, Feb 23, 2009
  4. 03/13 remote: fix two inconsistencies in the output of "show <remote>"Jay Soffian, Feb 23, 2009
  5. 04/13 remote: make get_remote_ref_states() always populate states.trackedJay Soffian, Feb 23, 2009
  6. Junio C HamanoFeb 24, 2009
  7. Jay SoffianFeb 24, 2009
  8. Jay SoffianFeb 24, 2009
  9. 05/13 remote: name remote_refs consistentlyJay Soffian, Feb 23, 2009
  10. 06/13 string-list: new for_each_string_list() functionJay Soffian, Feb 23, 2009
  11. 07/13 remote: new show output styleJay Soffian, Feb 23, 2009
  12. Jeff KingFeb 23, 2009
  13. Marc BranchaudFeb 23, 2009
  14. 08/13 refactor duplicated get_local_heads() to remote.cJay Soffian, Feb 23, 2009
  15. 09/13 refactor duplicated ref_newer() to remote.cJay Soffian, Feb 23, 2009
  16. Jeff KingFeb 23, 2009
  17. 09/13 refactor duplicated ref_newer() to remote.cJay Soffian, Feb 23, 2009
  18. Johannes SixtFeb 23, 2009
  19. Jay SoffianFeb 23, 2009
  20. 10/13 remote.c: make match_refs() copy src ref before assigning to peer_refJay Soffian, Feb 23, 2009
  21. Junio C HamanoFeb 24, 2009
  22. Jay SoffianFeb 24, 2009
  23. Junio C HamanoFeb 24, 2009
  24. remote.c: make match_refs() copy src ref before assigning to peer_refJay Soffian, Feb 24, 2009
  25. Junio C HamanoFeb 24, 2009
  26. Jay SoffianFeb 24, 2009
  27. Junio C HamanoFeb 24, 2009
  28. 11/13 remote.c: don't short-circuit match_refs() when error in match_explicit_refs()Jay Soffian, Feb 23, 2009
  29. Junio C HamanoFeb 24, 2009
  30. Jay SoffianFeb 24, 2009
  31. 12/13 remote.c: refactor get_remote_ref_states()Jay Soffian, Feb 23, 2009
  32. Jeff KingFeb 23, 2009
  33. Jay SoffianFeb 23, 2009
  34. Jay SoffianFeb 23, 2009
  35. Jeff KingFeb 24, 2009
  36. 13/13 remote: new show output style for push refspecsJay Soffian, Feb 23, 2009
  37. Jeff KingFeb 23, 2009
  38. Jay SoffianFeb 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.