@@ -738,106 +738,6 @@ char *interpolate_path(const char *path, int real_home)
738738 return NULL ;
739739}
740740
741- /*
742- * First, one directory to try is determined by the following algorithm.
743- *
744- * (0) If "strict" is given, the path is used as given and no DWIM is
745- * done. Otherwise:
746- * (1) "~/path" to mean path under the running user's home directory;
747- * (2) "~user/path" to mean path under named user's home directory;
748- * (3) "relative/path" to mean cwd relative directory; or
749- * (4) "/absolute/path" to mean absolute directory.
750- *
751- * Unless "strict" is given, we check "%s/.git", "%s", "%s.git/.git", "%s.git"
752- * in this order. We select the first one that is a valid git repository, and
753- * chdir() to it. If none match, or we fail to chdir, we return NULL.
754- *
755- * If all goes well, we return the directory we used to chdir() (but
756- * before ~user is expanded), avoiding getcwd() resolving symbolic
757- * links. User relative paths are also returned as they are given,
758- * except DWIM suffixing.
759- */
760- const char * enter_repo (const char * path , unsigned flags )
761- {
762- static struct strbuf validated_path = STRBUF_INIT ;
763- static struct strbuf used_path = STRBUF_INIT ;
764-
765- if (!path )
766- return NULL ;
767-
768- if (!(flags & ENTER_REPO_STRICT )) {
769- static const char * suffix [] = {
770- "/.git" , "" , ".git/.git" , ".git" , NULL ,
771- };
772- const char * gitfile ;
773- int len = strlen (path );
774- int i ;
775- while ((1 < len ) && (path [len - 1 ] == '/' ))
776- len -- ;
777-
778- /*
779- * We can handle arbitrary-sized buffers, but this remains as a
780- * sanity check on untrusted input.
781- */
782- if (PATH_MAX <= len )
783- return NULL ;
784-
785- strbuf_reset (& used_path );
786- strbuf_reset (& validated_path );
787- strbuf_add (& used_path , path , len );
788- strbuf_add (& validated_path , path , len );
789-
790- if (used_path .buf [0 ] == '~' ) {
791- char * newpath = interpolate_path (used_path .buf , 0 );
792- if (!newpath )
793- return NULL ;
794- strbuf_attach (& used_path , newpath , strlen (newpath ),
795- strlen (newpath ));
796- }
797- for (i = 0 ; suffix [i ]; i ++ ) {
798- struct stat st ;
799- size_t baselen = used_path .len ;
800- strbuf_addstr (& used_path , suffix [i ]);
801- if (!stat (used_path .buf , & st ) &&
802- (S_ISREG (st .st_mode ) ||
803- (S_ISDIR (st .st_mode ) && is_git_directory (used_path .buf )))) {
804- strbuf_addstr (& validated_path , suffix [i ]);
805- break ;
806- }
807- strbuf_setlen (& used_path , baselen );
808- }
809- if (!suffix [i ])
810- return NULL ;
811- gitfile = read_gitfile (used_path .buf );
812- if (!(flags & ENTER_REPO_ANY_OWNER_OK ))
813- die_upon_dubious_ownership (gitfile , NULL , used_path .buf );
814- if (gitfile ) {
815- strbuf_reset (& used_path );
816- strbuf_addstr (& used_path , gitfile );
817- }
818- if (chdir (used_path .buf ))
819- return NULL ;
820- path = validated_path .buf ;
821- }
822- else {
823- const char * gitfile = read_gitfile (path );
824- if (!(flags & ENTER_REPO_ANY_OWNER_OK ))
825- die_upon_dubious_ownership (gitfile , NULL , path );
826- if (gitfile )
827- path = gitfile ;
828- if (chdir (path ))
829- return NULL ;
830- }
831-
832- if (is_git_directory ("." )) {
833- set_git_dir ("." , 0 );
834- check_repository_format (NULL );
835- return path ;
836- }
837-
838- return NULL ;
839- }
840-
841741int calc_shared_perm (struct repository * repo ,
842742 int mode )
843743{
0 commit comments