/// <summary> /// TODO: only get GitDetail on Project level? /// </summary> /// <param name="path"></param> /// <returns></returns> public static GitDetail GetGitDetail(string path) { GitDetail detail = null; if (string.IsNullOrEmpty(path)) return detail; try { var repoPath = Repository.FindRepository(path); if (string.IsNullOrEmpty(repoPath)) return detail; var repo = new Repository(repoPath); detail = new GitDetail(); // Convert to forward slash detail.LocalWorkingDirectory = repo.WorkingDirectory.BackSlashToForwardSlash(); if (repo.Head == null) return detail; var branch = repo.CurrentBranch; detail.RemoteRepositoryUrl = repo.Config["remote.origin.url"]; detail.RemoteBranch = branch.Name; // detail.Description = repo.Head.CurrentCommit.ShortHash; detail.RelativePath = PathUtility.MakeRelativePath(Path.GetDirectoryName(repoPath), path); } catch (Exception) { // SWALLOW exception? // Console.Error.WriteLine(e.Message); } return detail; }
public void LoadBackupList(WorldSave save) { backupView.Items.Clear(); if (!Repository.IsValid(save.Path)) return; using (Repository repo = new Repository(save.Path)) { foreach (Commit commit in repo.CurrentBranch.CurrentCommit.Ancestors) { DateTime commitTime = commit.CommitDate.LocalDateTime; ListViewItem item = new ListViewItem(commit.Message); ListViewItem.ListViewSubItem dateItem = item.SubItems.Add( commitTime.ToString()); dateItem.Name = "date"; ListViewItem.ListViewSubItem hashItem = item.SubItems.Add(commit.ShortHash); hashItem.Name = "shorthash"; ListViewItem.ListViewSubItem longHashItem = item.SubItems.Add(commit.Hash); longHashItem.Name = "hash"; backupView.Items.Add(item); } } }
public ActionResult Index() { var dirs = Directory.GetDirectories(_settings.RepositoryRootPath); var viewModel = new RepositoriesViewModel { List = new List<RepositoryViewModel>() }; foreach (string path in dirs) { var isValid = Repository.IsValid(path); if (isValid) { using (var repo = new Repository(path)) { viewModel.List.Add(new RepositoryViewModel { Name = repo.IsBare ? Path.GetFileName(repo.Directory.TrimGit()) : Path.GetFileName(path.TrimGit()), Description = repo.Directory, Path = repo.Directory, CurrentCommit = repo.Branches["master"].CurrentCommit }); } } } return View(viewModel); }
protected void SetupContext() { _nicolai = new Author("Nicolai Meltveit", "*****@*****.**"); _repositoryUrl = "git://github.com/flyrev/Smeedee_dummy.git"; _localDirectory = "C:\\ennå_nyare\\"; _repo = new Repository(_localDirectory); }
/// <summary> /// Parsed reflog entry. /// </summary> public ReflogReader(Repository db, string refName) { _logName = new FileInfo( Path.Combine( db.Directory.FullName, Path.Combine("logs", refName)).Replace('/', Path.DirectorySeparatorChar)); }
/// <summary> /// Construct an object writer for the specified repository. /// </summary> /// <param name="repo"> </param> public ObjectWriter(Repository repo) { _r = repo; _buf = new byte[0x2000]; _md = new MessageDigest(); _def = new Deflater(_r.Config.getCore().getCompression()); }
public ObjectWriter(Repository repo) { this.r = repo; buf = new byte[8192]; md = new MessageDigest(); // [henon] Sha1 hash digest generator def = new Deflater(r.Config.Core.Compression); }
public Index(Repository repo) { _repo = repo; //GitIndex.FilenameEncoding = repo.PreferredEncoding; //if (_repo.PreferredEncoding != Encoding.UTF8 && _repo.PreferredEncoding != Encoding.Default) // GitIndex.FilenameEncoding = Encoding.Default; }
private void LoadRepository() { if (!Directory.Exists(Path.Combine(ResourceLocation, ".git"))) { Git.Init(ResourceLocation); } Repo = new Repository(ResourceLocation); }
/// <summary> /// Create a checkout class for checking out one tree, merging with the index /// </summary> /// <param name="repo"> </param> /// <param name="root"> workdir </param> /// <param name="index"> current index </param> /// <param name="merge"> tree to check out </param> public WorkDirCheckout(Repository repo, FileSystemInfo root, GitIndex index, Tree merge) : this() { this._repo = repo; this._root = root; this._index = index; this._merge = merge; }
public RefDatabase(Repository repo) { Repository = repo; _gitDir = repo.Directory; _refsDir = PathUtil.CombineDirectoryPath(_gitDir, "refs"); _packedRefsFile = PathUtil.CombineFilePath(_gitDir, "packed-refs"); ClearCache(); }
private readonly int tzOffset; // offset in minutes to UTC #endregion Fields #region Constructors /// <summary> /// Creates new PersonIdent from config info in repository, with current time. /// This new PersonIdent gets the info from the default committer as available /// from the configuration. /// </summary> /// <param name="repo"></param> public PersonIdent(Repository repo) { RepositoryConfig config = repo.Config; string username = config.getString("user", null, "name"); string email = config.getString("user", null, "email"); Name = username; EmailAddress = email; }
public Versioning(Data data, GitSharp.Repository repo) { GitDetails = null; InitializeComponent(); VersionControlData = data; _repo = repo; LoadFileStructure(); }
public RepositoryNavigationViewModelBase(Repository repository, RepositoryNavigationRequest request) : this() { RepositoryName = request.RepositoryName; Treeish = request.Treeish; Path = request.Path; RepositoryLocation = request.RepositoryLocation; FillFromRepository(repository, request); }
public PersonIdent(Repository repo) { RepositoryConfig config = repo.Config; string username = config.GetString("user", null, "name"); string email = config.GetString("user", null, "email"); this.Name = username; this.EmailAddress = email; this.when_time = DateTimeOffset.Now; }
public static IEnumerable<Change> GetChanges(string path, string firstIdentifier, string secondIdentifier, string repositoryPath = "Backend.git") { var repo = new Repository(repositoryPath); var firstCommit = repo.Get<Commit>(firstIdentifier); var secondCommit = repo.Get<Commit>(secondIdentifier); if (firstCommit == null || secondCommit == null) return null; return secondCommit.CompareAgainst(firstCommit).ToArray(); }
/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="r">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository r, ObjectId objectid) : base(@base) { ObjectLoader loader = r.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
public void MyTestInitialize() { _tempFiles = new TempFiles(); _repoPath = _tempFiles.GetTemporaryDirectory(); _gitPath = Path.Combine(_repoPath, ".git"); Directory.CreateDirectory(_gitPath); Program.Initialize(); _gitRepository = new GitRepository(ObjectFactory.GetInstance<TextWriter>(), _gitPath); _csharpRepository = new Repository(_gitPath); }
private readonly int tzOffset; // offset in minutes to UTC #endregion Fields #region Constructors public PersonIdent(Repository repo) { RepositoryConfig config = repo.Config; string username = config.getString("user", null, "name"); string email = config.getString("user", null, "email"); Name = username; EmailAddress = email; DateTimeOffset now = DateTimeOffset.Now; When = now.Millisecond; tzOffset = now.Offset.Minutes; }
public CommitViewModel(Repository repository, RepositoryNavigationRequest request, Commit commit, bool fillParents) : base(new RepositoryNavigationRequest(request) { Treeish = commit.Hash }) { if (fillParents) { Parents = new List<CommitViewModel>(commit.Parents.Select(x => new CommitViewModel(repository, request, x, false))); } Tree = new TreeNodeViewModel(repository, request, commit.Tree); Commit = commit; }
// load private void OnLoadRepository(object sender, RoutedEventArgs e) { var url = m_url_textbox.Text; var repo = Repository.Open(url); var head = repo.OpenCommit(repo.Head.ObjectId) as Commit; m_repository = repo; var tags = repo.Tags.Values.Select(@ref => repo.MapTag(@ref.Name, @ref.ObjectId)); //var branches = repo.Branches.Values.Select(@ref => repo.MapCommit(@ref.ObjectId)); m_refs.ItemsSource = repo.Refs.Values; DisplayCommit(head, "HEAD"); ReloadConfiguration(); }
static void Main(string[] args) { var repo = new Repository(@"."); var sb = new StringBuilder(); //sb.AppendLine(repo.CurrentBranch.CurrentCommit.Message); foreach (var commit in repo.CurrentBranch.CurrentCommit.Ancestors) { sb.Append(commit.Message); } Console.WriteLine(sb.ToString()); Clipboard.SetText(sb.ToString()); }
public Versioning(Data data, GitSharp.Repository repo) { GitDetails = null; InitializeComponent(); ForeColor = ThemeColorTable.ForeColor; BackColor = ThemeColorTable.BackgroundColor; ThemeUpdateControls.UpdateControls(this); Icon = Resources.Icon_Vixen3; VersionControlData = data; _repo = repo; LoadFileStructure(); }
/** * Construct a Tag representing an existing with a known name referencing an known object. * This could be either a simple or annotated tag. * * @param db {@link Repository} * @param id target id. * @param refName tag name or null * @param raw data of an annotated tag. */ public Tag(Repository db, ObjectId id, string refName, byte[] raw) { Repository = db; if (raw != null) { TagId = id; Id = ObjectId.FromString(raw, 7); } else Id = id; if (refName != null && refName.StartsWith("refs/tags/")) refName = refName.Substring(10); TagName = refName; this.raw = raw; }
public override bool Execute() { string hash = "private"; var path = Repository.FindRepository(Path); if (Repository.IsValid(path)) { var repo = new Repository(path); hash = repo.CurrentBranch.CurrentCommit.Hash; } CommitHash = new TaskItem(hash); return true; }
public static string GetTemplate(string path, string repository = "Backend.git", string branch = "template") { var repo = new Repository(repository); var commit = repo.Get<Commit>(branch); if (commit == null) return null; var blob = commit.Tree[path]; if (blob == null || !blob.IsBlob) { return null; } return new Blob(repo, blob.Hash).Data; }
public DirectoryWithHistory(IHistoryProvider provider, string path) { if (provider == null) { throw new ArgumentNullException ("provider"); } Path = path; Provider = provider; repository = ((HistoryProvider)provider).Repository; ReadSubDirectories (); ReadContainingFiles (); }
public static Blob GetData(string path, string identifier, string repositoryPath = "Backend.git") { var repo = new Repository(repositoryPath); var commit = repo.Get<Commit>(identifier); if (commit == null) return null; var blob = commit.Tree[path]; if (blob == null || !blob.IsBlob) { return null; } return new Blob(repo, blob.Hash); }
public static IEnumerable<Commit> GetHistory(string path, string identifier, string repositoryPath = "Backend.git") { var repo = new Repository(repositoryPath); var commit = repo.Get<Commit>(identifier); if (commit == null) yield break; while (commit != null) { if (commit.Tree[path] != null) { yield return commit; } commit = commit.HasParents ? commit.Parent : null; } }
public void see_if_we_get_a_not_disposed_warning() { Repository repository = new Repository(_localDirectory_cloned); var head = repository.Get<Commit>("HEAD"); var log = new Collection<Commit>(); Console.WriteLine(head.Message); log.Add(head); log.Add(head.Parent); for (int i=0; i<log.Count(); i++) Console.WriteLine(log.ElementAt(i).Message); GitChangesetRepository gcr = new GitChangesetRepository(_localDirectory_cloned); var testGet = gcr.Get(new ChangesetsAfterRevisionSpecification(65)); }
private void EnableDisableSourceControl(bool enabled) { _showCommand.Enabled = enabled; DisableWatchers(); if (enabled) { var repoCreated = CreateRepositoryIfNotExists(); repo = new GitSharp.Repository(GitRepositoryFolder); // repo.WorkingDirectory = GitRepositoryFolder; AddItemsToGit(repoCreated); CreateWatcher(GitRepositoryFolder, true); } }
private ActionResult GetInfoRefs(String project, String service) { Response.StatusCode = 200; Response.ContentType = String.Format("application/x-{0}-advertisement", service); SetNoCache(); Response.Write(FormatMessage(String.Format("# service={0}\n", service))); Response.Write(FlushMessage()); var directory = GetDirectoryInfo(project); if (GitSharp.Repository.IsValid(directory.FullName, true)) { using (var repository = new GitSharp.Repository(directory.FullName)) { if (String.Equals("git-receive-pack", service, StringComparison.InvariantCultureIgnoreCase)) { using (var pack = new ReceivePack(repository)) { pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream))); } } else if (String.Equals("git-upload-pack", service, StringComparison.InvariantCultureIgnoreCase)) { using (var pack = new UploadPack(repository)) { pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream))); } } } return(new EmptyResult()); } else { return(new HttpNotFoundResult()); } }
private ActionResult ExecuteUploadPack(string project) { Response.ContentType = "application/x-git-upload-pack-result"; SetNoCache(); var directory = GetDirectoryInfo(project); if (GitSharp.Repository.IsValid(directory.FullName, true)) { using (var repository = new GitSharp.Repository(directory.FullName)) using (var pack = new UploadPack(repository)) { pack.setBiDirectionalPipe(false); pack.Upload(GetInputStream(), Response.OutputStream, Response.OutputStream); } return(new EmptyResult()); } else { return(new HttpNotFoundResult()); } }
private void EnableDisableSourceControl(bool enabled) { Logging.Info("Initializing version control. Enabled:{0}.", enabled); _showCommand.Enabled = enabled; DisableWatchers(); if (enabled) { var repoCreated = CreateRepositoryIfNotExists(); repo = new GitSharp.Repository(GitRepositoryFolder); // repo.WorkingDirectory = GitRepositoryFolder; AddItemsToGit(repoCreated); CreateWatcher(GitRepositoryFolder, true); } Logging.Info("Initializing version control complete."); }
internal Commit(Repository repo, ObjectId id) : base(repo, id) { }
/// <summary> /// compare the given commits and return the changes. /// </summary> /// <param name="repo"></param> /// <param name="walk"></param> /// <param name="commits">first commit in the array is the commit that is compared against the others which are his ancestors (i.e. from different branches)</param> /// <returns></returns> private static IEnumerable <Change> CalculateCommitDiff(Repository repo, TreeWalk walk, Commit[] commits) { while (walk.next()) { int m0 = walk.getRawMode(0); if (walk.getTreeCount() == 2) { int m1 = walk.getRawMode(1); var change = new Change { ReferenceCommit = commits[0], ComparedCommit = commits[1], ReferencePermissions = walk.getFileMode(0).Bits, ComparedPermissions = walk.getFileMode(1).Bits, Name = walk.getNameString(), Path = walk.getPathString(), }; if (m0 != 0 && m1 == 0) { change.ChangeType = ChangeType.Added; change.ComparedObject = Wrap(repo, walk.getObjectId(0)); } else if (m0 == 0 && m1 != 0) { change.ChangeType = ChangeType.Deleted; change.ReferenceObject = Wrap(repo, walk.getObjectId(0)); } else if (m0 != m1 && walk.idEqual(0, 1)) { change.ChangeType = ChangeType.TypeChanged; change.ReferenceObject = Wrap(repo, walk.getObjectId(0)); change.ComparedObject = Wrap(repo, walk.getObjectId(1)); } else { change.ChangeType = ChangeType.Modified; change.ReferenceObject = Wrap(repo, walk.getObjectId(0)); change.ComparedObject = Wrap(repo, walk.getObjectId(1)); } yield return(change); } else { var raw_modes = new int[walk.getTreeCount() - 1]; for (int i = 0; i < walk.getTreeCount() - 1; i++) { raw_modes[i] = walk.getRawMode(i + 1); } var change = new Change { ReferenceCommit = commits[0], //ComparedCommit = compared, Name = walk.getNameString(), Path = walk.getPathString(), }; if (m0 != 0 && raw_modes.All(m1 => m1 == 0)) { change.ChangeType = ChangeType.Added; change.ComparedObject = Wrap(repo, walk.getObjectId(0)); yield return(change); } else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0)) { change.ChangeType = ChangeType.Deleted; yield return(change); } else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).All(x => !walk.idEqual(0, x.Index))) // TODO: not sure if this condition suffices in some special cases. { change.ChangeType = ChangeType.Modified; change.ReferenceObject = Wrap(repo, walk.getObjectId(0)); yield return(change); } else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).Any(x => m0 != x.Mode && walk.idEqual(0, x.Index))) { change.ChangeType = ChangeType.TypeChanged; change.ReferenceObject = Wrap(repo, walk.getObjectId(0)); yield return(change); } } } }
internal Commit(Repository repo, Core.Commit internal_commit) : base(repo, internal_commit.CommitId) { _internal_commit = internal_commit; }
public ActionResult Index(string project, string path = "", string file = "", bool returnAsBinary = false) { bool isAuthenticated = HttpContext.User.Identity.IsAuthenticated; if (isAuthenticated) { isAuthenticated = AuthService.CanRead(project, HttpContext.User.Identity.Name); } if (!AuthService.IsRepositoryPublic(project) && !isAuthenticated) { return(Redirect("../")); } var model = new LevelViewModel(); //Opening an existing git repository Lib.Repository gitasprepo = repositories.GetRepository(project); model.Project = project; var directory = gitasprepo.GitDirectory(); var repo = new GitSharp.Repository(directory); if (repo == null || repo.Head == null || repo.Head.CurrentCommit == null) { return(View(model)); } var tree = repo.Head.CurrentCommit.Tree; model.SetBreadCrumb(path.Split(Path.DirectorySeparatorChar).ToList()); if (model.BreadCrumb.Count > 0) { foreach (var breadCrumb in model.BreadCrumb) { var subTree = tree.Trees.Where(a => a.Name == Path.GetFileName(breadCrumb)).FirstOrDefault(); if (subTree != null) { tree = subTree; } } } if (string.IsNullOrEmpty(file)) { if (tree == null) { throw new Exception("Path not found"); } //Now you can browse throught that tree by iterating over its child trees foreach (Tree subtree in tree.Trees) { model.Directories.Add(new LevelItemViewModel(model) { Name = subtree.Path }); } //Or printing the names of the files it contains foreach (Leaf leaf in tree.Leaves) { model.Files.Add(new LevelItemViewModel(model) { Name = leaf.Path }); } } else { model.Ext = Path.GetExtension(file); if (!string.IsNullOrEmpty(model.Ext)) { model.Ext = model.Ext.Substring(1); } //Or printing the names of the files it contains foreach (Leaf leaf in tree.Leaves) { if (file == Path.GetFileName(leaf.Path)) { model.FileName = string.Format("Binary?project={0}&path={1}&file={2}", (project), (path), (file)); if (FileDisplayHandler.IsImage(file)) { model.ImageFile = string.Format("Binary?project={0}&path={1}&file={2}", (project), (path), (file)); model.FileName = model.ImageFile; } else { model.TextFile = FillFileData(leaf); if (model.TextFile == null) { model.BinaryFile = model.FileName; } } } } } return(View(model)); }
public FileContentResult Binary(string project, string path = "", string file = "", bool returnAsBinary = false) { bool isAuthenticated = HttpContext.User.Identity.IsAuthenticated; if (isAuthenticated) { isAuthenticated = AuthService.CanRead(project, HttpContext.User.Identity.Name); } if (!AuthService.IsRepositoryPublic(project) && !isAuthenticated) { return(new FileContentResult(new byte[] { }, "binary/octet-stream")); } var model = new LevelViewModel(); //Opening an existing git repository Lib.Repository gitasprepo = repositories.GetRepository(project); model.Project = project; var directory = gitasprepo.GitDirectory(); var repo = new GitSharp.Repository(directory); if (repo == null || repo.Head == null || repo.Head.CurrentCommit == null) { return(new FileContentResult(new byte[] { }, "binary/octet-stream")); } var tree = repo.Head.CurrentCommit.Tree; model.SetBreadCrumb(path.Split(Path.DirectorySeparatorChar).ToList()); if (model.BreadCrumb.Count > 0) { foreach (var breadCrumb in model.BreadCrumb) { var subTree = tree.Trees.Where(a => a.Name == Path.GetFileName(breadCrumb)).FirstOrDefault(); if (subTree != null) { tree = subTree; } } } if (string.IsNullOrEmpty(file)) { if (tree == null) { throw new Exception("Path not found"); } //Now you can browse throught that tree by iterating over its child trees foreach (Tree subtree in tree.Trees) { model.Directories.Add(new LevelItemViewModel(model) { Name = subtree.Path }); } //Or printing the names of the files it contains foreach (Leaf leaf in tree.Leaves) { model.Files.Add(new LevelItemViewModel(model) { Name = leaf.Path }); } } else { //Or printing the names of the files it contains foreach (Leaf leaf in tree.Leaves) { if (file == Path.GetFileName(leaf.Path)) { var fcr = new FileContentResult(leaf.RawData, FileDisplayHandler.GetMimeType(file)); fcr.FileDownloadName = leaf.Name; return(fcr); } } } return(new FileContentResult(new byte[] { }, "binary/octet-stream")); }
internal Commit(Repository repo, CoreRef @ref) : base(repo, @ref.ObjectId) { }
public Commit(Repository repo, string hash_or_name) : base(repo, hash_or_name) { }