2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 #define MTIME_CHANGED 0x0001
9 #define CTIME_CHANGED 0x0002
10 #define OWNER_CHANGED 0x0004
11 #define MODE_CHANGED 0x0008
12 #define INODE_CHANGED 0x0010
13 #define DATA_CHANGED 0x0020
15 static int match_stat(struct cache_entry
*ce
, struct stat
*st
)
17 unsigned int changed
= 0;
19 if (ce
->mtime
.sec
!= (unsigned int)st
->st_mtim
.tv_sec
||
20 ce
->mtime
.nsec
!= (unsigned int)st
->st_mtim
.tv_nsec
)
21 changed
|= MTIME_CHANGED
;
22 if (ce
->ctime
.sec
!= (unsigned int)st
->st_ctim
.tv_sec
||
23 ce
->ctime
.nsec
!= (unsigned int)st
->st_ctim
.tv_nsec
)
24 changed
|= CTIME_CHANGED
;
25 if (ce
->st_uid
!= (unsigned int)st
->st_uid
||
26 ce
->st_gid
!= (unsigned int)st
->st_gid
)
27 changed
|= OWNER_CHANGED
;
28 if (ce
->st_mode
!= (unsigned int)st
->st_mode
)
29 changed
|= MODE_CHANGED
;
30 if (ce
->st_dev
!= (unsigned int)st
->st_dev
||
31 ce
->st_ino
!= (unsigned int)st
->st_ino
)
32 changed
|= INODE_CHANGED
;
33 if (ce
->st_size
!= (unsigned int)st
->st_size
)
34 changed
|= DATA_CHANGED
;
38 static void show_differences(struct cache_entry
*ce
, struct stat
*cur
,
39 void *old_contents
, unsigned long long old_size
)
41 static char cmd
[1000];
44 snprintf(cmd
, sizeof(cmd
), "diff -u - %s", ce
->name
);
46 fwrite(old_contents
, old_size
, 1, f
);
50 int main(int argc
, char **argv
)
52 int entries
= read_cache();
59 for (i
= 0; i
< entries
; i
++) {
61 struct cache_entry
*ce
= active_cache
[i
];
67 if (stat(ce
->name
, &st
) < 0) {
68 printf("%s: %s\n", ce
->name
, strerror(errno
));
71 changed
= match_stat(ce
, &st
);
73 printf("%s: ok\n", ce
->name
);
76 printf("%.*s: ", ce
->namelen
, ce
->name
);
77 for (n
= 0; n
< 20; n
++)
78 printf("%02x", ce
->sha1
[n
]);
80 new = read_sha1_file(ce
->sha1
, type
, &size
);
81 show_differences(ce
, &st
, new, size
);