Merge branch 'jk/fix-refresh-utime' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 27 Jul 2015 19:21:40 +0000 (12:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Jul 2015 19:21:40 +0000 (12:21 -0700)
Fix a small bug in our use of umask() return value.

* jk/fix-refresh-utime:
check_and_freshen_file: fix reversed success-check

sha1_file.c
index 0c70152c17fbf612bbdf0112bf12fe8f7a852761..a68ae18dd8557e37dca82be3825cabe8f4cb53f4 100644 (file)
@@ -443,6 +443,7 @@ void prepare_alt_odb(void)
        read_info_alternates(get_object_directory(), 0);
 }
 
+/* Returns 1 if we have successfully freshened the file, 0 otherwise. */
 static int freshen_file(const char *fn)
 {
        struct utimbuf t;
@@ -450,11 +451,18 @@ static int freshen_file(const char *fn)
        return !utime(fn, &t);
 }
 
+/*
+ * All of the check_and_freshen functions return 1 if the file exists and was
+ * freshened (if freshening was requested), 0 otherwise. If they return
+ * 0, you should not assume that it is safe to skip a write of the object (it
+ * either does not exist on disk, or has a stale mtime and may be subject to
+ * pruning).
+ */
 static int check_and_freshen_file(const char *fn, int freshen)
 {
        if (access(fn, F_OK))
                return 0;
-       if (freshen && freshen_file(fn))
+       if (freshen && !freshen_file(fn))
                return 0;
        return 1;
 }