summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-24 23:24:00 +0100
committerhut <hut@lavabit.com>2013-02-24 23:24:00 +0100
commit6e46fd77cc8674e3ea3603a66981ce1c6abc3d18 (patch)
treedbfc86b9c63f2717c0a8396cc55adfb68172fdae
parentb108021d64010dbd4677dc24729680a8ab90fb04 (diff)
downloadranger-6e46fd77cc8674e3ea3603a66981ce1c6abc3d18.tar.gz
vcs: move some code from load_bit_by_bit to load_vcs
-rw-r--r--ranger/fsobject/directory.py31
-rw-r--r--ranger/fsobject/fsobject.py39
2 files changed, 42 insertions, 28 deletions
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 9bd728c1..546fc6d0 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -16,7 +16,6 @@ from ranger.core.shared import SettingsAware
 from ranger.ext.accumulator import Accumulator
 from ranger.ext.lazy_property import lazy_property
 from ranger.ext.human_readable import human_readable
-from ranger.ext.vcs import VcsError
 from ranger.container.settingobject import LocalSettingObject
 
 def sort_by_basename(path):
@@ -71,7 +70,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
     content_outdated = False
     content_loaded = False
 
-    has_vcschild=False
+    has_vcschild = False
 
     _cumulative_size_calculated = False
 
@@ -259,32 +258,8 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                     # Load vcs data
                     if self.settings.vcs_aware:
                         item.load_vcs()
-                        if item.vcs:
-                            if item.vcs.vcsname == 'git':   backend_state = self.settings.vcs_backend_git
-                            elif item.vcs.vcsname == 'hg':  backend_state = self.settings.vcs_backend_hg
-                            elif item.vcs.vcsname == 'bzr': backend_state = self.settings.vcs_backend_bzr
-                            else:                           backend_state = 'disabled'
-
-                            if backend_state in set(['enabled', 'local']):
-                                self.has_vcschild = True
-                                try:
-                                    if self.vcs_outdated or item.vcs_outdated:
-                                        item.vcs_outdated = False
-                                        item.vcs.get_status()  # caches the file status for get_file_status()
-                                        item.vcsbranch = item.vcs.get_branch()
-                                        item.vcshead = item.vcs.get_info(item.vcs.HEAD)
-                                        if item.path == item.vcs.root and backend_state == 'enabled':
-                                            item.vcsremotestatus = item.vcs.get_remote_status()
-                                    else:
-                                        item.vcsbranch = self.vcsbranch
-                                        item.vcshead = self.vcshead
-                                    item.vcsfilestatus = item.vcs.get_file_status(item.path)
-                                except VcsError as err:
-                                    item.vcsbranch = None
-                                    item.vcshead = None
-                                    item.vcsremotestatus = 'unknown'
-                                    item.vcsfilestatus = 'unknown'
-                                    self.fm.notify("Can not load vcs data on %s: %s" % (item.path, err), bad=True)
+                        if item.vcs_enabled:
+                            self.has_vcschild = True
 
                     files.append(item)
                     self.percent = 100 * len(files) // len(filenames)
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 506f13d9..737e3f5c 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -75,6 +75,7 @@ class FileSystemObject(FileManagerAware):
      vcshead) = (None,) * 5
 
     vcs_outdated = False
+    vcs_enabled = False
 
     def __init__(self, path, preload=None, path_is_abs=False):
         if not path_is_abs:
@@ -198,6 +199,7 @@ class FileSystemObject(FileManagerAware):
         Reads data regarding the version control system the object is on.
         Does not load content specific data.
         """
+        from ranger.ext.vcs import VcsError
 
         vcs = Vcs(self.path)
 
@@ -225,6 +227,43 @@ class FileSystemObject(FileManagerAware):
             if rootdir.vcs_outdated:
                 self.vcs_outdated = True
 
+        if self.vcs:
+            if self.vcs.vcsname == 'git':
+                backend_state = self.settings.vcs_backend_git
+            elif self.vcs.vcsname == 'hg':
+                backend_state = self.settings.vcs_backend_hg
+            elif item.vcs.vcsname == 'bzr':
+                backend_state = self.settings.vcs_backend_bzr
+            else:
+                backend_state = 'disabled'
+
+            self.vcs_enabled = backend_state in set(['enabled', 'local'])
+            if self.vcs_enabled:
+                try:
+                    if self.vcs_outdated or self.vcs_outdated:
+                        self.vcs_outdated = False
+                        # this caches the file status for get_file_status():
+                        self.vcs.get_status()
+                        self.vcsbranch = self.vcs.get_branch()
+                        self.vcshead = self.vcs.get_info(self.vcs.HEAD)
+                        if self.path == self.vcs.root and \
+                                backend_state == 'enabled':
+                            self.vcsremotestatus = \
+                                    self.vcs.get_remote_status()
+                    else:
+                        self.vcsbranch = self.vcsbranch
+                        self.vcshead = self.vcshead
+                    self.vcsfilestatus = self.vcs.get_file_status(self.path)
+                except VcsError as err:
+                    self.vcsbranch = None
+                    self.vcshead = None
+                    self.vcsremotestatus = 'unknown'
+                    self.vcsfilestatus = 'unknown'
+                    self.fm.notify("Can not load vcs data on %s: %s" %
+                            (self.path, err), bad=True)
+        else:
+            self.vcs_enabled = False
+
     def load(self):
         """Loads information about the directory itself.
 
ref='/akspecs/ranger/commit/ranger/conf/apps.py?h=v1.7.0-emacs&id=cc952d63d81e410d1c7dd3bfbe91ee6cfdd3d7a8'>cc952d63 ^
23236d0c ^


cc952d63 ^
d46a05a8 ^
23236d0c ^

cc952d63 ^
d46a05a8 ^
1b0786f2 ^



d46a05a8 ^
1b0786f2 ^





d46a05a8 ^

845bd407 ^




d46a05a8 ^
23236d0c ^


cc952d63 ^
23236d0c ^
d46a05a8 ^
23236d0c ^


cc952d63 ^
23236d0c ^

871c502d ^
cc952d63 ^
23236d0c ^

d46a05a8 ^
23236d0c ^










d46a05a8 ^
23236d0c ^




cc952d63 ^
d46a05a8 ^
ac0daa33 ^
23236d0c ^
ac0daa33 ^
845bd407 ^
d46a05a8 ^
845bd407 ^







c3cdeb9c ^







d46a05a8 ^
845bd407 ^
c3cdeb9c ^
845bd407 ^
d46a05a8 ^
845bd407 ^


d46a05a8 ^
845bd407 ^







d46a05a8 ^
845bd407 ^
8e1de917 ^
845bd407 ^
d46a05a8 ^
845bd407 ^


d46a05a8 ^
845bd407 ^
8e1de917 ^
845bd407 ^
d46a05a8 ^
845bd407 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174