James Moger
2016-01-25 252dc07d7f85cc344b5919bb7c6166ef84b2102e
commit | author | age
319342 1 /*
JM 2  * Copyright 2013 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.utils;
17
18 import java.io.IOException;
19
20 import org.eclipse.jgit.diff.DiffEntry;
21 import org.eclipse.jgit.diff.DiffFormatter;
22 import org.eclipse.jgit.diff.RawText;
46f33f 23 import org.eclipse.jgit.lib.Repository;
319342 24 import org.eclipse.jgit.util.io.NullOutputStream;
JM 25
26 import com.gitblit.models.PathModel.PathChangeModel;
27 import com.gitblit.utils.DiffUtils.DiffStat;
28
29 /**
30  * Calculates a DiffStat.
31  *
32  * @author James Moger
33  *
34  */
35 public class DiffStatFormatter extends DiffFormatter {
36
37     private final DiffStat diffStat;
38
39     private PathChangeModel path;
40
46f33f 41     public DiffStatFormatter(String commitId, Repository repository) {
319342 42         super(NullOutputStream.INSTANCE);
46f33f 43         diffStat = new DiffStat(commitId, repository);
319342 44     }
JM 45
46     @Override
47     public void format(DiffEntry entry) throws IOException {
48         path = diffStat.addPath(entry);
49         super.format(entry);
50     }
51
52     @Override
53     protected void writeLine(final char prefix, final RawText text, final int cur)
54             throws IOException {
55         path.update(prefix);
56     }
57
58     public DiffStat getDiffStat() {
59         return diffStat;
60     }
61 }