Procházet zdrojové kódy

Adapt methods and functions

Brendan Abolivier před 6 roky
rodič
revize
50c5e82899
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 změnil soubory, kde provedl 22 přidání a 12 odebrání
  1. 22
    12
      src/git/git.go

+ 22
- 12
src/git/git.go Zobrazit soubor

@@ -138,9 +138,12 @@ func (r *Repository) Log(fromHash string) (object.CommitIter, error) {
138 138
 	})
139 139
 }
140 140
 
141
-func (r *Repository) LineCountsDeltasIgnoreManagerCommits(
141
+func (r *Repository) GetModifiedAndRemovedFiles(
142 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 147
 	// We expect "from" to be the oldest commit, and "to" to be the most recent
145 148
 	// one. Because Log() works the other way (in anti-chronological order),
146 149
 	// we call it with "to" and not "from" because, that way, we'll go from "to"
@@ -150,7 +153,6 @@ func (r *Repository) LineCountsDeltasIgnoreManagerCommits(
150 153
 		return
151 154
 	}
152 155
 
153
-	lineCountsDeltas = make(map[string]int)
154 156
 	err = iter.ForEach(func(commit *object.Commit) error {
155 157
 		if commit.Author.Email == r.cfg.CommitsAuthor.Email {
156 158
 			return nil
@@ -166,9 +168,16 @@ func (r *Repository) LineCountsDeltasIgnoreManagerCommits(
166 168
 		}
167 169
 
168 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 183
 		return nil
@@ -177,29 +186,30 @@ func (r *Repository) LineCountsDeltasIgnoreManagerCommits(
177 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 192
 	tree, err := commit.Tree()
182 193
 	if err != nil {
183 194
 		return nil, err
184 195
 	}
185 196
 
186
-	lineCounts := make(map[string]int)
197
+	filesContents := make(map[string][]byte)
187 198
 
188 199
 	files := tree.Files()
189 200
 
190
-	var lines []string
191 201
 	err = files.ForEach(func(file *object.File) error {
192
-		lines, err = file.Lines()
202
+		content, err = file.Contents()
193 203
 		if err != nil {
194 204
 			return err
195 205
 		}
196 206
 
197
-		lineCounts[file.Name] = len(lines)
207
+		filesContents[file.Name] = []byte(content)
198 208
 
199 209
 		return nil
200 210
 	})
201 211
 
202
-	return lineCounts, err
212
+	return filesContents, err
203 213
 }
204 214
 
205 215
 // getAuth returns the authentication structure instance needed to authenticate