소스 검색

Handle Windows line endings when reading binary files

Without this change, '.git\HEAD' files, for examples, are sometime
read incorrectly resulting in the current branch to be reset to
"master" when running a "repo init -b xxx" on an already initialized
repository.

Change-Id: I48c7ef85ff81626edf156914329a560e14252f2a
Renaud Paquay 9 년 전
부모
커밋
2a4be94878
2개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      git_refs.py
  2. 3 3
      project.py

+ 1 - 1
git_refs.py

@@ -139,7 +139,7 @@ class GitRefs(object):
 
   def _ReadLoose1(self, path, name):
     try:
-      fd = open(path, 'rb')
+      fd = open(path)
     except IOError:
       return
 

+ 3 - 3
project.py

@@ -1258,7 +1258,7 @@ class Project(object):
     if is_new:
       alt = os.path.join(self.gitdir, 'objects/info/alternates')
       try:
-        fd = open(alt, 'rb')
+        fd = open(alt)
         try:
           alt_dir = fd.readline().rstrip()
         finally:
@@ -2691,11 +2691,11 @@ class Project(object):
       else:
         path = os.path.join(self._project.worktree, '.git', HEAD)
       try:
-        fd = open(path, 'rb')
+        fd = open(path)
       except IOError as e:
         raise NoManifestException(path, str(e))
       try:
-        line = fd.read()
+        line = fd.readline()
       finally:
         fd.close()
       try: