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

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion/SubversionVersionControl.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
{
12
12
        public abstract class SubversionVersionControl : VersionControlSystem
13
13
        {
14
 
                readonly string[] protocolsSvn = {"svn", "svn+ssh", "http", "https", "file"};
15
 
                
16
14
                public override string Name {
17
15
                        get { return "Subversion"; }
18
16
                }
22
20
                        return new SubversionRepository ();
23
21
                }
24
22
                
25
 
                public override Gtk.Widget CreateRepositoryEditor (Repository repo)
 
23
                public override IRepositoryEditor CreateRepositoryEditor (Repository repo)
26
24
                {
27
 
                        return new UrlBasedRepositoryEditor ((SubversionRepository)repo, protocolsSvn);
 
25
                        return new UrlBasedRepositoryEditor ((SubversionRepository)repo);
28
26
                }
29
27
 
30
28
                public override Repository GetRepositoryReference (FilePath path, string id)
33
31
                                if (!IsVersioned (path))
34
32
                                        return null;
35
33
                                string url = GetPathUrl (path);
36
 
                                return new SubversionRepository (this, url);
 
34
                                return new SubversionRepository (this, url, path);
37
35
                        } catch (Exception ex) {
38
36
                                // No SVN
39
37
                                LoggingService.LogError (ex.ToString ());
60
58
                        return Path.Combine(sourcepath, ".svn");
61
59
                }
62
60
                
63
 
                public bool IsDiffAvailable (Repository repo, FilePath sourcefile) {
64
 
                        try {
65
 
                                // Directory check is needed since directory links may look like versioned files
66
 
                                return File.Exists(GetTextBase(sourcefile)) && !Directory.Exists (sourcefile)
67
 
                                        && IsVersioned(sourcefile)
68
 
                                        && GetVersionInfo (repo, sourcefile, false).HasLocalChange (VersionStatus.Modified);
69
 
                        } catch {
70
 
                                // GetVersionInfo may throw an exception
71
 
                                return false;
72
 
                        }
73
 
                }
74
 
 
75
61
                public bool IsVersioned (FilePath sourcefile)
76
62
                {
77
63
                        return File.Exists (GetTextBase (sourcefile))
78
64
                                || Directory.Exists (GetDirectoryDotSvn (sourcefile));
79
65
                }
80
66
 
81
 
                public bool CanCommit (Repository repo, FilePath sourcepath)
82
 
                {
83
 
                        if (Directory.Exists (sourcepath) && Directory.Exists (GetDirectoryDotSvn (sourcepath)))
84
 
                                return true;
85
 
                        if (GetVersionInfo (repo, sourcepath, false) != null)
86
 
                                return true;
87
 
                        return false;
88
 
                }
89
 
 
90
 
                public bool CanAdd (Repository repo, FilePath sourcepath)
91
 
                {
92
 
                        // Do some trivial checks
93
 
                        
94
 
                        if (!Directory.Exists (GetDirectoryDotSvn (Path.GetDirectoryName (sourcepath))))
95
 
                                return false;
96
 
                        
97
 
                        if (File.Exists (sourcepath)) {
98
 
                                if (File.Exists (GetTextBase (sourcepath)))
99
 
                                        return false;
100
 
                        } else if (Directory.Exists (sourcepath)) {
101
 
                                if (Directory.Exists (GetTextBase (sourcepath)))
102
 
                                        return false;
103
 
                        } else
104
 
                                return false;
105
 
                                
106
 
                        // Allow adding only if the path is not already scheduled for adding
107
 
                        
108
 
                        VersionInfo ver = this.GetVersionInfo (repo, sourcepath, false);
109
 
                        if (ver == null)
110
 
                                return true;
111
 
                        return !ver.IsVersioned;
112
 
                }
113
 
                
114
67
                public string GetPathToBaseText (FilePath sourcefile) {
115
68
                        return GetTextBase (sourcefile);
116
69
                }
132
85
 
133
86
                public abstract IEnumerable<SvnRevision> Log (Repository repo, FilePath path, SvnRevision revisionStart, SvnRevision revisionEnd);
134
87
                
135
 
                public abstract string GetTextAtRevision (string repositoryPath, Revision revision);
 
88
                public abstract string GetTextAtRevision (string repositoryPath, Revision revision);
 
