t / helper / test-write-cache.con commit Merge branch 'bp/fsmonitor-prime-index' (7a79d7e)
   1#include "test-tool.h"
   2#include "cache.h"
   3#include "lockfile.h"
   4
   5static struct lock_file index_lock;
   6
   7int cmd__write_cache(int argc, const char **argv)
   8{
   9        int i, cnt = 1, lockfd;
  10        if (argc == 2)
  11                cnt = strtol(argv[1], NULL, 0);
  12        setup_git_directory();
  13        read_cache();
  14        for (i = 0; i < cnt; i++) {
  15                lockfd = hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
  16                if (0 <= lockfd) {
  17                        write_locked_index(&the_index, &index_lock, COMMIT_LOCK);
  18                } else {
  19                        rollback_lock_file(&index_lock);
  20                }
  21        }
  22
  23        return 0;
  24}