Thread (193 messages) flat view 193 messages, 3 authors, 2021-03-21
STALE1982d

[PATCH] read_tree(): pass "int stage" as context to read_tree_recursive()

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:46:37
Subsystem: the rest · Maintainer: Linus Torvalds

Back in history, read_tree_recursive() did not have context argument to
pass custom parameters through. To support read_tree(), it took "stage"
from read_tree() and pass it to read_tree_fn_t function.  Then context
argument was added but "stage" remains as a read_tree_fn_t argument.

This patch converts read_tree() to pass stage as a context instead,
thus remove the last usage of "stage" argument in
read_tree_recursive() and read_tree_fn_t. When the opportunity comes,
"stage" should be removed from read_tree_fn_t and read_tree_recursive().

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 tree.c |    6 +++---
 tree.h |    1 +
 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tree.c b/tree.c
index 0d703a0..02f2ca0 100644
--- a/tree.c
+++ b/tree.c
@@ -31,7 +31,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
 
 static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
 {
-	return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
+	return read_one_entry_opt(sha1, base, baselen, pathname, mode, *(int *)context,
 				  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
 }
 
@@ -41,7 +41,7 @@ static int read_one_entry(const unsigned char *sha1, const char *base, int basel
  */
 static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
 {
-	return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
+	return read_one_entry_opt(sha1, base, baselen, pathname, mode, *(int *)context,
 				  ADD_CACHE_JUST_APPEND);
 }
 
@@ -206,7 +206,7 @@ int read_tree(struct tree *tree, int stage, const char **match)
 
 	if (!fn)
 		fn = read_one_entry_quick;
-	err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL);
+	err = read_tree_recursive(tree, "", 0, 0, match, fn, &stage);
 	if (fn == read_one_entry || err)
 		return err;
 
diff --git a/tree.h b/tree.h
index 2ff01a4..d0f4c9b 100644
--- a/tree.h
+++ b/tree.h
@@ -21,6 +21,7 @@ int parse_tree(struct tree *tree);
 struct tree *parse_tree_indirect(const unsigned char *sha1);
 
 #define READ_TREE_RECURSIVE 1
+/* FIXME: remove "int stage" argument from read_tree_fn_t */
 typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int, void *);
 
 extern int read_tree_recursive(struct tree *tree,
-- 
1.6.2.2.693.g5a1be
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help