Skip to content

Commit

Permalink
refresh_index_quietly(): express "optional" nature of index writing b…
Browse files Browse the repository at this point in the history
…etter

The point of the part of the code this patch touches is that if
we modified the active_cache, we try to write it out and make it
the index file for later users to use by calling
"commit_locked_index", but we do not really care about the
failure from this sequence because it is done purely as an
optimization.

The original code called three functions primarily for their
side effects but as condition of an if statement, which is
admittedly a bad style.

Incidentally, it squelches an "empty if body" warning from gcc.

Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
gitster committed Nov 9, 2007
1 parent 4f2e94c commit fbbdbfc
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,11 @@ static void refresh_index_quietly(void)
discard_cache();
read_cache();
refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
if (active_cache_changed) {
if (write_cache(fd, active_cache, active_nr) ||
close(fd) ||
commit_locked_index(lock_file))
; /*
* silently ignore it -- we haven't mucked
* with the real index.
*/
}

if (active_cache_changed &&
!write_cache(fd, active_cache, active_nr) && !close(fd))
commit_locked_index(lock_file);

rollback_lock_file(lock_file);
}

Expand Down

0 comments on commit fbbdbfc

Please sign in to comment.