show-diff.con commit Make the cache stat information comparator public. (734aab7)
   1/*
   2 * GIT - The information manager from hell
   3 *
   4 * Copyright (C) Linus Torvalds, 2005
   5 */
   6#include "cache.h"
   7
   8static void show_differences(struct cache_entry *ce, struct stat *cur,
   9        void *old_contents, unsigned long long old_size)
  10{
  11        static char cmd[1000];
  12        FILE *f;
  13
  14        snprintf(cmd, sizeof(cmd), "diff -u - %s", ce->name);
  15        f = popen(cmd, "w");
  16        fwrite(old_contents, old_size, 1, f);
  17        pclose(f);
  18}
  19
  20int main(int argc, char **argv)
  21{
  22        int entries = read_cache();
  23        int i;
  24
  25        if (entries < 0) {
  26                perror("read_cache");
  27                exit(1);
  28        }
  29        for (i = 0; i < entries; i++) {
  30                struct stat st;
  31                struct cache_entry *ce = active_cache[i];
  32                int n, changed;
  33                unsigned long size;
  34                char type[20];
  35                void *new;
  36
  37                if (stat(ce->name, &st) < 0) {
  38                        printf("%s: %s\n", ce->name, strerror(errno));
  39                        continue;
  40                }
  41                changed = cache_match_stat(ce, &st);
  42                if (!changed) {
  43                        printf("%s: ok\n", ce->name);
  44                        continue;
  45                }
  46                printf("%.*s:  ", ce->namelen, ce->name);
  47                for (n = 0; n < 20; n++)
  48                        printf("%02x", ce->sha1[n]);
  49                printf("\n");
  50                new = read_sha1_file(ce->sha1, type, &size);
  51                show_differences(ce, &st, new, size);
  52                free(new);
  53        }
  54        return 0;
  55}