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

[PATCH RFC 11/20] cat-file: move filter_object to diff.c

From
Olga Telezhnaya <olyatelezhnaya@gmail.com>
Date
Feb 22, 2019, 16:05 UTC
Message-ID
<0102016915f49a5f-d96e159b-149d-40f9-9789-d0859dc7e2e9-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com>

Move function filter_object to diff.c, like it is done with function textconv_object.

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
---
 builtin/cat-file.c | 23 -----------------------
 diff.c             | 23 +++++++++++++++++++++++
 diff.h             |  4 ++++
 3 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index cd9a4447c8da9..41f333b73d851 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -3,7 +3,6 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
@@ -34,28 +33,6 @@ static int mark_query;
 static int skip_object_info;
 static const char *rest;
 
-static int filter_object(const char *path, unsigned mode,
-			 const struct object_id *oid,
-			 char **buf, unsigned long *size)
-{
-	enum object_type type;
-
-	*buf = read_object_file(oid, &type, size);
-	if (!*buf)
-		return error(_("cannot read object %s '%s'"),
-			     oid_to_hex(oid), path);
-	if ((type == OBJ_BLOB) && S_ISREG(mode)) {
-		struct strbuf strbuf = STRBUF_INIT;
-		if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
-			free(*buf);
-			*size = strbuf.len;
-			*buf = strbuf_detach(&strbuf, NULL);
-		}
-	}
-
-	return 0;
-}
-
 static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 			int unknown_type)
 {
diff --git a/diff.c b/diff.c
index 5306c48652db5..fe7160c86755d 100644
--- a/diff.c
+++ b/diff.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2005 Junio C Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "tempfile.h"
@@ -6524,6 +6525,28 @@ int textconv_object(struct repository *r,
 	return 1;
 }
 
+int filter_object(const char *path, unsigned mode,
+		  const struct object_id *oid,
+		  char **buf, unsigned long *size)
+{
+	enum object_type type;
+
+	*buf = read_object_file(oid, &type, size);
+	if (!*buf)
+		return error(_("cannot read object %s '%s'"),
+			     oid_to_hex(oid), path);
+	if ((type == OBJ_BLOB) && S_ISREG(mode)) {
+		struct strbuf strbuf = STRBUF_INIT;
+		if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
+			free(*buf);
+			*size = strbuf.len;
+			*buf = strbuf_detach(&strbuf, NULL);
+		}
+	}
+
+	return 0;
+}
+
 void setup_diff_pager(struct diff_options *opt)
 {
 	/*
diff --git a/diff.h b/diff.h
index b512d0477ac3a..c3709e611870a 100644
--- a/diff.h
+++ b/diff.h
@@ -476,6 +476,10 @@ int textconv_object(struct repository *repo,
 		    const struct object_id *oid, int oid_valid,
 		    char **buf, unsigned long *buf_size);
 
+int filter_object(const char *path, unsigned mode,
+		  const struct object_id *oid,
+		  char **buf, unsigned long *size);
+
 int parse_rename_score(const char **cp_p);
 
 long parse_algorithm_value(const char *value);

--
https://github.com/git/git/pull/568
Previous: Olga TelezhnayaNext: Olga Telezhnaya
Message 21 of 32 in “cat-file: reuse struct ref_format”
  1. 01/20 cat-file: reuse struct ref_formatOlga Telezhnaya, Feb 22, 2019
  2. 14/20 cat-file: move print_object_or_die to ref-filterOlga Telezhnaya, Feb 22, 2019
  3. 18/20 cat-file: get rid of expand_dataOlga Telezhnaya, Feb 22, 2019
  4. 08/20 cat-file: remove rest from expand_dataOlga Telezhnaya, Feb 22, 2019
  5. Jeff KingFeb 28, 2019
  6. 19/20 cat-file: tests for new atoms addedOlga Telezhnaya, Feb 22, 2019
  7. 17/20 cat-file: reuse ref-filter formatting logicOlga Telezhnaya, Feb 22, 2019
  8. 16/20 for-each-ref: tests for new atom %(raw) addedOlga Telezhnaya, Feb 22, 2019
  9. 20/20 cat-file: update docsOlga Telezhnaya, Feb 22, 2019
  10. 06/20 cat-file: remove mark_query from expand_dataOlga Telezhnaya, Feb 22, 2019
  11. Jeff KingFeb 28, 2019
  12. Christian CouderMar 3, 2019
  13. 03/20 ref-filter: add rest formatting optionOlga Telezhnaya, Feb 22, 2019
  14. Jeff KingFeb 28, 2019
  15. 13/20 cat-file: rewrite print_object_or_dieOlga Telezhnaya, Feb 22, 2019
  16. 09/20 ref-filter: make expand_data globalOlga Telezhnaya, Feb 22, 2019
  17. Jeff KingFeb 28, 2019
  18. 04/20 for-each-ref: tests for new atom %(rest) addedOlga Telezhnaya, Feb 22, 2019
  19. Jeff KingFeb 28, 2019
  20. Olga TelezhnayaMar 1, 2019
  21. 11/20 cat-file: move filter_object to diff.cOlga Telezhnaya, Feb 22, 2019
  22. 10/20 cat-file: inline stream_blobOlga Telezhnaya, Feb 22, 2019
  23. Jeff KingFeb 28, 2019
  24. 15/20 ref-filter: add raw formatting optionOlga Telezhnaya, Feb 22, 2019
  25. 07/20 cat-file: remove skip_object_infoOlga Telezhnaya, Feb 22, 2019
  26. Jeff KingFeb 28, 2019
  27. 05/20 cat-file: remove split_on_whitespaceOlga Telezhnaya, Feb 22, 2019
  28. Jeff KingFeb 28, 2019
  29. 02/20 ref-filter: rename field in ref_array_item stuctOlga Telezhnaya, Feb 22, 2019
  30. Jeff KingFeb 28, 2019
  31. 12/20 cat-file: remove batch_write functionOlga Telezhnaya, Feb 22, 2019
  32. Jeff KingFeb 28, 2019

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.