Add a "checkout-cache" command which does what the name suggests.
[git/debian.git] / show-diff.c
blobd9af29fd876612855dfe659f6bb270804118edef
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
8 static void show_differences(struct cache_entry *ce, struct stat *cur,
9 void *old_contents, unsigned long long old_size)
11 static char cmd[1000];
12 FILE *f;
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);
20 int main(int argc, char **argv)
22 int entries = read_cache();
23 int i;
25 if (entries < 0) {
26 perror("read_cache");
27 exit(1);
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;
37 if (stat(ce->name, &st) < 0) {
38 printf("%s: %s\n", ce->name, strerror(errno));
39 continue;
41 changed = cache_match_stat(ce, &st);
42 if (!changed) {
43 printf("%s: ok\n", ce->name);
44 continue;
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);
54 return 0;