File tree Expand file tree Collapse file tree 3 files changed +53
-54
lines changed Expand file tree Collapse file tree 3 files changed +53
-54
lines changed Original file line number Diff line number Diff line change 5
5
#include "abspath.h"
6
6
#include "environment.h"
7
7
#include "gettext.h"
8
- #include "hex.h"
9
8
#include "repository.h"
10
9
#include "strbuf.h"
11
10
#include "string-list.h"
@@ -647,58 +646,6 @@ void strbuf_git_common_path(struct strbuf *sb,
647
646
va_end (args );
648
647
}
649
648
650
- int validate_headref (const char * path )
651
- {
652
- struct stat st ;
653
- char buffer [256 ];
654
- const char * refname ;
655
- struct object_id oid ;
656
- int fd ;
657
- ssize_t len ;
658
-
659
- if (lstat (path , & st ) < 0 )
660
- return -1 ;
661
-
662
- /* Make sure it is a "refs/.." symlink */
663
- if (S_ISLNK (st .st_mode )) {
664
- len = readlink (path , buffer , sizeof (buffer )- 1 );
665
- if (len >= 5 && !memcmp ("refs/" , buffer , 5 ))
666
- return 0 ;
667
- return -1 ;
668
- }
669
-
670
- /*
671
- * Anything else, just open it and try to see if it is a symbolic ref.
672
- */
673
- fd = open (path , O_RDONLY );
674
- if (fd < 0 )
675
- return -1 ;
676
- len = read_in_full (fd , buffer , sizeof (buffer )- 1 );
677
- close (fd );
678
-
679
- if (len < 0 )
680
- return -1 ;
681
- buffer [len ] = '\0' ;
682
-
683
- /*
684
- * Is it a symbolic ref?
685
- */
686
- if (skip_prefix (buffer , "ref:" , & refname )) {
687
- while (isspace (* refname ))
688
- refname ++ ;
689
- if (starts_with (refname , "refs/" ))
690
- return 0 ;
691
- }
692
-
693
- /*
694
- * Is this a detached HEAD?
695
- */
696
- if (get_oid_hex_any (buffer , & oid ) != GIT_HASH_UNKNOWN )
697
- return 0 ;
698
-
699
- return -1 ;
700
- }
701
-
702
649
static struct passwd * getpw_str (const char * username , size_t len )
703
650
{
704
651
struct passwd * pw ;
Original file line number Diff line number Diff line change @@ -173,7 +173,6 @@ const char *git_path_fetch_head(struct repository *r);
173
173
const char * git_path_shallow (struct repository * r );
174
174
175
175
int ends_with_path_components (const char * path , const char * components );
176
- int validate_headref (const char * ref );
177
176
178
177
int calc_shared_perm (int mode );
179
178
int adjust_shared_perm (const char * path );
Original file line number Diff line number Diff line change 4
4
#include "environment.h"
5
5
#include "exec-cmd.h"
6
6
#include "gettext.h"
7
+ #include "hex.h"
7
8
#include "object-name.h"
8
9
#include "refs.h"
9
10
#include "repository.h"
@@ -341,6 +342,58 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
341
342
return ret ;
342
343
}
343
344
345
+ static int validate_headref (const char * path )
346
+ {
347
+ struct stat st ;
348
+ char buffer [256 ];
349
+ const char * refname ;
350
+ struct object_id oid ;
351
+ int fd ;
352
+ ssize_t len ;
353
+
354
+ if (lstat (path , & st ) < 0 )
355
+ return -1 ;
356
+
357
+ /* Make sure it is a "refs/.." symlink */
358
+ if (S_ISLNK (st .st_mode )) {
359
+ len = readlink (path , buffer , sizeof (buffer )- 1 );
360
+ if (len >= 5 && !memcmp ("refs/" , buffer , 5 ))
361
+ return 0 ;
362
+ return -1 ;
363
+ }
364
+
365
+ /*
366
+ * Anything else, just open it and try to see if it is a symbolic ref.
367
+ */
368
+ fd = open (path , O_RDONLY );
369
+ if (fd < 0 )
370
+ return -1 ;
371
+ len = read_in_full (fd , buffer , sizeof (buffer )- 1 );
372
+ close (fd );
373
+
374
+ if (len < 0 )
375
+ return -1 ;
376
+ buffer [len ] = '\0' ;
377
+
378
+ /*
379
+ * Is it a symbolic ref?
380
+ */
381
+ if (skip_prefix (buffer , "ref:" , & refname )) {
382
+ while (isspace (* refname ))
383
+ refname ++ ;
384
+ if (starts_with (refname , "refs/" ))
385
+ return 0 ;
386
+ }
387
+
388
+ /*
389
+ * Is this a detached HEAD?
390
+ */
391
+ if (get_oid_hex_any (buffer , & oid ) != GIT_HASH_UNKNOWN )
392
+ return 0 ;
393
+
394
+ return -1 ;
395
+ }
396
+
344
397
/*
345
398
* Test if it looks like we're at a git directory.
346
399
* We want to see:
You can’t perform that action at this time.
0 commit comments