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

[PATCH 2/4] archive: factor out helper functions for handling attributes

From
René Scharfe <l.s.r@web.de>
Date
Aug 19, 2017, 05:29 UTC
Message-ID
<aaf9c857-76b9-5766-59ce-cffc1b65015f@web.de>
In-Reply-To
<887652a4-3f03-e2dd-2c68-cff4f7194898@web.de>

Add helpers for accessing attributes that encapsulate the details of how to retrieve their values.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 archive.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/archive.c b/archive.c
index 557dd2db85..8e5f632912 100644
--- a/archive.c
+++ b/archive.c
@@ -103,12 +103,30 @@ struct archiver_context {
 	struct directory *bottom;
 };
 
+static const struct attr_check *get_archive_attrs(const char *path)
+{
+	static struct attr_check *check;
+	if (!check)
+		check = attr_check_initl("export-ignore", "export-subst", NULL);
+	return git_check_attr(path, check) ? NULL : check;
+}
+
+static int check_attr_export_ignore(const struct attr_check *check)
+{
+	return check && ATTR_TRUE(check->items[0].value);
+}
+
+static int check_attr_export_subst(const struct attr_check *check)
+{
+	return check && ATTR_TRUE(check->items[1].value);
+}
+
 static int write_archive_entry(const unsigned char *sha1, const char *base,
 		int baselen, const char *filename, unsigned mode, int stage,
 		void *context)
 {
 	static struct strbuf path = STRBUF_INIT;
-	static struct attr_check *check;
+	const struct attr_check *check;
 	struct archiver_context *c = context;
 	struct archiver_args *args = c->args;
 	write_archive_entry_fn_t write_entry = c->write_entry;
@@ -125,13 +143,10 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 		strbuf_addch(&path, '/');
 	path_without_prefix = path.buf + args->baselen;
 
-	if (!check)
-		check = attr_check_initl("export-ignore", "export-subst", NULL);
-	if (!git_check_attr(path_without_prefix, check)) {
-		if (ATTR_TRUE(check->items[0].value))
-			return 0;
-		args->convert = ATTR_TRUE(check->items[1].value);
-	}
+	check = get_archive_attrs(path_without_prefix);
+	if (check_attr_export_ignore(check))
+		return 0;
+	args->convert = check_attr_export_subst(check);
 
 	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
 		if (args->verbose)
-- 
2.14.1
Previous: René ScharfeNext: René Scharfe
Message 6 of 17 in “Bug?: git archive exclude pathspec and gitattributes export-ignore”
  1. David AdamAug 13, 2017
  2. René ScharfeAug 14, 2017
  3. David AdamAug 15, 2017
  4. René ScharfeAug 19, 2017
  5. 1/4 t5001: add tests for export-ignore attributes and exclude pathspecsRené Scharfe, Aug 19, 2017
  6. 2/4 archive: factor out helper functions for handling attributesRené Scharfe, Aug 19, 2017
  7. 4/4 archive: queue directories for all types of pathspecsRené Scharfe, Aug 19, 2017
  8. René ScharfeAug 19, 2017
  9. René ScharfeAug 19, 2017
  10. Junio C HamanoAug 19, 2017
  11. Jeff KingAug 20, 2017
  12. René ScharfeSep 12, 2017
  13. Jeff KingSep 13, 2017
  14. René ScharfeSep 13, 2017
  15. Stefan BellerAug 21, 2017
  16. Junio C HamanoAug 19, 2017
  17. 3/4 archive: don't queue excluded directoriesRené Scharfe, Aug 19, 2017

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.