Add new backend class and a default backend. Add backend member to repo.

This commit is contained in:
Hylke Bons 2011-05-09 00:04:53 +01:00
parent 3322e46fc9
commit a29f7b32bc
7 changed files with 63 additions and 32 deletions

View file

@ -5,6 +5,7 @@ LINK = $(REF_SPARKLELIB)
SOURCES = \
Defines.cs \
SparkleBackend.cs \
SparkleCommit.cs \
SparkleEvents.cs \
SparkleFetcher.cs \

View file

@ -0,0 +1,50 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
namespace SparkleLib {
public class SparkleBackend {
public static SparkleBackend DefaultBackend;
public string Name;
public string Path;
public SparkleBackend (string name, string [] paths)
{
Name = name;
foreach (string path in paths) {
if (File.Exists (path)) {
Path = path;
break;
}
}
}
public bool IsPresent {
get {
return (Path != null);
}
}
}
}

View file

@ -25,7 +25,7 @@ namespace SparkleLib {
public SparkleGit (string path, string args) : base ()
{
EnableRaisingEvents = true;
StartInfo.FileName = SparklePaths.GitPath;
StartInfo.FileName = SparkleBackend.DefaultBackend.Path;
StartInfo.Arguments = args;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false;

View file

@ -14,43 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Diagnostics;
using System.IO;
using Mono.Unix;
namespace SparkleLib {
public static class Backend {
public static string Name = "Git";
public static string Path {
get {
string [] possible_git_paths = {"/usr/bin/git",
"/usr/local/git/bin/git",
"/usr/local/bin/git"};
foreach (string git_path in possible_git_paths)
if (File.Exists (git_path))
return git_path;
return null;
}
}
public static bool IsPresent {
get {
return (Path != null);
}
}
}
public static class SparklePaths {
public static string GitPath = Backend.Path;
public static string HomePath = new UnixUserInfo (UnixEnvironment.UserName).HomeDirectory;
public static string SparklePath = Path.Combine (HomePath ,"SparkleShare");
public static string SparkleTmpPath = Path.Combine (SparklePath, ".tmp");

View file

@ -48,6 +48,7 @@ namespace SparkleLib {
private bool has_unsynced_changes;
private bool server_online;
public readonly SparkleBackend Backend;
public readonly string Name;
public readonly string RemoteName;
public readonly string Domain;
@ -132,7 +133,7 @@ namespace SparkleLib {
public event CommitEndedUpEmptyEventHandler CommitEndedUpEmpty;
public SparkleRepo (string path)
public SparkleRepo (string path, SparkleBackend backend)
{
LocalPath = path;
Name = Path.GetFileName (LocalPath);
@ -142,6 +143,7 @@ namespace SparkleLib {
Description = GetDescription ();
UserName = GetUserName ();
UserEmail = GetUserEmail ();
Backend = backend;
this.is_syncing = false;
this.is_buffering = false;

View file

@ -476,7 +476,7 @@ namespace SparkleShare {
if (!SparkleRepo.IsRepo (folder_path))
return;
SparkleRepo repo = new SparkleRepo (folder_path);
SparkleRepo repo = new SparkleRepo (folder_path, SparkleBackend.DefaultBackend);
repo.NewCommit += delegate (SparkleCommit commit, string repository_path) {
string message = FormatMessage (commit);
@ -705,7 +705,7 @@ namespace SparkleShare {
public bool BackendIsPresent {
get {
return SparkleLib.Backend.IsPresent;
return SparkleBackend.DefaultBackend.IsPresent;
}
}

View file

@ -76,6 +76,10 @@ namespace SparkleShare {
if (show_help)
ShowHelp (p);
// Set the default backend for SparkleLib
string [] git_paths = new string [3] {"/usr/bin/git", "/usr/local/git/bin/git", "/usr/local/bin/git"};
SparkleBackend.DefaultBackend = new SparkleBackend ("Git", git_paths);
// Load the right controller for the OS
string controller_name;
switch (SparkleShare.Platform) {