~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/ChangeLogAddIn/ChangeLogService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
using MonoDevelop.Projects;
31
31
using MonoDevelop.Ide.Gui;
32
32
using MonoDevelop.Core;
 
33
using MonoDevelop.VersionControl;
33
34
 
34
35
namespace MonoDevelop.ChangeLogAddIn
35
36
{
36
37
        public static class ChangeLogService
37
38
        {
38
 
                public static ChangeLogData GetChangeLogData (CombineEntry entry)
39
 
                {
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;
46
 
                                }
47
 
                        }
48
 
                        changeLogData.Bind (entry);
49
 
                        return changeLogData;
50
 
                }
51
 
                
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)
56
43
                {
57
 
                        if (IdeApp.ProjectOperations.CurrentOpenCombine == null)
 
44
                        parentEntry = null;
 
45
                        policy = null;
 
46
                        if (!IdeApp.Workspace.IsOpen)
58
47
                                return null;
59
48
                        
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);
65
53
                        
66
 
                        foreach (CombineEntry e in IdeApp.ProjectOperations.CurrentOpenCombine.GetAllEntries ()) {
67
 
                                if (e is Project && ((Project)e).ProjectFiles.GetFile (file) != null) {
68
 
                                        entry = e;
 
54
                        foreach (SolutionItem e in IdeApp.Workspace.GetAllSolutionItems ()) {
 
55
                                if (e is Project && ((Project)e).Files.GetFile (file) != null) {
 
56
                                        parentEntry = e;
69
57
                                        break;
70
58
                                }
71
59
                                string epath = FileService.GetFullPath (e.BaseDirectory) + Path.DirectorySeparatorChar;
72
60
                                if (file.StartsWith (epath) && (bestPath == null || bestPath.Length < epath.Length)) {
73
61
                                        bestPath = epath;
74
 
                                        entry = e;
 
62
                                        parentEntry = e;
75
63
                                }
76
64
                        }
77
65
                        
78
 
                        if (entry == null)
 
66
                        if (parentEntry == null)
79
67
                                return null;
80
68
                        
 
69
                        policy = parentEntry.Policies.Get<ChangeLogPolicy> ();
 
70
                        
81
71
                        if (baseCommitPath == null)
82
 
                                baseCommitPath = entry.RootCombine.BaseDirectory;
 
72
                                baseCommitPath = parentEntry.ParentSolution.BaseDirectory;
83
73
                        
84
74
                        baseCommitPath = FileService.GetFullPath (baseCommitPath);
85
75
                        
86
 
                        ChangeLogData changeLogData = GetChangeLogData (entry);
87
 
                        
88
 
                        CombineEntry parent = entry;
89
 
                        while (changeLogData.Policy == ChangeLogPolicy.UseParentPolicy) {
90
 
                                parent = parent.ParentCombine;
91
 
                                changeLogData = GetChangeLogData (parent);
92
 
                        }
93
 
                        
94
 
                        switch (changeLogData.Policy)
 
76
                        if (policy.VcsIntegration == VcsIntegration.None)
 
77
                                return "";
 
78
                        
 
79
                        switch (policy.UpdateMode)
95
80
                        {
96
 
                                case ChangeLogPolicy.NoChangeLog:
 
81
                                case ChangeLogUpdateMode.None:
97
82
                                        return string.Empty;
98
83
                                        
99
 
                                case ChangeLogPolicy.UpdateNearestChangeLog: {
 
84
                                case ChangeLogUpdateMode.Nearest: {
100
85
                                        string dir = FileService.GetFullPath (Path.GetDirectoryName (file));
101
86
                                        
102
87
                                        do {
109
94
                                        return null;
110
95
                                }
111
96
                                        
112
 
                                case ChangeLogPolicy.OneChangeLogInProjectRootDirectory:                                
113
 
                                        return Path.Combine (entry.BaseDirectory, "ChangeLog");
 
97
                                case ChangeLogUpdateMode.ProjectRoot:                           
 
98
                                        return Path.Combine (parentEntry.BaseDirectory, "ChangeLog");
114
99
                                        
115
 
                                case ChangeLogPolicy.OneChangeLogInEachDirectory:
 
100
                                case ChangeLogUpdateMode.Directory:
116
101
                                        string dir = Path.GetDirectoryName (file);
117
102
                                        return Path.Combine (dir, "ChangeLog");
118
103
 
119
104
                                default:
120
 
                                        LoggingService.LogError ("Could not handle ChangeLogPolicy: " + changeLogData.Policy);
 
105
                                        LoggingService.LogError ("Could not handle ChangeLogUpdateMode: " + policy.UpdateMode);
121
106
                                        return null;
122
107
                        }                                                       
123
108
                }       
 
109
                
 
110
                public static string GetChangeLogForFile (string baseCommitPath, string file)
 
111
                {
 
112
                        SolutionItem parentEntry;
 
113
                        ChangeLogPolicy policy;
 
114
                        return GetChangeLogForFile (baseCommitPath, file, out parentEntry, out policy);
 
115
                }
 
116
                
 
117
                public static CommitMessageStyle GetMessageStyle (SolutionItem item)
 
118
                {
 
119
                        ChangeLogPolicy policy;
 
120
                        if (item != null)
 
121
                                policy = item.Policies.Get<ChangeLogPolicy> ();
 
122
                        else
 
123
                                policy = new ChangeLogPolicy ();
 
124
                        return policy.MessageStyle;
 
125
                }
124
126
        }
125
127
}