89
                
 
90
                internal protected virtual VersionControlOperation GetSupportedOperations (Repository repo, VersionInfo vinfo, VersionControlOperation defaultValue)
 
91
                {
 
92
                        if (vinfo.IsVersioned && File.Exists (vinfo.LocalPath) && !Directory.Exists (vinfo.LocalPath) && vinfo.HasLocalChange (VersionStatus.ScheduledDelete))
 
93
                                defaultValue |= VersionControlOperation.Add;
 
94
                        return defaultValue;
 
95
                }
136
96
 
137
97
                public VersionInfo GetVersionInfo (Repository repo, FilePath localPath, bool getRemoteStatus)
138
98
                {
142
102
                        else if (File.Exists (GetTextBase(localPath)) || File.Exists (localPath))
143
103
                                return GetFileStatus (repo, localPath, getRemoteStatus);
144
104
                        else
145
 
                                return null;
 
105
                                return VersionInfo.CreateUnversioned (localPath, false);
146
106
                }
147
107
 
148
108
                private VersionInfo GetFileStatus (Repository repo, FilePath sourcefile, bool getRemoteStatus)
149
109
                {
 
110
                        SubversionRepository srepo = (SubversionRepository) repo;
 
111
                        
150
112
                        // If the directory is not versioned, there is no version info
151
113
                        if (!Directory.Exists (GetDirectoryDotSvn (sourcefile.ParentDirectory)))
152
 
                                return null;
 
114
                                return VersionInfo.CreateUnversioned (sourcefile, false);
 
115
                        if (!sourcefile.IsChildPathOf (srepo.RootPath))
 
116
                                return VersionInfo.CreateUnversioned (sourcefile, false);
153
117
                        
154
118
                        List<VersionInfo> statuses = new List<VersionInfo> ();
155
119
                        statuses.AddRange (Status (repo, sourcefile, SvnRevision.Head, false, false, getRemoteStatus));
156
120
 
157
121
                        if (statuses.Count == 0)
158
 
                                throw new ArgumentException("Path '" + sourcefile + "' does not exist in the repository.");
 
122
                                return VersionInfo.CreateUnversioned (sourcefile, false);
159
123
                        
160
124
                        if (statuses.Count != 1)
161
 
                                throw new ArgumentException("Path '" + sourcefile + "' does not refer to a file in the repository.");
 
125
                                return VersionInfo.CreateUnversioned (sourcefile, false);
162
126
                        
163
127
                        VersionInfo ent = (VersionInfo) statuses[0];
164
128
                        if (ent.IsDirectory)
165
 
                                throw new ArgumentException("Path '" + sourcefile + "' does not refer to a file.");
 
129
                                return VersionInfo.CreateUnversioned (sourcefile, false);
166
130
                        
167
131
                        return ent;
168
132
                }
171
135
                {
172
136
                        // If the directory is not versioned, there is no version info
173
137
                        if (!Directory.Exists (GetDirectoryDotSvn (localPath)))
174
 
                                return null;
 
138
                                return VersionInfo.CreateUnversioned (localPath, true);
175
139
                                
176
140
                        foreach (VersionInfo ent in Status (repo, localPath, SvnRevision.Head, false, false, getRemoteStatus)) {
177
 
                                if (ent.LocalPath == localPath)
 
141
                                if (ent.LocalPath.CanonicalPath == localPath.CanonicalPath)
178
142
                                        return ent;
179
143
                        }
180
 
                        return null;
 
144
                        return VersionInfo.CreateUnversioned (localPath, true);
181
145
                }
182
146
 
183
147
                public VersionInfo[] GetDirectoryVersionInfo (Repository repo, FilePath sourcepath, bool getRemoteStatus, bool recursive)
292
256
                /// <returns>
293
257
                /// A <see cref="System.String"/> annotation for each line in file.
294
258
                /// </returns>
295
 
                public virtual List<string> GetAnnotations (Repository repo, FilePath file, SvnRevision revStart, SvnRevision revEnd)
 
259
                public virtual Annotation[] GetAnnotations (Repository repo, FilePath file, SvnRevision revStart, SvnRevision revEnd)
296
260
                {
297
 
                        return new List<string> ();
 
261
                        return new Annotation[0];
298
262
                }
299
263
        }
300
264