@@ -17,34 +17,99 @@ void test_odb_freshen__cleanup(void)
1717 cl_git_sandbox_cleanup ();
1818}
1919
20- #define LOOSE_STR "hey\n"
21- #define LOOSE_ID "1385f264afb75a56a5bec74243be9b367ba4ca08"
22- #define LOOSE_FN "13/85f264afb75a56a5bec74243be9b367ba4ca08"
20+ static void set_time_wayback (struct stat * out , const char * fn )
21+ {
22+ git_buf fullpath = GIT_BUF_INIT ;
23+ struct p_timeval old [2 ];
24+
25+ old [0 ].tv_sec = 1234567890 ;
26+ old [0 ].tv_usec = 0 ;
27+ old [1 ].tv_sec = 1234567890 ;
28+ old [1 ].tv_usec = 0 ;
29+
30+ git_buf_joinpath (& fullpath , "testrepo.git/objects" , fn );
31+
32+ cl_must_pass (p_utimes (git_buf_cstr (& fullpath ), old ));
33+ cl_must_pass (p_lstat (git_buf_cstr (& fullpath ), out ));
34+ git_buf_free (& fullpath );
35+ }
2336
24- void test_odb_freshen__loose_object (void )
37+ #define LOOSE_STR "my new file\n"
38+ #define LOOSE_BLOB_ID "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"
39+ #define LOOSE_BLOB_FN "a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd"
40+
41+ void test_odb_freshen__loose_blob (void )
2542{
2643 git_oid expected_id , id ;
2744 struct stat before , after ;
28- struct p_timeval old_times [2 ];
2945
30- cl_git_pass (git_oid_fromstr (& expected_id , LOOSE_ID ));
46+ cl_git_pass (git_oid_fromstr (& expected_id , LOOSE_BLOB_ID ));
47+ set_time_wayback (& before , LOOSE_BLOB_FN );
3148
32- old_times [ 0 ]. tv_sec = 1234567890 ;
33- old_times [ 0 ]. tv_usec = 0 ;
34- old_times [ 1 ]. tv_sec = 1234567890 ;
35- old_times [ 1 ]. tv_usec = 0 ;
49+ /* make sure we freshen a blob */
50+ cl_git_pass ( git_blob_create_frombuffer ( & id , repo , LOOSE_STR , CONST_STRLEN ( LOOSE_STR ))) ;
51+ cl_assert_equal_oid ( & expected_id , & id ) ;
52+ cl_must_pass ( p_lstat ( "testrepo.git/objects/" LOOSE_BLOB_FN , & after )) ;
3653
37- /* set time to way back */
38- cl_must_pass (p_utimes ("testrepo.git/objects/" LOOSE_FN , old_times ));
39- cl_must_pass (p_lstat ("testrepo.git/objects/" LOOSE_FN , & before ));
54+ cl_assert (before .st_atime < after .st_atime );
55+ cl_assert (before .st_mtime < after .st_mtime );
56+ }
57+
58+ #define LOOSE_TREE_ID "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
59+ #define LOOSE_TREE_FN "94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
60+
61+ void test_odb_freshen__loose_tree (void )
62+ {
63+ git_oid expected_id , id ;
64+ git_tree * tree ;
65+ struct stat before , after ;
66+
67+ cl_git_pass (git_oid_fromstr (& expected_id , LOOSE_TREE_ID ));
68+ set_time_wayback (& before , LOOSE_TREE_FN );
69+
70+ cl_git_pass (git_tree_lookup (& tree , repo , & expected_id ));
71+ cl_git_pass (git_tree_create_updated (& id , repo , tree , 0 , NULL ));
4072
41- cl_git_pass (git_odb_write (& id , odb , LOOSE_STR , CONST_STRLEN (LOOSE_STR ),
42- GIT_OBJ_BLOB ));
73+ /* make sure we freshen a tree */
4374 cl_assert_equal_oid (& expected_id , & id );
44- cl_must_pass (p_lstat ("testrepo.git/objects/" LOOSE_FN , & after ));
75+ cl_must_pass (p_lstat ("testrepo.git/objects/" LOOSE_TREE_FN , & after ));
76+
77+ cl_assert (before .st_atime < after .st_atime );
78+ cl_assert (before .st_mtime < after .st_mtime );
79+
80+ git_tree_free (tree );
81+ }
82+
83+ void test_odb_freshen__tree_during_commit (void )
84+ {
85+ git_oid tree_id , parent_id , commit_id ;
86+ git_tree * tree ;
87+ git_commit * parent ;
88+ git_signature * signature ;
89+ struct stat before , after ;
90+
91+ cl_git_pass (git_oid_fromstr (& tree_id , LOOSE_TREE_ID ));
92+ cl_git_pass (git_tree_lookup (& tree , repo , & tree_id ));
93+ set_time_wayback (& before , LOOSE_TREE_FN );
4594
95+ cl_git_pass (git_oid_fromstr (& parent_id , "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" ));
96+ cl_git_pass (git_commit_lookup (& parent , repo , & parent_id ));
97+
98+ cl_git_pass (git_signature_new (& signature ,
99+ "Refresher" , "refresher@example.com" , 1488547083 , 0 ));
100+
101+ cl_git_pass (git_commit_create (& commit_id , repo , NULL ,
102+ signature , signature , NULL , "New commit pointing to old tree" ,
103+ tree , 1 , (const git_commit * * )& parent ));
104+
105+ /* make sure we freshen the tree the commit points to */
106+ cl_must_pass (p_lstat ("testrepo.git/objects/" LOOSE_TREE_FN , & after ));
46107 cl_assert (before .st_atime < after .st_atime );
47108 cl_assert (before .st_mtime < after .st_mtime );
109+
110+ git_signature_free (signature );
111+ git_commit_free (parent );
112+ git_tree_free (tree );
48113}
49114
50115#define PACKED_STR "Testing a readme.txt\n"
0 commit comments