|
@@ -4,17 +4,14 @@ import java.io.File;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayDeque;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.SortedSet;
|
|
import java.util.SortedSet;
|
|
|
import java.util.TreeSet;
|
|
import java.util.TreeSet;
|
|
|
-import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
import info.knacki.pass.git.GitSha1;
|
|
import info.knacki.pass.git.GitSha1;
|
|
|
|
|
|
|
|
public class GitCommit implements GitPackable {
|
|
public class GitCommit implements GitPackable {
|
|
|
- private final static Logger log = Logger.getLogger(GitCommit.class.getName());
|
|
|
|
|
-
|
|
|
|
|
private String fHash;
|
|
private String fHash;
|
|
|
private byte[] fTreeHash;
|
|
private byte[] fTreeHash;
|
|
|
private GitObject.GitTree fTree;
|
|
private GitObject.GitTree fTree;
|
|
@@ -22,6 +19,7 @@ public class GitCommit implements GitPackable {
|
|
|
private String fAuthor;
|
|
private String fAuthor;
|
|
|
private String fCommitter;
|
|
private String fCommitter;
|
|
|
private String fMessage;
|
|
private String fMessage;
|
|
|
|
|
+ private Date fTime;
|
|
|
|
|
|
|
|
public GitCommit(String hash, String sha1Content) {
|
|
public GitCommit(String hash, String sha1Content) {
|
|
|
int pos = sha1Content.indexOf('\0');
|
|
int pos = sha1Content.indexOf('\0');
|
|
@@ -41,7 +39,7 @@ public class GitCommit implements GitPackable {
|
|
|
else if (line.startsWith("author"))
|
|
else if (line.startsWith("author"))
|
|
|
fAuthor = Util.RemoveHead(line);
|
|
fAuthor = Util.RemoveHead(line);
|
|
|
else if (line.startsWith("committer"))
|
|
else if (line.startsWith("committer"))
|
|
|
- fCommitter = Util.RemoveHead(line);
|
|
|
|
|
|
|
+ fCommitter = Util.RemoveHead(line); // FIXME time
|
|
|
}
|
|
}
|
|
|
fHash = hash;
|
|
fHash = hash;
|
|
|
fMessage = message == null ? "" : message.toString();
|
|
fMessage = message == null ? "" : message.toString();
|
|
@@ -54,6 +52,7 @@ public class GitCommit implements GitPackable {
|
|
|
fParent = parent.fHash;
|
|
fParent = parent.fHash;
|
|
|
fMessage = msg;
|
|
fMessage = msg;
|
|
|
fHash = null;
|
|
fHash = null;
|
|
|
|
|
+ fTime = new Date();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String GetMessage() {
|
|
public String GetMessage() {
|
|
@@ -82,6 +81,10 @@ public class GitCommit implements GitPackable {
|
|
|
return fParent;
|
|
return fParent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Date GetTime() {
|
|
|
|
|
+ return fTime;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public eType GetPackableType() {
|
|
public eType GetPackableType() {
|
|
|
return eType.eType_Commit;
|
|
return eType.eType_Commit;
|
|
@@ -89,8 +92,7 @@ public class GitCommit implements GitPackable {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public byte[] GetPack() {
|
|
public byte[] GetPack() {
|
|
|
- Date date = new Date();
|
|
|
|
|
- String dateStr = (date.getTime() / 1000) +" " +(new SimpleDateFormat("Z", Locale.US).format(date));
|
|
|
|
|
|
|
+ String dateStr = (fTime.getTime() / 1000) +" " +(new SimpleDateFormat("Z", Locale.US).format(fTime));
|
|
|
String data = "tree " +GitSha1.BytesToString(fTree.GetHash()) +"\n" +
|
|
String data = "tree " +GitSha1.BytesToString(fTree.GetHash()) +"\n" +
|
|
|
"parent " +GetParent() +"\n" +
|
|
"parent " +GetParent() +"\n" +
|
|
|
"author " +fAuthor +" " +dateStr +"\n" +
|
|
"author " +fAuthor +" " +dateStr +"\n" +
|
|
@@ -105,7 +107,7 @@ public class GitCommit implements GitPackable {
|
|
|
private final GitCommit fParent;
|
|
private final GitCommit fParent;
|
|
|
private final GitObject.GitTree fTree;
|
|
private final GitObject.GitTree fTree;
|
|
|
private final ArrayDeque<File> fFilesToPush = new ArrayDeque<>();
|
|
private final ArrayDeque<File> fFilesToPush = new ArrayDeque<>();
|
|
|
- private final HashMap<String, GitPackable> fToPack = new HashMap<>();
|
|
|
|
|
|
|
+ private final Set<String> fToPack = new TreeSet<>();
|
|
|
|
|
|
|
|
public Builder(GitCommit parent, String author, String authorEmail, String message) {
|
|
public Builder(GitCommit parent, String author, String authorEmail, String message) {
|
|
|
String aut = author +" <" +authorEmail +">";
|
|
String aut = author +" <" +authorEmail +">";
|
|
@@ -116,6 +118,10 @@ public class GitCommit implements GitPackable {
|
|
|
|
|
|
|
|
public GitCommit Build() {
|
|
public GitCommit Build() {
|
|
|
co.fTree = fTree;
|
|
co.fTree = fTree;
|
|
|
|
|
+ for (GitPackable go: PreparePack()) {
|
|
|
|
|
+ if (go instanceof GitObject.GitTree)
|
|
|
|
|
+ ((GitObject.GitTree) go).GetHash();
|
|
|
|
|
+ }
|
|
|
return co;
|
|
return co;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -123,9 +129,9 @@ public class GitCommit implements GitPackable {
|
|
|
fFilesToPush.add(f);
|
|
fFilesToPush.add(f);
|
|
|
GitObject obj = fTree.AddItem(relativeFilename, f);
|
|
GitObject obj = fTree.AddItem(relativeFilename, f);
|
|
|
do {
|
|
do {
|
|
|
- fToPack.put(obj.GetGitPath(), obj);
|
|
|
|
|
|
|
+ fToPack.add(obj.GetGitPath());
|
|
|
obj = obj.GetParent();
|
|
obj = obj.GetParent();
|
|
|
- } while (obj != null);
|
|
|
|
|
|
|
+ } while (obj != null && !"".equals(obj.fName));
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -134,15 +140,18 @@ public class GitCommit implements GitPackable {
|
|
|
if (obj != null) {
|
|
if (obj != null) {
|
|
|
GitObject.GitTree parent = obj.GetParent();
|
|
GitObject.GitTree parent = obj.GetParent();
|
|
|
if (parent != null)
|
|
if (parent != null)
|
|
|
- parent.Remove(obj.GetHash());
|
|
|
|
|
|
|
+ parent.Remove(obj.fName);
|
|
|
}
|
|
}
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public SortedSet<GitPackable> PreparePack() {
|
|
public SortedSet<GitPackable> PreparePack() {
|
|
|
TreeSet packs = new TreeSet<GitPackable>(new GitPackableUtil.Comparator());
|
|
TreeSet packs = new TreeSet<GitPackable>(new GitPackableUtil.Comparator());
|
|
|
- packs.add(Build());
|
|
|
|
|
- packs.addAll(fToPack.values());
|
|
|
|
|
|
|
+ packs.add(co);
|
|
|
|
|
+ for (String i: fToPack)
|
|
|
|
|
+ packs.add(fTree.GetObjectFullPath(i));
|
|
|
|
|
+ if (!fToPack.isEmpty())
|
|
|
|
|
+ packs.add(fTree);
|
|
|
return packs;
|
|
return packs;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|