diff options
| author | Ben Straub <bstraub@github.com> | 2012-07-30 14:37:40 -0700 | 
|---|---|---|
| committer | Ben Straub <bstraub@github.com> | 2012-07-30 14:37:40 -0700 | 
| commit | f1587b97a11e3a7283b32f5af46b7d057b8be4c5 (patch) | |
| tree | b028efd2921b06c5c94db33abea9b83d0ff6edfb /src/index.c | |
| parent | e0681f6d07a9f6041e7450af4715a8df8552ad2e (diff) | |
| download | libgit2-f1587b97a11e3a7283b32f5af46b7d057b8be4c5.tar.gz | |
Checkout: use git_index_read_tree_with_stats.
New variant of git_index_read_tree that fills in
the 'total' field of a git_indexer_stats struct
as it's walking the tree.
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 27 | 
1 files changed, 23 insertions, 4 deletions
diff --git a/src/index.c b/src/index.c index 89d479870..434c1f102 100644 --- a/src/index.c +++ b/src/index.c @@ -985,12 +985,19 @@ int git_index_entry_stage(const git_index_entry *entry)  	return (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;  } +typedef struct read_tree_data { +	git_index *index; +	git_indexer_stats *stats; +} read_tree_data; +  static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *data)  { -	git_index *index = data; +	read_tree_data *rtd = data;  	git_index_entry *entry = NULL;  	git_buf path = GIT_BUF_INIT; +	rtd->stats->total++; +  	if (git_tree_entry__is_tree(tentry))  		return 0; @@ -1005,7 +1012,7 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da  	entry->path = git_buf_detach(&path);  	git_buf_free(&path); -	if (index_insert(index, entry, 0) < 0) { +	if (index_insert(rtd->index, entry, 0) < 0) {  		index_entry_free(entry);  		return -1;  	} @@ -1013,9 +1020,21 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da  	return 0;  } -int git_index_read_tree(git_index *index, git_tree *tree) +int git_index_read_tree_with_stats(git_index *index, git_tree *tree, git_indexer_stats *stats)  { +	git_indexer_stats dummy_stats; +	read_tree_data rtd = {index, NULL}; + +	if (!stats) stats = &dummy_stats; +	stats->total = 0; +	rtd.stats = stats; +  	git_index_clear(index); -	return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index); +	return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, &rtd); +} + +int git_index_read_tree(git_index *index, git_tree *tree) +{ +	return git_index_read_tree_with_stats(index, tree, NULL);  }  | 
