Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SugoiDev committed Feb 5, 2018
1 parent b951995 commit ac1c95e
Show file tree
Hide file tree
Showing 29 changed files with 3,554 additions and 1,111 deletions.
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@
*.snk
ipch/
obj/
.vs/
Backup/
_ReSharper.Caches
*.DotSettings.user
*.DotSettings
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
.localhistory/
.localhistory/
ignore.conf
hidden_changes.conf
.plastic
BUILD.bat
packages/
.idea/
LocalHistory*.tss
7 changes: 5 additions & 2 deletions LocalHistory.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalHistory", "LocalHistory\LocalHistory.csproj", "{47F22155-F29E-417B-9F72-08D503DF18F9}"
EndProject
Expand All @@ -19,4 +19,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(CodealikeProperties) = postSolution
SolutionGuid = a6baee5e-c10a-4e27-9a71-f6dd403e97bd
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions LocalHistory/Changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
02/05/2018
First public release of v2.0.0
Main features
* settings page (Tools -> Options -> LocalHistory)
* external diff tool support
* labels (select the history item to add/change label, then use the L key)
* filtering for "labeled only" in the history panel
248 changes: 208 additions & 40 deletions LocalHistory/DocumentNode.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,213 @@
/*
Copyright 2013 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using System;
using System.Globalization;

namespace Intel.LocalHistory
{
public class DocumentNode
{
private readonly string repositoryPath;
private readonly string originalPath;
private readonly string fileName;
private readonly DateTime time;

public DocumentNode(string repositoryPath, string originalPath, string fileName, DateTime time)
{
this.repositoryPath = repositoryPath;
this.originalPath = originalPath;
this.fileName = fileName;
this.time = time;
}
// Copyright 2017 LOSTALLOY
// Copyright 2013 Intel Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace LOSTALLOY.LocalHistory {
using System;
using System.IO;

using JetBrains.Annotations;


public class DocumentNode {

#region Static Fields

// Epoch used for converting to unix time.
private static readonly DateTime EPOCH = new DateTime(1970, 1, 1);

#endregion


#region Fields

[NotNull]
private readonly string repositoryPath;

[NotNull]
private readonly string originalPath;

[NotNull]
private readonly string originalFileName;

private readonly string _unixTime;

[CanBeNull]
private string _label;

private DateTime _time;

#endregion


#region Constructors and Destructors

public DocumentNode(
[NotNull] string repositoryPath,
[NotNull] string originalPath,
[NotNull] string originalFileName,
DateTime time):
this(repositoryPath, originalPath, originalFileName, ToUnixTime(time).ToString()) { }


public DocumentNode(
[NotNull] string repositoryPath,
[NotNull] string originalPath,
[NotNull] string originalFileName,
string unixTime,
[CanBeNull] string label = null) {
this.repositoryPath = Utils.NormalizePath(repositoryPath);
this.originalPath = Utils.NormalizePath(originalPath);
this.originalFileName = originalFileName;
_unixTime = unixTime;
_time = ToDateTime(_unixTime);
_label = label;
}

#endregion


#region Public Properties

public bool HasLabel => !string.IsNullOrEmpty(_label);

public string VersionFileFullFilePath => Path.Combine(RepositoryPath, VersionFileName);
public string VersionFileName => $"{_unixTime}${originalFileName}{(HasLabel ? $"${_label}" : "")}";

[NotNull]
public string RepositoryPath => repositoryPath;

[NotNull]
public string OriginalPath => originalPath;

[NotNull]
public string OriginalFileName => originalFileName;

public string RepositoryPath { get { return repositoryPath; } }
[CanBeNull]
public string Label => _label;

public string OriginalPath { get { return originalPath; } }
/// <summary>
/// xaml binding. We only store seconds, so we can't have .f and fiends.
/// </summary>
[NotNull]
[UsedImplicitly]
public string Timestamp => $"{_time:dd/MM/yyyy HH:mm:ss}";

public string FileName { get { return fileName; } }
[NotNull]
public string TimestampAndLabel => $"{_time:dd/MM/yyyy HH:mm:ss}{(HasLabel ? $" {_label}" : "")}";

public string TimeStamp { get { return time.ToString(CultureInfo.CurrentCulture); } }
}
#endregion


#region Public Methods and Operators

/// <inheritdoc />
public static bool operator ==(DocumentNode left, DocumentNode right) {
return Equals(left, right);
}


/// <inheritdoc />
public static bool operator !=(DocumentNode left, DocumentNode right) {
return !Equals(left, right);
}


/// <inheritdoc />
public bool Equals([CanBeNull] DocumentNode other) {
if (ReferenceEquals(null, other)) {
return false;
}

if (ReferenceEquals(this, other)) {
return true;
}

//see comment ID 02:07 11/04/2017 for why label and repositoryPath are not included here
return string.Equals(originalPath, other.originalPath, StringComparison.OrdinalIgnoreCase)
&& string.Equals(originalFileName, other.originalFileName, StringComparison.OrdinalIgnoreCase)
&& string.Equals(_unixTime, other._unixTime, StringComparison.OrdinalIgnoreCase);
}


/// <inheritdoc />
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}

if (ReferenceEquals(this, obj)) {
return true;
}

if (obj.GetType() != GetType()) {
return false;
}

return Equals((DocumentNode)obj);
}


/// <inheritdoc />
public override int GetHashCode() {
unchecked {
//comment ID 02:07 11/04/2017
//label is not part of hashcode.
//we only care for the original file and the timestamp
//for this reason, we also don't include the repositoryPath
//two nodes are the considered the same if they are a version for the same file
//take at the same time. Nothing more.
var hashCode = StringComparer.OrdinalIgnoreCase.GetHashCode(originalPath);
hashCode = (hashCode * 397) ^ StringComparer.OrdinalIgnoreCase.GetHashCode(originalFileName);
hashCode = (hashCode * 397) ^ StringComparer.OrdinalIgnoreCase.GetHashCode(_unixTime);
return hashCode;
}
}


public void AddLabel(string label) {
var currentFullPath = Path.Combine(RepositoryPath, VersionFileName);
_label = label;
var newFullPath = Path.Combine(RepositoryPath, VersionFileName);
File.Move(currentFullPath, newFullPath);
}


public void RemoveLabel() {
if (!HasLabel) {
return;
}

var currentFullPath = Path.Combine(RepositoryPath, VersionFileName);
var fileNameWithoutLabel = VersionFileName.Substring(0, VersionFileName.Length - $"${_label}".Length);
var newFullPath = Path.Combine(RepositoryPath, fileNameWithoutLabel);
File.Move(currentFullPath, newFullPath);
_label = null;
}

#endregion


#region Methods

private static DateTime ToDateTime(string unixTime) {
return EPOCH.ToLocalTime().AddSeconds(long.Parse(unixTime));
}


private static long ToUnixTime(DateTime dateTime) {
return (long) (dateTime - EPOCH.ToLocalTime()).TotalSeconds;
}

#endregion

}
}
Loading

0 comments on commit ac1c95e

Please sign in to comment.