@@ -105,13 +105,6 @@ static int create_tracking_branch(
105105 git_reference_name (* branch ));
106106}
107107
108- struct head_info {
109- git_repository * repo ;
110- git_oid remote_head_oid ;
111- const git_refspec * refspec ;
112- bool found ;
113- };
114-
115108static int update_head_to_new_branch (
116109 git_repository * repo ,
117110 const git_oid * target ,
@@ -147,11 +140,11 @@ static int update_head_to_remote(
147140 const git_signature * signature ,
148141 const char * reflog_message )
149142{
150- int error = 0 ;
143+ int error = 0 , found_branch = 0 ;
151144 size_t refs_len ;
152- git_refspec dummy_spec ;
145+ git_refspec dummy_spec , * refspec ;
153146 const git_remote_head * remote_head , * * refs ;
154- struct head_info head_info ;
147+ const git_oid * remote_head_id ;
155148 git_buf remote_master_name = GIT_BUF_INIT ;
156149 git_buf branch = GIT_BUF_INIT ;
157150
@@ -163,47 +156,43 @@ static int update_head_to_remote(
163156 return setup_tracking_config (
164157 repo , "master" , GIT_REMOTE_ORIGIN , GIT_REFS_HEADS_MASTER_FILE );
165158
166- memset (& head_info , 0 , sizeof (head_info ));
167159 error = git_remote_default_branch (& branch , remote );
168160 if (error == GIT_ENOTFOUND ) {
169161 git_buf_puts (& branch , GIT_REFS_HEADS_MASTER_FILE );
170162 } else {
171- head_info . found = 1 ;
163+ found_branch = 1 ;
172164 }
173165
174166 /* Get the remote's HEAD. This is always the first ref in the list. */
175167 remote_head = refs [0 ];
176168 assert (remote_head );
177169
178- git_oid_cpy (& head_info .remote_head_oid , & remote_head -> oid );
179- head_info .repo = repo ;
180- head_info .refspec =
181- git_remote__matching_refspec (remote , git_buf_cstr (& branch ));
170+ remote_head_id = & remote_head -> oid ;
171+ refspec = git_remote__matching_refspec (remote , git_buf_cstr (& branch ));
182172
183- if (head_info . refspec == NULL ) {
173+ if (refspec == NULL ) {
184174 memset (& dummy_spec , 0 , sizeof (git_refspec ));
185- head_info . refspec = & dummy_spec ;
175+ refspec = & dummy_spec ;
186176 }
187177
188178 /* Determine the remote tracking reference name from the local master */
189179 if ((error = git_refspec_transform (
190180 & remote_master_name ,
191- head_info . refspec ,
181+ refspec ,
192182 git_buf_cstr (& branch ))) < 0 )
193183 return error ;
194184
195- if (head_info . found ) {
185+ if (found_branch ) {
196186 error = update_head_to_new_branch (
197187 repo ,
198- & head_info . remote_head_oid ,
188+ remote_head_id ,
199189 git_buf_cstr (& branch ),
200190 signature , reflog_message );
201191 } else {
202192 error = git_repository_set_head_detached (
203- repo , & head_info . remote_head_oid , signature , reflog_message );
193+ repo , remote_head_id , signature , reflog_message );
204194 }
205195
206- cleanup :
207196 git_buf_free (& remote_master_name );
208197 git_buf_free (& branch );
209198 return error ;
0 commit comments