]> git.ipfire.org Git - thirdparty/git.git/commitdiff
clean: remove unnecessary variable
authorMatheus Tavares <matheus.bernardino@usp.br>
Thu, 6 May 2021 19:33:15 +0000 (16:33 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 May 2021 22:48:11 +0000 (07:48 +0900)
The variable `matches` used to hold the return of a `dir_path_match()`
call that was removed in 95c11ecc73 ("Fix error-prone fill_directory()
API; make it only return matches", 2020-04-01). Now `matches` will
always hold 0, which is the value it's initialized with; and the
condition `matches != MATCHED_EXACTLY` will always evaluate to true. So
let's remove this unnecessary variable.

Interestingly, it seems that `matches != MATCHED_EXACTLY` was already
unnecessary before 95c11ecc73. That's because `remove_directories` is
always set to 1 when we have pathspecs; So, in the condition
`!remove_directories && matches != MATCHED_EXACTLY`, we would either:

- have pathspecs (or have been given `-d`) and ignore `matches` because
  `remove_directories` is 1; or

- not have pathspecs (nor `-d`) and end up just checking that
  `0 != MATCHED_EXACTLY`, as `matches` would never get reassigned
  after its zero initialization (because there is no pathspec to match).

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clean.c

index 4ca12bc0c0ba2c3bc3084a320835cf83600173ce..e3046b962c1d0604558c11b39b093b04069cb371 100644 (file)
@@ -976,7 +976,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
-               int matches = 0;
                struct stat st;
                const char *rel;
 
@@ -986,8 +985,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                if (lstat(ent->name, &st))
                        die_errno("Cannot lstat '%s'", ent->name);
 
-               if (S_ISDIR(st.st_mode) && !remove_directories &&
-                   matches != MATCHED_EXACTLY)
+               if (S_ISDIR(st.st_mode) && !remove_directories)
                        continue;
 
                rel = relative_path(ent->name, prefix, &buf);