reencode_string: use st_add/st_mult helpers
[gitweb.git] / rerere.c
index 51376cf6da3b8ab8f8e0c4f20c307fef9dec8392..e0862e27786244b1a98723d09475223cc001dd62 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -159,8 +159,8 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
                ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
                /* ... and add it in. */
                rerere_dir_nr++;
-               memmove(rerere_dir + pos + 1, rerere_dir + pos,
-                       (rerere_dir_nr - pos - 1) * sizeof(*rerere_dir));
+               MOVE_ARRAY(rerere_dir + pos + 1, rerere_dir + pos,
+                          rerere_dir_nr - pos - 1);
                rerere_dir[pos] = rr_dir;
                scan_rerere_dir(rr_dir);
        }
@@ -703,10 +703,9 @@ static int merge(const struct rerere_id *id, const char *path)
        return ret;
 }
 
-static struct lock_file index_lock;
-
 static void update_paths(struct string_list *update)
 {
+       struct lock_file index_lock = LOCK_INIT;
        int i;
 
        hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
@@ -719,11 +718,9 @@ static void update_paths(struct string_list *update)
                        item->string);
        }
 
-       if (active_cache_changed) {
-               if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
-                       die("Unable to write new index file");
-       } else
-               rollback_lock_file(&index_lock);
+       if (write_locked_index(&the_index, &index_lock,
+                              COMMIT_LOCK | SKIP_IF_UNCHANGED))
+               die("Unable to write new index file");
 }
 
 static void remove_variant(struct rerere_id *id)
@@ -981,8 +978,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
                        break;
                i = ce_stage(ce) - 1;
                if (!mmfile[i].ptr) {
-                       mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,
-                                                      &size);
+                       mmfile[i].ptr = read_object_file(&ce->oid, &type,
+                                                        &size);
                        mmfile[i].size = size;
                }
        }
@@ -1133,14 +1130,14 @@ int rerere_forget(struct pathspec *pathspec)
  * Garbage collection support
  */
 
-static time_t rerere_created_at(struct rerere_id *id)
+static timestamp_t rerere_created_at(struct rerere_id *id)
 {
        struct stat st;
 
        return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
 }
 
-static time_t rerere_last_used_at(struct rerere_id *id)
+static timestamp_t rerere_last_used_at(struct rerere_id *id)
 {
        struct stat st;
 
@@ -1157,11 +1154,11 @@ static void unlink_rr_item(struct rerere_id *id)
        id->collection->status[id->variant] = 0;
 }
 
-static void prune_one(struct rerere_id *id, time_t now,
-                     int cutoff_resolve, int cutoff_noresolve)
+static void prune_one(struct rerere_id *id,
+                     timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
 {
-       time_t then;
-       int cutoff;
+       timestamp_t then;
+       timestamp_t cutoff;
 
        then = rerere_last_used_at(id);
        if (then)
@@ -1172,7 +1169,7 @@ static void prune_one(struct rerere_id *id, time_t now,
                        return;
                cutoff = cutoff_noresolve;
        }
-       if (then < now - cutoff * 86400)
+       if (then < cutoff)
                unlink_rr_item(id);
 }
 
@@ -1182,15 +1179,15 @@ void rerere_gc(struct string_list *rr)
        DIR *dir;
        struct dirent *e;
        int i;
-       time_t now = time(NULL);
-       int cutoff_noresolve = 15;
-       int cutoff_resolve = 60;
+       timestamp_t now = time(NULL);
+       timestamp_t cutoff_noresolve = now - 15 * 86400;
+       timestamp_t cutoff_resolve = now - 60 * 86400;
 
        if (setup_rerere(rr, 0) < 0)
                return;
 
-       git_config_get_int("gc.rerereresolved", &cutoff_resolve);
-       git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
+       git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
+       git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now);
        git_config(git_default_config, NULL);
        dir = opendir(git_path("rr-cache"));
        if (!dir)
@@ -1211,7 +1208,7 @@ void rerere_gc(struct string_list *rr)
                for (id.variant = 0, id.collection = rr_dir;
                     id.variant < id.collection->status_nr;
                     id.variant++) {
-                       prune_one(&id, now, cutoff_resolve, cutoff_noresolve);
+                       prune_one(&id, cutoff_resolve, cutoff_noresolve);
                        if (id.collection->status[id.variant])
                                now_empty = 0;
                }