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

[PATCH 1/4] Move add_name_decoration() and add_ref_decoration() to commit.[ch]

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 11, 2007, 01:28 UTC
Message-ID
<Pine.LNX.4.64.0707110228470.4047@racer.site>
In-Reply-To
<Pine.LNX.4.64.0707110220340.4047@racer.site>

The functions add_{name,ref}_decoration() should really be in commit.[ch], since the struct they are modifying is there, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-log.c |   25 -------------------------
 commit.c      |   25 +++++++++++++++++++++++++
 commit.h      |    3 +++
 3 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 13bae31..c14eea5 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -21,31 +21,6 @@ static const char *fmt_patch_subject_prefix = "PATCH";
 /* this is in builtin-diff.c */
 void add_head(struct rev_info *revs);
 
-static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
-{
-	int plen = strlen(prefix);
-	int nlen = strlen(name);
-	struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
-	memcpy(res->name, prefix, plen);
-	memcpy(res->name + plen, name, nlen + 1);
-	res->next = add_decoration(&name_decoration, obj, res);
-}
-
-static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
-{
-	struct object *obj = parse_object(sha1);
-	if (!obj)
-		return 0;
-	add_name_decoration("", refname, obj);
-	while (obj->type == OBJ_TAG) {
-		obj = ((struct tag *)obj)->tagged;
-		if (!obj)
-			break;
-		add_name_decoration("tag: ", refname, obj);
-	}
-	return 0;
-}
-
 static void cmd_log_init(int argc, const char **argv, const char *prefix,
 		      struct rev_info *rev)
 {
diff --git a/commit.c b/commit.c
index 03436b1..c0748ed 100644
--- a/commit.c
+++ b/commit.c
@@ -1553,3 +1553,28 @@ int in_merge_bases(struct commit *commit, struct commit **reference, int num)
 	free_commit_list(bases);
 	return ret;
 }
+
+void add_name_decoration(const char *prefix, const char *name, struct object *obj)
+{
+	int plen = strlen(prefix);
+	int nlen = strlen(name);
+	struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
+	memcpy(res->name, prefix, plen);
+	memcpy(res->name + plen, name, nlen + 1);
+	res->next = add_decoration(&name_decoration, obj, res);
+}
+
+int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
+{
+	struct object *obj = parse_object(sha1);
+	if (!obj)
+		return 0;
+	add_name_decoration("", refname, obj);
+	while (obj->type == OBJ_TAG) {
+		obj = ((struct tag *)obj)->tagged;
+		if (!obj)
+			break;
+		add_name_decoration("tag: ", refname, obj);
+	}
+	return 0;
+}
diff --git a/commit.h b/commit.h
index 467872e..787ae5e 100644
--- a/commit.h
+++ b/commit.h
@@ -29,6 +29,9 @@ struct name_decoration {
 	char name[1];
 };
 
+void add_name_decoration(const char *prefix, const char *name, struct object *obj);
+int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
+
 struct commit *lookup_commit(const unsigned char *sha1);
 struct commit *lookup_commit_reference(const unsigned char *sha1);
 struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
-- 
1.5.3.rc0.2783.gf3f7
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 11 in “Make --decorate more useful”
  1. 0/4 Make --decorate more usefulJohannes Schindelin, Jul 11, 2007
  2. 1/4 Move add_name_decoration() and add_ref_decoration() to commit.[ch]Johannes Schindelin, Jul 11, 2007
  3. 2/4 Move the --decorate option from builtin-log.c to revision.c.Johannes Schindelin, Jul 11, 2007
  4. Junio C HamanoJul 12, 2007
  5. Johannes SchindelinJul 13, 2007
  6. 3/4 --decorate now decorates ancestors, tooJohannes Schindelin, Jul 11, 2007
  7. Theodore TsoJul 11, 2007
  8. Junio C HamanoJul 12, 2007
  9. Johannes SchindelinJul 14, 2007
  10. Johannes SchindelinJul 21, 2007
  11. 4/4 --decorate: prefer shorter namesJohannes Schindelin, Jul 11, 2007

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.