aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJens Lehmann <Jens.Lehmann@web.de>2010-01-18 21:26:18 +0100
committerJunio C Hamano <gitster@pobox.com>2010-01-18 17:28:21 -0800
commite3d42c4773bccebb50f01b108d20b06c6a11e615 (patch)
tree08850034e0df462aab65fc69cd4b36bed6048256 /diff.c
parentf17a5d34948363087db94a1cb2c3c715c1ada2d8 (diff)
downloadgit-e3d42c4773bccebb50f01b108d20b06c6a11e615.tar.gz
git-e3d42c4773bccebb50f01b108d20b06c6a11e615.tar.xz
Performance optimization for detection of modified submodules
In the worst case is_submodule_modified() got called three times for each submodule. The information we got from scanning the whole submodule tree the first time can be reused instead. New parameters have been added to diff_change() and diff_addremove(), the information is stored in a new member of struct diff_filespec. Its value is then reused instead of calling is_submodule_modified() again. When no explicit "-dirty" is needed in the output the call to is_submodule_modified() is not necessary when the submodules HEAD already disagrees with the ref of the superproject, as this alone marks it as modified. To achieve that, get_stat_data() got an extra argument. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/diff.c b/diff.c
index 750c066a5..8986873c0 100644
--- a/diff.c
+++ b/diff.c
@@ -2032,7 +2032,7 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
char *data = xmalloc(100), *dirty = "";
/* Are we looking at the work tree? */
- if (!s->sha1_valid && is_submodule_modified(s->path))
+ if (!s->sha1_valid && s->dirty_submodule)
dirty = "-dirty";
len = snprintf(data, 100,
@@ -3719,7 +3719,7 @@ int diff_result_code(struct diff_options *opt, int status)
void diff_addremove(struct diff_options *options,
int addremove, unsigned mode,
const unsigned char *sha1,
- const char *concatpath)
+ const char *concatpath, unsigned dirty_submodule)
{
struct diff_filespec *one, *two;
@@ -3751,8 +3751,10 @@ void diff_addremove(struct diff_options *options,
if (addremove != '+')
fill_filespec(one, sha1, mode);
- if (addremove != '-')
+ if (addremove != '-') {
fill_filespec(two, sha1, mode);
+ two->dirty_submodule = dirty_submodule;
+ }
diff_queue(&diff_queued_diff, one, two);
if (!DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))
@@ -3763,7 +3765,8 @@ void diff_change(struct diff_options *options,
unsigned old_mode, unsigned new_mode,
const unsigned char *old_sha1,
const unsigned char *new_sha1,
- const char *concatpath)
+ const char *concatpath,
+ unsigned old_dirty_submodule, unsigned new_dirty_submodule)
{
struct diff_filespec *one, *two;
@@ -3776,6 +3779,8 @@ void diff_change(struct diff_options *options,
const unsigned char *tmp_c;
tmp = old_mode; old_mode = new_mode; new_mode = tmp;
tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
+ tmp = old_dirty_submodule; old_dirty_submodule = new_dirty_submodule;
+ new_dirty_submodule = tmp;
}
if (options->prefix &&
@@ -3786,6 +3791,8 @@ void diff_change(struct diff_options *options,
two = alloc_filespec(concatpath);
fill_filespec(one, old_sha1, old_mode);
fill_filespec(two, new_sha1, new_mode);
+ one->dirty_submodule = old_dirty_submodule;
+ two->dirty_submodule = new_dirty_submodule;
diff_queue(&diff_queued_diff, one, two);
if (!DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))