本文整理汇总了C#中SparkleLib.SparkleGit类的典型用法代码示例。如果您正苦于以下问题:C# SparkleGit类的具体用法?C# SparkleGit怎么用?C# SparkleGit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparkleGit类属于SparkleLib命名空间,在下文中一共展示了SparkleGit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Start
// Clones the remote repository
public void Start()
{
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning Repository");
if (Directory.Exists (TargetFolder))
Directory.Delete (TargetFolder, true);
if (CloningStarted != null)
CloningStarted (this, new SparkleEventArgs ("CloningStarted"));
SparkleGit git = new SparkleGit (SparklePaths.SparkleTmpPath,
"clone \"" + RemoteOriginUrl + "\" " + "\"" + TargetFolder + "\"");
git.Exited += delegate {
SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ());
if (git.ExitCode != 0) {
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning failed");
if (CloningFailed != null)
CloningFailed (this, new SparkleEventArgs ("CloningFailed"));
} else {
InstallConfiguration ();
InstallExcludeRules ();
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Repository cloned");
if (CloningFinished != null)
CloningFinished (this, new SparkleEventArgs ("CloningFinished"));
}
};
git.Start ();
}
开发者ID:f2knight,项目名称:SparkleShare,代码行数:35,代码来源:SparkleFetcher.cs
示例2: Fetch
public override bool Fetch()
{
SparkleGit git = new SparkleGit (SparklePaths.SparkleTmpPath,
"clone \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
git.Start ();
git.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ());
if (git.ExitCode != 0) {
return false;
} else {
InstallConfiguration ();
InstallExcludeRules ();
return true;
}
}
开发者ID:TriggerHappy,项目名称:SparkleShare,代码行数:18,代码来源:SparkleFetcherGit.cs
示例3: GetCurrentHash
private string GetCurrentHash()
{
// Remove stale rebase-apply files because it
// makes the method return the wrong hashes.
string rebase_apply_file = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply");
if (File.Exists (rebase_apply_file))
File.Delete (rebase_apply_file);
SparkleGit git = new SparkleGit (LocalPath, "log -1 --format=%H");
git.Start ();
git.WaitForExit ();
string output = git.StandardOutput.ReadToEnd ();
string hash = output.Trim ();
return hash;
}
开发者ID:f2knight,项目名称:SparkleShare,代码行数:17,代码来源:SparkleRepo.cs
示例4: GetUserEmail
private string GetUserEmail()
{
SparkleGit git = new SparkleGit (LocalPath, "config --get user.email");
git.Start ();
git.WaitForExit ();
string output = git.StandardOutput.ReadToEnd ();
string user_email = output.Trim ();
return user_email;
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:11,代码来源:SparkleRepo.cs
示例5: GetCurrentHash
private string GetCurrentHash()
{
SparkleGit git = new SparkleGit (LocalPath, "log -1 --format=%H");
git.Start ();
git.WaitForExit ();
string output = git.StandardOutput.ReadToEnd ();
string hash = output.Trim ();
return hash;
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:11,代码来源:SparkleRepo.cs
示例6: CollectGarbage
// Removes unneeded objects
private void CollectGarbage()
{
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Collecting garbage...");
SparkleGit git = new SparkleGit (LocalPath, "gc");
git.Start ();
git.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Garbage collected.");
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:11,代码来源:SparkleRepo.cs
示例7: Add
// Stages the made changes
private void Add()
{
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");
SparkleGit git = new SparkleGit (LocalPath, "add --all");
git.Start ();
git.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");
SparkleEventArgs args = new SparkleEventArgs ("Added");
if (Added != null)
Added (this, args);
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:15,代码来源:SparkleRepo.cs
示例8: Push
// Pushes the changes to the remote repo
public void Push()
{
_IsSyncing = true;
_IsPushing = true;
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
SparkleGit git = new SparkleGit (LocalPath, "push origin master");
SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");
if (PushingStarted != null)
PushingStarted (this, args);
git.Exited += delegate {
_IsSyncing = false;
_IsPushing = false;
if (git.ExitCode != 0) {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing failed.");
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
".git", "has_unsynced_changes");
if (!File.Exists (unsynced_file_path))
File.Create (unsynced_file_path);
_HasUnsyncedChanges = true;
args = new SparkleEventArgs ("PushingFailed");
if (PushingFailed != null)
PushingFailed (this, args);
FetchRebaseAndPush ();
} else {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
args = new SparkleEventArgs ("PushingFinished");
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
".git", "has_unsynced_changes");
if (File.Exists (unsynced_file_path))
File.Delete (unsynced_file_path);
_HasUnsyncedChanges = false;
if (PushingFinished != null)
PushingFinished (this, args);
if (Listener.Client.IsConnected) {
Listener.Announce (_CurrentHash);
} else {
AnnounceQueue++;
SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Could not deliver notification, added it to the queue");
}
}
};
git.Start ();
git.WaitForExit ();
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:63,代码来源:SparkleRepo.cs
示例9: Fetch
// Fetches changes from the remote repository
public void Fetch()
{
_IsSyncing = true;
_IsFetching = true;
RemoteTimer.Stop ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
SparkleEventArgs args = new SparkleEventArgs ("FetchingStarted");
if (FetchingStarted != null)
FetchingStarted (this, args);
git.Exited += delegate {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
_IsSyncing = false;
_IsFetching = false;
_CurrentHash = GetCurrentHash ();
if (git.ExitCode != 0) {
_ServerOnline = false;
args = new SparkleEventArgs ("FetchingFailed");
if (FetchingFailed != null)
FetchingFailed (this, args);
} else {
_ServerOnline = true;
args = new SparkleEventArgs ("FetchingFinished");
if (FetchingFinished != null)
FetchingFinished (this, args);
}
RemoteTimer.Start ();
};
git.Start ();
git.WaitForExit ();
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:45,代码来源:SparkleRepo.cs
示例10: Commit
// Commits the made changes
private void Commit(string message)
{
if (!AnyDifferences)
return;
SparkleGit git = new SparkleGit (LocalPath, "commit -m \"" + message + "\"");
git.Start ();
git.WaitForExit ();
SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message);
// Collect garbage pseudo-randomly. Turn off for
// now: too resource heavy.
// if (DateTime.Now.Second % 10 == 0)
// CollectGarbage ();
}
开发者ID:ktze,项目名称:SparkleShare,代码行数:17,代码来源:SparkleRepoGit.cs
示例11: SyncUp
public override bool SyncUp()
{
Add ();
string message = FormatCommitMessage ();
Commit (message);
SparkleGit git = new SparkleGit (LocalPath, "push origin master");
git.Start ();
git.WaitForExit ();
if (git.ExitCode == 0)
return true;
else
return false;
}
开发者ID:ktze,项目名称:SparkleShare,代码行数:17,代码来源:SparkleRepoGit.cs
示例12: SyncDown
public override bool SyncDown()
{
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
git.Start ();
git.WaitForExit ();
if (git.ExitCode == 0) {
Rebase ();
return true;
} else {
return false;
}
}
开发者ID:ktze,项目名称:SparkleShare,代码行数:14,代码来源:SparkleRepoGit.cs
示例13: SyncUpNotes
public override void SyncUpNotes()
{
while (Status != SyncStatus.Idle) {
System.Threading.Thread.Sleep (5 * 20);
}
SparkleGit git_push = new SparkleGit (LocalPath, "push origin refs/notes/*");
git_push.Start ();
git_push.WaitForExit ();
if (git_push.ExitCode == 0) {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Notes pushed");
} else {
HasUnsyncedChanges = true;
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing notes failed, trying again later");
}
SparkleAnnouncement announcement = new SparkleAnnouncement (Identifier, SHA1 (DateTime.Now.ToString ()));
base.listener.Announce (announcement);
}
开发者ID:iainlane,项目名称:SparkleShare,代码行数:21,代码来源:SparkleRepoGit.cs
示例14: GetChangeSets
// Returns a list of the latest change sets
public override List<SparkleChangeSet> GetChangeSets(int count)
{
if (count < 1)
count = 30;
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso --show-notes=*");
Console.OutputEncoding = System.Text.Encoding.Unicode;
git_log.Start ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git_log.StandardOutput.ReadToEnd ();
git_log.WaitForExit ();
string [] lines = output.Split ("\n".ToCharArray ());
List <string> entries = new List <string> ();
int j = 0;
string entry = "", last_entry = "";
foreach (string line in lines) {
if (line.StartsWith ("commit") && j > 0) {
entries.Add (entry);
entry = "";
}
entry += line + "\n";
j++;
last_entry = entry;
}
entries.Add (last_entry);
Regex merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Merge: .+ .+\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
"*", RegexOptions.Compiled);
Regex non_merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
"*", RegexOptions.Compiled);
foreach (string log_entry in entries) {
Regex regex;
bool is_merge_commit = false;
if (log_entry.Contains ("\nMerge: ")) {
regex = merge_regex;
is_merge_commit = true;
} else {
regex = non_merge_regex;
}
Match match = regex.Match (log_entry);
if (match.Success) {
SparkleChangeSet change_set = new SparkleChangeSet ();
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.UserName = match.Groups [2].Value;
change_set.UserEmail = match.Groups [3].Value;
change_set.IsMerge = is_merge_commit;
change_set.SupportsNotes = true;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
int.Parse (match.Groups [9].Value));
string time_zone = match.Groups [10].Value;
int our_offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
int their_offset = int.Parse (time_zone.Substring (0, 3));
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
foreach (string entry_line in entry_lines) {
if (entry_line.StartsWith (":")) {
string change_type = entry_line [37].ToString ();
string file_path = entry_line.Substring (39);
string to_file_path;
if (change_type.Equals ("A")) {
change_set.Added.Add (file_path);
} else if (change_type.Equals ("M")) {
change_set.Edited.Add (file_path);
} else if (change_type.Equals ("D")) {
change_set.Deleted.Add (file_path);
//.........这里部分代码省略.........
开发者ID:iainlane,项目名称:SparkleShare,代码行数:101,代码来源:SparkleRepoGit.cs
示例15: AddNote
public override void AddNote(string revision, string note)
{
string url = SparkleConfig.DefaultConfig.GetUrlForFolder (Name);
if (url.StartsWith ("git") || url.StartsWith ("http"))
return;
int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
// Create the note in one line for easier merging
note = "<note>" +
" <user>" +
" <name>" + SparkleConfig.DefaultConfig.UserName + "</name>" +
" <email>" + SparkleConfig.DefaultConfig.UserEmail + "</email>" +
" </user>" +
" <timestamp>" + timestamp + "</timestamp>" +
" <body>" + note + "</body>" +
"</note>";
string note_namespace = SHA1 (timestamp.ToString () + note);
SparkleGit git_notes = new SparkleGit (LocalPath,
"notes --ref=" + note_namespace + " append -m \"" + note + "\" " + revision);
git_notes.Start ();
git_notes.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Added note to " + revision);
SyncUpNotes ();
}
开发者ID:iainlane,项目名称:SparkleShare,代码行数:28,代码来源:SparkleRepoGit.cs
示例16: ResolveConflict
private void ResolveConflict()
{
// This is al list of conflict status codes that Git uses, their
// meaning, and how SparkleShare should handle them.
//
// DD unmerged, both deleted -> Do nothing
// AU unmerged, added by us -> Use theirs, save ours as a timestamped copy
// UD unmerged, deleted by them -> Use ours
// UA unmerged, added by them -> Use theirs, save ours as a timestamped copy
// DU unmerged, deleted by us -> Use theirs
// AA unmerged, both added -> Use theirs, save ours as a timestamped copy
// UU unmerged, both modified -> Use theirs, save ours as a timestamped copy
// ?? unmerged, new files -> Stage the new files
//
// Note that a rebase merge works by replaying each commit from the working branch on
// top of the upstream branch. Because of this, when a merge conflict happens the
// side reported as 'ours' is the so-far rebased series, starting with upstream,
// and 'theirs' is the working branch. In other words, the sides are swapped.
//
// So: 'ours' means the 'server's version' and 'theirs' means the 'local version'
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
git_status.Start ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git_status.StandardOutput.ReadToEnd ().TrimEnd ();
git_status.WaitForExit ();
string [] lines = output.Split ("\n".ToCharArray ());
foreach (string line in lines) {
string conflicting_path = line.Substring (3);
conflicting_path = conflicting_path.Trim ("\"".ToCharArray ());
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict type: " + line);
// Both the local and server version have been modified
if (line.StartsWith ("UU") || line.StartsWith ("AA") ||
line.StartsWith ("AU") || line.StartsWith ("UA")) {
// Recover local version
SparkleGit git_theirs = new SparkleGit (LocalPath,
"checkout --theirs \"" + conflicting_path + "\"");
git_theirs.Start ();
git_theirs.WaitForExit ();
// Append a timestamp to local version.
// Windows doesn't allow colons in the file name, so
// we use "h" between the hours and minutes instead.
string timestamp = DateTime.Now.ToString ("HH\\hmm MMM d");
string their_path = conflicting_path + " (" + SparkleConfig.DefaultConfig.User.Name + ", " + timestamp + ")";
string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path);
string abs_their_path = Path.Combine (LocalPath, their_path);
File.Move (abs_conflicting_path, abs_their_path);
// Recover server version
SparkleGit git_ours = new SparkleGit (LocalPath,
"checkout --ours \"" + conflicting_path + "\"");
git_ours.Start ();
git_ours.WaitForExit ();
Add ();
SparkleGit git_rebase_continue = new SparkleGit (LocalPath, "rebase --continue");
git_rebase_continue.Start ();
git_rebase_continue.WaitForExit ();
}
// The local version has been modified, but the server version was removed
if (line.StartsWith ("DU")) {
// The modified local version is already in the
// checkout, so it just needs to be added.
//
// We need to specifically mention the file, so
// we can't reuse the Add () method
SparkleGit git_add = new SparkleGit (LocalPath,
"add \"" + conflicting_path + "\"");
git_add.Start ();
git_add.WaitForExit ();
SparkleGit git_rebase_continue = new SparkleGit (LocalPath, "rebase --continue");
git_rebase_continue.Start ();
git_rebase_continue.WaitForExit ();
}
// The server version has been modified, but the local version was removed
if (line.StartsWith ("UD")) {
// We can just skip here, the server version is
// already in the checkout
SparkleGit git_rebase_skip = new SparkleGit (LocalPath, "rebase --skip");
git_rebase_skip.Start ();
git_rebase_skip.WaitForExit ();
}
// New local files
if (line.StartsWith ("??")) {
//.........这里部分代码省略.........
开发者ID:shilga,项目名称:SparkleShare,代码行数:101,代码来源:SparkleRepoGit.cs
示例17: Commit
// Commits the made changes
public void Commit(string message)
{
if (!AnyDifferences)
return;
SparkleGit git = new SparkleGit (LocalPath, "commit -m '" + message + "'");
git.Start ();
git.WaitForExit ();
_CurrentHash = GetCurrentHash ();
SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message + " (" + _CurrentHash + ")");
SparkleEventArgs args = new SparkleEventArgs ("Commited") {
Message = message
};
if (Commited != null)
Commited (this, args);
// Collect garbage pseudo-randomly
if (DateTime.Now.Second % 10 == 0)
CollectGarbage ();
}
开发者ID:derflocki,项目名称:SparkleShare,代码行数:24,代码来源:SparkleRepo.cs
示例18: CheckForRemoteChanges
public override bool CheckForRemoteChanges()
{
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes...");
SparkleGit git = new SparkleGit (LocalPath, "ls-remote origin master");
git.Start ();
git.WaitForExit ();
if (git.ExitCode != 0)
return false;
string remote_revision = git.StandardOutput.ReadToEnd ().TrimEnd ();
if (!remote_revision.StartsWith (CurrentRevision)) {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_revision + ")");
return true;
} else {
return false;
}
}
开发者ID:shilga,项目名称:SparkleShare,代码行数:21,代码来源:SparkleRepoGit.cs
示例19: GetCommits
// Returns a list of latest commits
// TODO: Method needs to be made a lot faster
public List<SparkleCommit> GetCommits(int count)
{
if (count < 1)
count = 30;
List <SparkleCommit> commits = new List <SparkleCommit> ();
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso");
Console.OutputEncoding = System.Text.Encoding.Unicode;
git_log.Start ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git_log.StandardOutput.ReadToEnd ();
git_log.WaitForExit ();
string [] lines = output.Split ("\n".ToCharArray ());
List <string> entries = new List <string> ();
int j = 0;
string entry = "", last_entry = "";
foreach (string line in lines) {
if (line.StartsWith ("commit") && j > 0) {
entries.Add (entry);
entry = "";
}
entry += line + "\n";
j++;
last_entry = entry;
}
entries.Add (last_entry);
// TODO: Need to optimise for speed
foreach (string log_entry in entries) {
Regex regex;
bool is_merge_commit = false;
if (log_entry.Contains ("\nMerge: ")) {
regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Merge: .+ .+\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
"*");
is_merge_commit = true;
} else {
regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
"*");
}
Match match = regex.Match (log_entry);
if (match.Success) {
SparkleCommit commit = new SparkleCommit ();
commit.Hash = match.Groups [1].Value;
commit.UserName = match.Groups [2].Value;
commit.UserEmail = match.Groups [3].Value;
commit.IsMerge = is_merge_commit;
commit.DateTime = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
int.Parse (match.Groups [9].Value));
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
foreach (string entry_line in entry_lines) {
if (entry_line.StartsWith (":")) {
string change_type = entry_line [37].ToString ();
string file_path = entry_line.Substring (39);
string to_file_path;
if (change_type.Equals ("A")) {
commit.Added.Add (file_path);
} else if (change_type.Equals ("M")) {
commit.Edited.Add (file_path);
} else if (change_type.Equals ("D")) {
commit.Deleted.Add (file_path);
} else if (change_type.Equals ("R")) {
int tab_pos = entry_line.LastIndexOf ("\t");
file_path = entry_line.Substring (42, tab_pos - 42);
to_file_path = entry_line.Substring (tab_pos + 1);
commit.MovedFrom.Add (file_path);
commit.MovedTo.Add (to_file_path);
}
}
}
//.........这里部分代码省略.........
开发者ID:derflocki,项目名称:SparkleShare,代码行数:101,代码来源:SparkleRepo.cs
示例20: GetChangeSets
// Returns a list of the latest change sets
public override List<SparkleChangeSet> GetChangeSets(int count)
{
if (count < 1)
count = 30;
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
// Console.InputEncoding = System.Text.Encoding.Unicode;
Console.OutputEncoding = System.Text.Encoding.Unicode;
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso");
git_log.Start ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git_log.StandardOutput.ReadToEnd ();
git_log.WaitForExit ();
string [] lines = output.Split ("\n".ToCharArray ());
List <string> entries = new List <string> ();
int line_number = 0;
bool first_pass = true;
string entry = "", last_entry = "";
foreach (string line in lines) {
if (line.StartsWith ("commit") && !first_pass) {
entries.Add (entry);
entry = "";
line_number = 0;
} else {
first_pass = false;
}
// Only parse 250 files to prevent memory issues
if (line_number < 254) {
entry += line + "\n";
line_number++;
}
last_entry = entry;
}
entries.Add (last_entry);
Regex merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Merge: .+ .+\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
"*", RegexOptions.Compiled);
Regex non_merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
"Author: (.+) <(.+)>\n" +
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
"*", RegexOptions.Compiled);
foreach (string log_entry in entries) {
Regex regex;
bool is_merge_commit = false;
if (log_entry.Contains ("\nMerge: ")) {
regex = merge_regex;
is_merge_commit = true;
} else {
regex = non_merge_regex;
}
Match match = regex.Match (log_entry);
if (match.Success) {
SparkleChangeSet change_set = new SparkleChangeSet ();
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.User.Name = match.Groups [2].Value;
change_set.User.Email = match.Groups [3].Value;
change_set.IsMagical = is_merge_commit;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
int.Parse (match.Groups [9].Value));
string time_zone = match.Groups [10].Value;
int our_offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
int their_offset = int.Parse (time_zone.Substring (0, 3));
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
foreach (string entry_line in entry_lines) {
if (entry_line.StartsWith (":")) {
string change_type = entry_line [37].ToString ();
string file_path = entry_line.Substring (39);
string to_file_path;
//.........这里部分代码省略.........
开发者ID:shilga,项目名称:SparkleShare,代码行数:101,代码来源:SparkleRepoGit.cs
注:本文中的SparkleLib.SparkleGit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论