readIndex reads the index JSON from the Git repo into a map. It returns the populated map & the Git SHA associated with the contents. If the index file is not found in the Git repo, an empty index is returned with no error. If any error occurs, a nil index and empty SHA are returned along with the e
()
| 211 | // If the index file is not found in the Git repo, an empty index is returned with no error. |
| 212 | // If any error occurs, a nil index and empty SHA are returned along with the error. |
| 213 | func (gh *Storage) readIndex() (map[string]int64, string, error) { |
| 214 | index := map[string]int64{} |
| 215 | |
| 216 | contents, sha, err := gh.readFile(fs.IndexName) |
| 217 | if err != nil && err != errFileNotFound { |
| 218 | return nil, "", err |
| 219 | } |
| 220 | if err == errFileNotFound { |
| 221 | return index, "", nil |
| 222 | } |
| 223 | |
| 224 | err = json.Unmarshal(contents, &index) |
| 225 | return index, sha, err |
| 226 | } |
| 227 | |
| 228 | // writeIndex marshals the index into JSON and writes the file to the Git repo. |
| 229 | // It returns any errors associated with marshaling the data or writing the file. |