@@ -38,7 +38,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
3838 return commit ;
3939}
4040
41- static int push_commit (git_revwalk * walk , const git_oid * oid , int uninteresting , int from_glob )
41+ int git_revwalk__push_commit (git_revwalk * walk , const git_oid * oid , const git_revwalk__push_options * opts )
4242{
4343 git_oid commit_id ;
4444 int error ;
@@ -54,7 +54,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
5454
5555 if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL ) {
5656 /* If this comes from e.g. push_glob("tags"), ignore this */
57- if (from_glob )
57+ if (opts -> from_glob )
5858 return 0 ;
5959
6060 git_error_set (GIT_ERROR_INVALID , "object is not a committish" );
@@ -74,16 +74,18 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
7474 if (commit -> uninteresting )
7575 return 0 ;
7676
77- if (uninteresting ) {
77+ if (opts -> uninteresting ) {
7878 walk -> limited = 1 ;
7979 walk -> did_hide = 1 ;
8080 } else {
8181 walk -> did_push = 1 ;
8282 }
8383
84- commit -> uninteresting = uninteresting ;
84+ commit -> uninteresting = opts -> uninteresting ;
8585 list = walk -> user_input ;
86- if (git_commit_list_insert (commit , & list ) == NULL ) {
86+ if ((opts -> insert_by_date &&
87+ git_commit_list_insert_by_date (commit , & list ) == NULL ) ||
88+ git_commit_list_insert (commit , & list ) == NULL ) {
8789 git_error_set_oom ();
8890 return -1 ;
8991 }
@@ -95,29 +97,36 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
9597
9698int git_revwalk_push (git_revwalk * walk , const git_oid * oid )
9799{
100+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
101+
98102 assert (walk && oid );
99- return push_commit (walk , oid , 0 , false);
103+
104+ return git_revwalk__push_commit (walk , oid , & opts );
100105}
101106
102107
103108int git_revwalk_hide (git_revwalk * walk , const git_oid * oid )
104109{
110+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
105111 assert (walk && oid );
106- return push_commit (walk , oid , 1 , false);
112+
113+ opts .uninteresting = 1 ;
114+ return git_revwalk__push_commit (walk , oid , & opts );
107115}
108116
109- static int push_ref (git_revwalk * walk , const char * refname , int hide , int from_glob )
117+ int git_revwalk__push_ref (git_revwalk * walk , const char * refname , const git_revwalk__push_options * opts )
110118{
111119 git_oid oid ;
112120
113121 if (git_reference_name_to_id (& oid , walk -> repo , refname ) < 0 )
114122 return -1 ;
115123
116- return push_commit (walk , & oid , hide , from_glob );
124+ return git_revwalk__push_commit (walk , & oid , opts );
117125}
118126
119- static int push_glob (git_revwalk * walk , const char * glob , int hide )
127+ int git_revwalk__push_glob (git_revwalk * walk , const char * glob , const git_revwalk__push_options * given_opts )
120128{
129+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
121130 int error = 0 ;
122131 git_buf buf = GIT_BUF_INIT ;
123132 git_reference * ref ;
@@ -126,6 +135,9 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
126135
127136 assert (walk && glob );
128137
138+ if (given_opts )
139+ memcpy (& opts , given_opts , sizeof (opts ));
140+
129141 /* refs/ is implied if not given in the glob */
130142 if (git__prefixcmp (glob , GIT_REFS_DIR ) != 0 )
131143 git_buf_joinpath (& buf , GIT_REFS_DIR , glob );
@@ -141,8 +153,9 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
141153 if ((error = git_reference_iterator_glob_new (& iter , walk -> repo , buf .ptr )) < 0 )
142154 goto out ;
143155
156+ opts .from_glob = true;
144157 while ((error = git_reference_next (& ref , iter )) == 0 ) {
145- error = push_ref (walk , git_reference_name (ref ), hide , true );
158+ error = git_revwalk__push_ref (walk , git_reference_name (ref ), & opts );
146159 git_reference_free (ref );
147160 if (error < 0 )
148161 break ;
@@ -158,36 +171,49 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
158171
159172int git_revwalk_push_glob (git_revwalk * walk , const char * glob )
160173{
174+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
161175 assert (walk && glob );
162- return push_glob (walk , glob , 0 );
176+
177+ return git_revwalk__push_glob (walk , glob , & opts );
163178}
164179
165180int git_revwalk_hide_glob (git_revwalk * walk , const char * glob )
166181{
182+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
167183 assert (walk && glob );
168- return push_glob (walk , glob , 1 );
184+
185+ opts .uninteresting = 1 ;
186+ return git_revwalk__push_glob (walk , glob , & opts );
169187}
170188
171189int git_revwalk_push_head (git_revwalk * walk )
172190{
191+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
173192 assert (walk );
174- return push_ref (walk , GIT_HEAD_FILE , 0 , false);
193+
194+ return git_revwalk__push_ref (walk , GIT_HEAD_FILE , & opts );
175195}
176196
177197int git_revwalk_hide_head (git_revwalk * walk )
178198{
199+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
179200 assert (walk );
180- return push_ref (walk , GIT_HEAD_FILE , 1 , false);
201+
202+ opts .uninteresting = 1 ;
203+ return git_revwalk__push_ref (walk , GIT_HEAD_FILE , & opts );
181204}
182205
183206int git_revwalk_push_ref (git_revwalk * walk , const char * refname )
184207{
208+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
185209 assert (walk && refname );
186- return push_ref (walk , refname , 0 , false);
210+
211+ return git_revwalk__push_ref (walk , refname , & opts );
187212}
188213
189214int git_revwalk_push_range (git_revwalk * walk , const char * range )
190215{
216+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
191217 git_revspec revspec ;
192218 int error = 0 ;
193219
@@ -207,10 +233,12 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
207233 goto out ;
208234 }
209235
210- if ((error = push_commit (walk , git_object_id (revspec .from ), 1 , false)))
236+ opts .uninteresting = 1 ;
237+ if ((error = git_revwalk__push_commit (walk , git_object_id (revspec .from ), & opts )))
211238 goto out ;
212239
213- error = push_commit (walk , git_object_id (revspec .to ), 0 , false);
240+ opts .uninteresting = 0 ;
241+ error = git_revwalk__push_commit (walk , git_object_id (revspec .to ), & opts );
214242
215243out :
216244 git_object_free (revspec .from );
@@ -220,8 +248,10 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
220248
221249int git_revwalk_hide_ref (git_revwalk * walk , const char * refname )
222250{
251+ git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT ;
223252 assert (walk && refname );
224- return push_ref (walk , refname , 1 , false);
253+ opts .uninteresting = 1 ;
254+ return git_revwalk__push_ref (walk , refname , & opts );
225255}
226256
227257static int revwalk_enqueue_timesort (git_revwalk * walk , git_commit_list_node * commit )
0 commit comments