@@ -309,53 +309,6 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
309309 return ref ;
310310}
311311
312- int create_symref (const char * ref_target , const char * refs_heads_master )
313- {
314- const char * lockpath ;
315- char ref [1000 ];
316- int fd , len , written ;
317- const char * git_HEAD = git_path ("%s" , ref_target );
318-
319- #ifndef NO_SYMLINK_HEAD
320- if (prefer_symlink_refs ) {
321- unlink (git_HEAD );
322- if (!symlink (refs_heads_master , git_HEAD ))
323- return 0 ;
324- fprintf (stderr , "no symlink - falling back to symbolic ref\n" );
325- }
326- #endif
327-
328- len = snprintf (ref , sizeof (ref ), "ref: %s\n" , refs_heads_master );
329- if (sizeof (ref ) <= len ) {
330- error ("refname too long: %s" , refs_heads_master );
331- return -1 ;
332- }
333- lockpath = mkpath ("%s.lock" , git_HEAD );
334- fd = open (lockpath , O_CREAT | O_EXCL | O_WRONLY , 0666 );
335- if (fd < 0 ) {
336- error ("Unable to open %s for writing" , lockpath );
337- return -5 ;
338- }
339- written = write_in_full (fd , ref , len );
340- close (fd );
341- if (written != len ) {
342- unlink (lockpath );
343- error ("Unable to write to %s" , lockpath );
344- return -2 ;
345- }
346- if (rename (lockpath , git_HEAD ) < 0 ) {
347- unlink (lockpath );
348- error ("Unable to create %s" , git_HEAD );
349- return -3 ;
350- }
351- if (adjust_shared_perm (git_HEAD )) {
352- unlink (lockpath );
353- error ("Unable to fix permissions on %s" , lockpath );
354- return -4 ;
355- }
356- return 0 ;
357- }
358-
359312int read_ref (const char * ref , unsigned char * sha1 )
360313{
361314 if (resolve_ref (ref , sha1 , 1 , NULL ))
@@ -1033,6 +986,53 @@ int write_ref_sha1(struct ref_lock *lock,
1033986 return 0 ;
1034987}
1035988
989+ int create_symref (const char * ref_target , const char * refs_heads_master )
990+ {
991+ const char * lockpath ;
992+ char ref [1000 ];
993+ int fd , len , written ;
994+ const char * git_HEAD = git_path ("%s" , ref_target );
995+
996+ #ifndef NO_SYMLINK_HEAD
997+ if (prefer_symlink_refs ) {
998+ unlink (git_HEAD );
999+ if (!symlink (refs_heads_master , git_HEAD ))
1000+ return 0 ;
1001+ fprintf (stderr , "no symlink - falling back to symbolic ref\n" );
1002+ }
1003+ #endif
1004+
1005+ len = snprintf (ref , sizeof (ref ), "ref: %s\n" , refs_heads_master );
1006+ if (sizeof (ref ) <= len ) {
1007+ error ("refname too long: %s" , refs_heads_master );
1008+ return -1 ;
1009+ }
1010+ lockpath = mkpath ("%s.lock" , git_HEAD );
1011+ fd = open (lockpath , O_CREAT | O_EXCL | O_WRONLY , 0666 );
1012+ if (fd < 0 ) {
1013+ error ("Unable to open %s for writing" , lockpath );
1014+ return -5 ;
1015+ }
1016+ written = write_in_full (fd , ref , len );
1017+ close (fd );
1018+ if (written != len ) {
1019+ unlink (lockpath );
1020+ error ("Unable to write to %s" , lockpath );
1021+ return -2 ;
1022+ }
1023+ if (rename (lockpath , git_HEAD ) < 0 ) {
1024+ unlink (lockpath );
1025+ error ("Unable to create %s" , git_HEAD );
1026+ return -3 ;
1027+ }
1028+ if (adjust_shared_perm (git_HEAD )) {
1029+ unlink (lockpath );
1030+ error ("Unable to fix permissions on %s" , lockpath );
1031+ return -4 ;
1032+ }
1033+ return 0 ;
1034+ }
1035+
10361036static char * ref_msg (const char * line , const char * endp )
10371037{
10381038 const char * ep ;
0 commit comments