##// END OF EJS Templates
files: fixes error when passing a diff without parameters and caused server crash...
marcink -
r1224:e76833cd beta
parent child Browse files
Show More
@@ -98,7 +98,7 b' class FilesController(BaseRepoController'
98 #reditect to given revision from form if given
98 #reditect to given revision from form if given
99 post_revision = request.POST.get('at_rev', None)
99 post_revision = request.POST.get('at_rev', None)
100 if post_revision:
100 if post_revision:
101 cs = self.__get_cs_or_redirect(revision, repo_name)
101 cs = self.__get_cs_or_redirect(post_revision, repo_name)
102 redirect(url('files_home', repo_name=c.repo_name,
102 redirect(url('files_home', repo_name=c.repo_name,
103 revision=cs.raw_id, f_path=f_path))
103 revision=cs.raw_id, f_path=f_path))
104
104
@@ -213,14 +213,14 b' class FilesController(BaseRepoController'
213 c.changeset_1 = c.rhodecode_repo.get_changeset(diff1)
213 c.changeset_1 = c.rhodecode_repo.get_changeset(diff1)
214 node1 = c.changeset_1.get_node(f_path)
214 node1 = c.changeset_1.get_node(f_path)
215 else:
215 else:
216 c.changeset_1 = EmptyChangeset()
216 c.changeset_1 = EmptyChangeset(repo=c.rhodecode_repo)
217 node1 = FileNode('.', '', changeset=c.changeset_1)
217 node1 = FileNode('.', '', changeset=c.changeset_1)
218
218
219 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
219 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
220 c.changeset_2 = c.rhodecode_repo.get_changeset(diff2)
220 c.changeset_2 = c.rhodecode_repo.get_changeset(diff2)
221 node2 = c.changeset_2.get_node(f_path)
221 node2 = c.changeset_2.get_node(f_path)
222 else:
222 else:
223 c.changeset_2 = EmptyChangeset()
223 c.changeset_2 = EmptyChangeset(repo=c.rhodecode_repo)
224 node2 = FileNode('.', '', changeset=c.changeset_2)
224 node2 = FileNode('.', '', changeset=c.changeset_2)
225 except RepositoryError:
225 except RepositoryError:
226 return redirect(url('files_home',
226 return redirect(url('files_home',
@@ -68,6 +68,7 b" def recursive_replace(str, replace=' '):"
68 str = str.replace(replace * 2, replace)
68 str = str.replace(replace * 2, replace)
69 return recursive_replace(str, replace)
69 return recursive_replace(str, replace)
70
70
71
71 def repo_name_slug(value):
72 def repo_name_slug(value):
72 """Return slug of name of repository
73 """Return slug of name of repository
73 This function is called on each creation/modification
74 This function is called on each creation/modification
@@ -83,9 +84,11 b' def repo_name_slug(value):'
83 slug = collapse(slug, '-')
84 slug = collapse(slug, '-')
84 return slug
85 return slug
85
86
87
86 def get_repo_slug(request):
88 def get_repo_slug(request):
87 return request.environ['pylons.routes_dict'].get('repo_name')
89 return request.environ['pylons.routes_dict'].get('repo_name')
88
90
91
89 def action_logger(user, action, repo, ipaddr='', sa=None):
92 def action_logger(user, action, repo, ipaddr='', sa=None):
90 """
93 """
91 Action logger for various actions made by users
94 Action logger for various actions made by users
@@ -113,7 +116,6 b' def action_logger(user, action, repo, ip'
113 else:
116 else:
114 raise Exception('You have to provide user object or username')
117 raise Exception('You have to provide user object or username')
115
118
116
117 rm = RepoModel()
119 rm = RepoModel()
118 if hasattr(repo, 'repo_id'):
120 if hasattr(repo, 'repo_id'):
119 repo_obj = rm.get(repo.repo_id, cache=False)
121 repo_obj = rm.get(repo.repo_id, cache=False)
@@ -124,7 +126,6 b' def action_logger(user, action, repo, ip'
124 else:
126 else:
125 raise Exception('You have to provide repository to action logger')
127 raise Exception('You have to provide repository to action logger')
126
128
127
128 user_log = UserLog()
129 user_log = UserLog()
129 user_log.user_id = user_obj.user_id
130 user_log.user_id = user_obj.user_id
130 user_log.action = action
131 user_log.action = action
@@ -142,6 +143,7 b' def action_logger(user, action, repo, ip'
142 log.error(traceback.format_exc())
143 log.error(traceback.format_exc())
143 sa.rollback()
144 sa.rollback()
144
145
146
145 def get_repos(path, recursive=False):
147 def get_repos(path, recursive=False):
146 """
148 """
147 Scans given path for repos and return (name,(type,path)) tuple
149 Scans given path for repos and return (name,(type,path)) tuple
@@ -178,6 +180,7 b' def get_repos(path, recursive=False):'
178
180
179 return _get_repos(path)
181 return _get_repos(path)
180
182
183
181 def check_repo_fast(repo_name, base_path):
184 def check_repo_fast(repo_name, base_path):
182 """
185 """
183 Check given path for existence of directory
186 Check given path for existence of directory
@@ -186,9 +189,11 b' def check_repo_fast(repo_name, base_path'
186
189
187 :return False: if this directory is present
190 :return False: if this directory is present
188 """
191 """
189 if os.path.isdir(os.path.join(base_path, repo_name)):return False
192 if os.path.isdir(os.path.join(base_path, repo_name)):
193 return False
190 return True
194 return True
191
195
196
192 def check_repo(repo_name, base_path, verify=True):
197 def check_repo(repo_name, base_path, verify=True):
193
198
194 repo_path = os.path.join(base_path, repo_name)
199 repo_path = os.path.join(base_path, repo_name)
@@ -207,13 +212,17 b' def check_repo(repo_name, base_path, ver'
207 log.info('%s repo is free for creation', repo_name)
212 log.info('%s repo is free for creation', repo_name)
208 return True
213 return True
209
214
215
210 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
216 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
211 while True:
217 while True:
212 ok = raw_input(prompt)
218 ok = raw_input(prompt)
213 if ok in ('y', 'ye', 'yes'): return True
219 if ok in ('y', 'ye', 'yes'):
214 if ok in ('n', 'no', 'nop', 'nope'): return False
220 return True
221 if ok in ('n', 'no', 'nop', 'nope'):
222 return False
215 retries = retries - 1
223 retries = retries - 1
216 if retries < 0: raise IOError
224 if retries < 0:
225 raise IOError
217 print complaint
226 print complaint
218
227
219 #propagated from mercurial documentation
228 #propagated from mercurial documentation
@@ -228,6 +237,7 b" ui_sections = ['alias', 'auth',"
228 'server', 'trusted',
237 'server', 'trusted',
229 'ui', 'web', ]
238 'ui', 'web', ]
230
239
240
231 def make_ui(read_from='file', path=None, checkpaths=True):
241 def make_ui(read_from='file', path=None, checkpaths=True):
232 """A function that will read python rc files or database
242 """A function that will read python rc files or database
233 and make an mercurial ui object from read options
243 and make an mercurial ui object from read options
@@ -256,7 +266,6 b" def make_ui(read_from='file', path=None,"
256 log.debug('settings ui from file[%s]%s:%s', section, k, v)
266 log.debug('settings ui from file[%s]%s:%s', section, k, v)
257 baseui.setconfig(section, k, v)
267 baseui.setconfig(section, k, v)
258
268
259
260 elif read_from == 'db':
269 elif read_from == 'db':
261 sa = meta.Session()
270 sa = meta.Session()
262 ret = sa.query(RhodeCodeUi)\
271 ret = sa.query(RhodeCodeUi)\
@@ -285,6 +294,7 b' def set_rhodecode_config(config):'
285 for k, v in hgsettings.items():
294 for k, v in hgsettings.items():
286 config[k] = v
295 config[k] = v
287
296
297
288 def invalidate_cache(cache_key, *args):
298 def invalidate_cache(cache_key, *args):
289 """Puts cache invalidation task into db for
299 """Puts cache invalidation task into db for
290 further global cache invalidation
300 further global cache invalidation
@@ -296,18 +306,20 b' def invalidate_cache(cache_key, *args):'
296 name = cache_key.split('get_repo_cached_')[-1]
306 name = cache_key.split('get_repo_cached_')[-1]
297 ScmModel().mark_for_invalidation(name)
307 ScmModel().mark_for_invalidation(name)
298
308
309
299 class EmptyChangeset(BaseChangeset):
310 class EmptyChangeset(BaseChangeset):
300 """
311 """
301 An dummy empty changeset. It's possible to pass hash when creating
312 An dummy empty changeset. It's possible to pass hash when creating
302 an EmptyChangeset
313 an EmptyChangeset
303 """
314 """
304
315
305 def __init__(self, cs='0' * 40):
316 def __init__(self, cs='0' * 40, repo=None):
306 self._empty_cs = cs
317 self._empty_cs = cs
307 self.revision = -1
318 self.revision = -1
308 self.message = ''
319 self.message = ''
309 self.author = ''
320 self.author = ''
310 self.date = ''
321 self.date = ''
322 self.repository = repo
311
323
312 @LazyProperty
324 @LazyProperty
313 def raw_id(self):
325 def raw_id(self):
@@ -330,6 +342,7 b' class EmptyChangeset(BaseChangeset):'
330 def get_file_size(self, path):
342 def get_file_size(self, path):
331 return 0
343 return 0
332
344
345
333 def map_groups(groups):
346 def map_groups(groups):
334 """Checks for groups existence, and creates groups structures.
347 """Checks for groups existence, and creates groups structures.
335 It returns last group in structure
348 It returns last group in structure
@@ -352,6 +365,7 b' def map_groups(groups):'
352
365
353 return group
366 return group
354
367
368
355 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
369 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
356 """maps all repos given in initial_repo_list, non existing repositories
370 """maps all repos given in initial_repo_list, non existing repositories
357 are created, if remove_obsolete is True it also check for db entries
371 are created, if remove_obsolete is True it also check for db entries
@@ -371,13 +385,13 b' def repo2db_mapper(initial_repo_list, re'
371 log.info('repository %s not found creating default', name)
385 log.info('repository %s not found creating default', name)
372 added.append(name)
386 added.append(name)
373 form_data = {
387 form_data = {
374 'repo_name':name,
388 'repo_name': name,
375 'repo_type':repo.alias,
389 'repo_type': repo.alias,
376 'description':repo.description \
390 'description': repo.description \
377 if repo.description != 'unknown' else \
391 if repo.description != 'unknown' else \
378 '%s repository' % name,
392 '%s repository' % name,
379 'private':False,
393 'private': False,
380 'group_id':getattr(group, 'group_id', None)
394 'group_id': getattr(group, 'group_id', None)
381 }
395 }
382 rm.create(form_data, user, just_db=True)
396 rm.create(form_data, user, just_db=True)
383
397
@@ -391,6 +405,8 b' def repo2db_mapper(initial_repo_list, re'
391 sa.commit()
405 sa.commit()
392
406
393 return added, removed
407 return added, removed
408
409
394 class OrderedDict(dict, DictMixin):
410 class OrderedDict(dict, DictMixin):
395
411
396 def __init__(self, *args, **kwds):
412 def __init__(self, *args, **kwds):
@@ -493,7 +509,7 b' class OrderedDict(dict, DictMixin):'
493
509
494 #set cache regions for beaker so celery can utilise it
510 #set cache regions for beaker so celery can utilise it
495 def add_cache(settings):
511 def add_cache(settings):
496 cache_settings = {'regions':None}
512 cache_settings = {'regions': None}
497 for key in settings.keys():
513 for key in settings.keys():
498 for prefix in ['beaker.cache.', 'cache.']:
514 for prefix in ['beaker.cache.', 'cache.']:
499 if key.startswith(prefix):
515 if key.startswith(prefix):
@@ -518,6 +534,7 b' def add_cache(settings):'
518 'memory')
534 'memory')
519 beaker.cache.cache_regions[region] = region_settings
535 beaker.cache.cache_regions[region] = region_settings
520
536
537
521 def get_current_revision():
538 def get_current_revision():
522 """Returns tuple of (number, id) from repository containing this package
539 """Returns tuple of (number, id) from repository containing this package
523 or None if repository could not be found.
540 or None if repository could not be found.
@@ -537,9 +554,10 b' def get_current_revision():'
537 "was: %s" % err)
554 "was: %s" % err)
538 return None
555 return None
539
556
540 #===============================================================================
557
558 #==============================================================================
541 # TEST FUNCTIONS AND CREATORS
559 # TEST FUNCTIONS AND CREATORS
542 #===============================================================================
560 #==============================================================================
543 def create_test_index(repo_location, full_index):
561 def create_test_index(repo_location, full_index):
544 """Makes default test index
562 """Makes default test index
545 :param repo_location:
563 :param repo_location:
@@ -562,6 +580,7 b' def create_test_index(repo_location, ful'
562 except LockHeld:
580 except LockHeld:
563 pass
581 pass
564
582
583
565 def create_test_env(repos_test_path, config):
584 def create_test_env(repos_test_path, config):
566 """Makes a fresh database and
585 """Makes a fresh database and
567 install test repository into tmp dir
586 install test repository into tmp dir
@@ -582,7 +601,8 b' def create_test_env(repos_test_path, con'
582 ch.setLevel(logging.DEBUG)
601 ch.setLevel(logging.DEBUG)
583
602
584 # create formatter
603 # create formatter
585 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
604 formatter = logging.Formatter("%(asctime)s - %(name)s -"
605 " %(levelname)s - %(message)s")
586
606
587 # add formatter to ch
607 # add formatter to ch
588 ch.setFormatter(formatter)
608 ch.setFormatter(formatter)
@@ -619,10 +639,10 b' def create_test_env(repos_test_path, con'
619 tar.extractall(jn(TESTS_TMP_PATH, HG_REPO))
639 tar.extractall(jn(TESTS_TMP_PATH, HG_REPO))
620 tar.close()
640 tar.close()
621
641
642
622 #==============================================================================
643 #==============================================================================
623 # PASTER COMMANDS
644 # PASTER COMMANDS
624 #==============================================================================
645 #==============================================================================
625
626 class BasePasterCommand(Command):
646 class BasePasterCommand(Command):
627 """
647 """
628 Abstract Base Class for paster commands.
648 Abstract Base Class for paster commands.
@@ -649,7 +669,6 b' class BasePasterCommand(Command):'
649 if log and isinstance(log, logging):
669 if log and isinstance(log, logging):
650 log(msg)
670 log(msg)
651
671
652
653 def run(self, args):
672 def run(self, args):
654 """
673 """
655 Overrides Command.run
674 Overrides Command.run
@@ -21,6 +21,7 b' requirements = ['
21 "celery>=2.2.5",
21 "celery>=2.2.5",
22 "babel",
22 "babel",
23 "python-dateutil>=1.5.0,<2.0.0",
23 "python-dateutil>=1.5.0,<2.0.0",
24 "dulwich>=0.7.0"
24 ]
25 ]
25
26
26 classifiers = ['Development Status :: 4 - Beta',
27 classifiers = ['Development Status :: 4 - Beta',
General Comments 0
You need to be logged in to leave comments. Login now