30
30
using MonoDevelop.Projects;
31
31
using MonoDevelop.Ide.Gui;
32
32
using MonoDevelop.Core;
33
using MonoDevelop.VersionControl;
34
35
namespace MonoDevelop.ChangeLogAddIn
36
37
public static class ChangeLogService
38
public static ChangeLogData GetChangeLogData (CombineEntry entry)
40
ChangeLogData changeLogData = entry.ExtendedProperties ["MonoDevelop.ChangeLogAddIn.ChangeLogInfo"] as ChangeLogData;
41
if (changeLogData == null) {
42
changeLogData = entry.ExtendedProperties ["Temp.MonoDevelop.ChangeLogAddIn.ChangeLogInfo"] as ChangeLogData;
43
if (changeLogData == null) {
44
changeLogData = new ChangeLogData (entry);
45
entry.ExtendedProperties ["Temp.MonoDevelop.ChangeLogAddIn.ChangeLogInfo"] = changeLogData;
48
changeLogData.Bind (entry);
52
39
// Returns the path of the ChangeLog where changes of the provided file have to be logged.
53
40
// Returns null if no ChangeLog could be found.
54
41
// Returns an empty string if changes don't have to be logged.
55
public static string GetChangeLogForFile (string baseCommitPath, string file)
42
public static string GetChangeLogForFile (string baseCommitPath, string file, out SolutionItem parentEntry, out ChangeLogPolicy policy)
57
if (IdeApp.ProjectOperations.CurrentOpenCombine == null)
46
if (!IdeApp.Workspace.IsOpen)
60
49
// Find the project that contains the file. If none is found
61
50
// find a combine entry at the file location
62
CombineEntry entry = null;
63
51
string bestPath = null;
64
52
file = FileService.GetFullPath (file);
66
foreach (CombineEntry e in IdeApp.ProjectOperations.CurrentOpenCombine.GetAllEntries ()) {
67
if (e is Project && ((Project)e).ProjectFiles.GetFile (file) != null) {
54
foreach (SolutionItem e in IdeApp.Workspace.GetAllSolutionItems ()) {
55
if (e is Project && ((Project)e).Files.GetFile (file) != null) {
71
59
string epath = FileService.GetFullPath (e.BaseDirectory) + Path.DirectorySeparatorChar;
72
60
if (file.StartsWith (epath) && (bestPath == null || bestPath.Length < epath.Length)) {
66
if (parentEntry == null)
69
policy = parentEntry.Policies.Get<ChangeLogPolicy> ();
81
71
if (baseCommitPath == null)
82
baseCommitPath = entry.RootCombine.BaseDirectory;
72
baseCommitPath = parentEntry.ParentSolution.BaseDirectory;
84
74
baseCommitPath = FileService.GetFullPath (baseCommitPath);
86
ChangeLogData changeLogData = GetChangeLogData (entry);
88
CombineEntry parent = entry;
89
while (changeLogData.Policy == ChangeLogPolicy.UseParentPolicy) {
90
parent = parent.ParentCombine;
91
changeLogData = GetChangeLogData (parent);
94
switch (changeLogData.Policy)
76
if (policy.VcsIntegration == VcsIntegration.None)
79
switch (policy.UpdateMode)
96
case ChangeLogPolicy.NoChangeLog:
81
case ChangeLogUpdateMode.None:
97
82
return string.Empty;
99
case ChangeLogPolicy.UpdateNearestChangeLog: {
84
case ChangeLogUpdateMode.Nearest: {
100
85
string dir = FileService.GetFullPath (Path.GetDirectoryName (file));
112
case ChangeLogPolicy.OneChangeLogInProjectRootDirectory:
113
return Path.Combine (entry.BaseDirectory, "ChangeLog");
97
case ChangeLogUpdateMode.ProjectRoot:
98
return Path.Combine (parentEntry.BaseDirectory, "ChangeLog");
115
case ChangeLogPolicy.OneChangeLogInEachDirectory:
100
case ChangeLogUpdateMode.Directory:
116
101
string dir = Path.GetDirectoryName (file);
117
102
return Path.Combine (dir, "ChangeLog");
120
LoggingService.LogError ("Could not handle ChangeLogPolicy: " + changeLogData.Policy);
105
LoggingService.LogError ("Could not handle ChangeLogUpdateMode: " + policy.UpdateMode);
110
public static string GetChangeLogForFile (string baseCommitPath, string file)
112
SolutionItem parentEntry;
113
ChangeLogPolicy policy;
114
return GetChangeLogForFile (baseCommitPath, file, out parentEntry, out policy);
117
public static CommitMessageStyle GetMessageStyle (SolutionItem item)
119
ChangeLogPolicy policy;
121
policy = item.Policies.Get<ChangeLogPolicy> ();
123
policy = new ChangeLogPolicy ();
124
return policy.MessageStyle;