@@ -45,12 +45,16 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
xpparam_t xpp;
xdemitconf_t xecfg;
- if (!one)
- return !regexec_buf(regexp, two->ptr, two->size,
- 1, ®match, 0);
- if (!two)
- return !regexec_buf(regexp, one->ptr, one->size,
- 1, ®match, 0);
+ if (!one || !two) {
+ mmfile_t *which = one ? one : two;
+ int ret;
+ char *string = which->ptr;
+ size_t size = which->size;
+ assert(!(!one && !two));
+ ret = !regexec_buf(regexp, string, size,
+ 1, ®match, 0);
+ return ret;
+ }
/*
* We have both sides; need to run textual diff and see if
Refactor the code around processing an added (!one) or deleted (!two) file in diff_grep, which is used by the -G option. This makes a subsequent change where we'd like to munge the "one" or "two" "ptr" smaller. While we're at it let's add an assert that "one" and "two" can't both be false at the same time, which is always the case. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- diffcore-pickaxe.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)