Sfoglia il codice sorgente

Adapt methods and functions

Brendan Abolivier 6 anni fa
parent
commit
50c5e82899
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 ha cambiato i file con 22 aggiunte e 12 eliminazioni
  1. 22
    12
      src/git/git.go

+ 22
- 12
src/git/git.go Vedi File

138
 	})
138
 	})
139
 }
139
 }
140
 
140
 
141
-func (r *Repository) LineCountsDeltasIgnoreManagerCommits(
141
+func (r *Repository) GetModifiedAndRemovedFiles(
142
 	from *object.Commit, to *object.Commit,
142
 	from *object.Commit, to *object.Commit,
143
-) (lineCountsDeltas map[string]int, err error) {
143
+) (modified []string, removed []string, err error) {
144
+	modified = make([]string, 0)
145
+	removed = make([]string, 0)
146
+
144
 	// We expect "from" to be the oldest commit, and "to" to be the most recent
147
 	// We expect "from" to be the oldest commit, and "to" to be the most recent
145
 	// one. Because Log() works the other way (in anti-chronological order),
148
 	// one. Because Log() works the other way (in anti-chronological order),
146
 	// we call it with "to" and not "from" because, that way, we'll go from "to"
149
 	// we call it with "to" and not "from" because, that way, we'll go from "to"
150
 		return
153
 		return
151
 	}
154
 	}
152
 
155
 
153
-	lineCountsDeltas = make(map[string]int)
154
 	err = iter.ForEach(func(commit *object.Commit) error {
156
 	err = iter.ForEach(func(commit *object.Commit) error {
155
 		if commit.Author.Email == r.cfg.CommitsAuthor.Email {
157
 		if commit.Author.Email == r.cfg.CommitsAuthor.Email {
156
 			return nil
158
 			return nil
166
 		}
168
 		}
167
 
169
 
168
 		for _, stat := range stats {
170
 		for _, stat := range stats {
169
-			// We're getting recent -> old additions and deletions. Because we
170
-			// want the opposite (old -> recent), we must invert the sign of both.
171
-			lineCountsDeltas[stat.Name] = stat.Deletion - stat.Addition
171
+			_, err := commit.File(stat.Name)
172
+			if err != nil && err != object.ErrFileNotFound {
173
+				return err
174
+			}
175
+
176
+			if err == object.ErrFileNotFound {
177
+				removed = append(removed, stat.Name)
178
+			} else {
179
+				modified = append(modified, stat.Name)
180
+			}
172
 		}
181
 		}
173
 
182
 
174
 		return nil
183
 		return nil
177
 	return
186
 	return
178
 }
187
 }
179
 
188
 
180
-func GetFilesLineCountsAtCommit(commit *object.Commit) (map[string]int, error) {
189
+func (r *Repository) GetFilesContentsAtCommit(commit *object.Commit) (map[string][]byte, error) {
190
+	var content string
191
+
181
 	tree, err := commit.Tree()
192
 	tree, err := commit.Tree()
182
 	if err != nil {
193
 	if err != nil {
183
 		return nil, err
194
 		return nil, err
184
 	}
195
 	}
185
 
196
 
186
-	lineCounts := make(map[string]int)
197
+	filesContents := make(map[string][]byte)
187
 
198
 
188
 	files := tree.Files()
199
 	files := tree.Files()
189
 
200
 
190
-	var lines []string
191
 	err = files.ForEach(func(file *object.File) error {
201
 	err = files.ForEach(func(file *object.File) error {
192
-		lines, err = file.Lines()
202
+		content, err = file.Contents()
193
 		if err != nil {
203
 		if err != nil {
194
 			return err
204
 			return err
195
 		}
205
 		}
196
 
206
 
197
-		lineCounts[file.Name] = len(lines)
207
+		filesContents[file.Name] = []byte(content)
198
 
208
 
199
 		return nil
209
 		return nil
200
 	})
210
 	})
201
 
211
 
202
-	return lineCounts, err
212
+	return filesContents, err
203
 }
213
 }
204
 
214
 
205
 // getAuth returns the authentication structure instance needed to authenticate
215
 // getAuth returns the authentication structure instance needed to authenticate