# HG changeset patch # User Marcin Kuzminski # Date 1302159671 -7200 # Node ID e76833cd555a2e2e6faf75de91c829454d8aaac9 # Parent f7b24987d5fb236be774de46230cef7b11fb3aa6 files: fixes error when passing a diff without parameters and caused server crash adde dulwich dep, to rhodecode to make sure it is installed diff -r f7b24987d5fb -r e76833cd555a rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py Wed Apr 06 20:35:50 2011 +0200 +++ b/rhodecode/controllers/files.py Thu Apr 07 09:01:11 2011 +0200 @@ -98,7 +98,7 @@ #reditect to given revision from form if given post_revision = request.POST.get('at_rev', None) if post_revision: - cs = self.__get_cs_or_redirect(revision, repo_name) + cs = self.__get_cs_or_redirect(post_revision, repo_name) redirect(url('files_home', repo_name=c.repo_name, revision=cs.raw_id, f_path=f_path)) @@ -213,14 +213,14 @@ c.changeset_1 = c.rhodecode_repo.get_changeset(diff1) node1 = c.changeset_1.get_node(f_path) else: - c.changeset_1 = EmptyChangeset() + c.changeset_1 = EmptyChangeset(repo=c.rhodecode_repo) node1 = FileNode('.', '', changeset=c.changeset_1) if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]: c.changeset_2 = c.rhodecode_repo.get_changeset(diff2) node2 = c.changeset_2.get_node(f_path) else: - c.changeset_2 = EmptyChangeset() + c.changeset_2 = EmptyChangeset(repo=c.rhodecode_repo) node2 = FileNode('.', '', changeset=c.changeset_2) except RepositoryError: return redirect(url('files_home', diff -r f7b24987d5fb -r e76833cd555a rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py Wed Apr 06 20:35:50 2011 +0200 +++ b/rhodecode/lib/utils.py Thu Apr 07 09:01:11 2011 +0200 @@ -68,6 +68,7 @@ str = str.replace(replace * 2, replace) return recursive_replace(str, replace) + def repo_name_slug(value): """Return slug of name of repository This function is called on each creation/modification @@ -83,9 +84,11 @@ slug = collapse(slug, '-') return slug + def get_repo_slug(request): return request.environ['pylons.routes_dict'].get('repo_name') + def action_logger(user, action, repo, ipaddr='', sa=None): """ Action logger for various actions made by users @@ -113,7 +116,6 @@ else: raise Exception('You have to provide user object or username') - rm = RepoModel() if hasattr(repo, 'repo_id'): repo_obj = rm.get(repo.repo_id, cache=False) @@ -124,7 +126,6 @@ else: raise Exception('You have to provide repository to action logger') - user_log = UserLog() user_log.user_id = user_obj.user_id user_log.action = action @@ -142,6 +143,7 @@ log.error(traceback.format_exc()) sa.rollback() + def get_repos(path, recursive=False): """ Scans given path for repos and return (name,(type,path)) tuple @@ -178,6 +180,7 @@ return _get_repos(path) + def check_repo_fast(repo_name, base_path): """ Check given path for existence of directory @@ -186,9 +189,11 @@ :return False: if this directory is present """ - if os.path.isdir(os.path.join(base_path, repo_name)):return False + if os.path.isdir(os.path.join(base_path, repo_name)): + return False return True + def check_repo(repo_name, base_path, verify=True): repo_path = os.path.join(base_path, repo_name) @@ -207,13 +212,17 @@ log.info('%s repo is free for creation', repo_name) return True + def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): while True: ok = raw_input(prompt) - if ok in ('y', 'ye', 'yes'): return True - if ok in ('n', 'no', 'nop', 'nope'): return False + if ok in ('y', 'ye', 'yes'): + return True + if ok in ('n', 'no', 'nop', 'nope'): + return False retries = retries - 1 - if retries < 0: raise IOError + if retries < 0: + raise IOError print complaint #propagated from mercurial documentation @@ -228,6 +237,7 @@ 'server', 'trusted', 'ui', 'web', ] + def make_ui(read_from='file', path=None, checkpaths=True): """A function that will read python rc files or database and make an mercurial ui object from read options @@ -256,7 +266,6 @@ log.debug('settings ui from file[%s]%s:%s', section, k, v) baseui.setconfig(section, k, v) - elif read_from == 'db': sa = meta.Session() ret = sa.query(RhodeCodeUi)\ @@ -285,6 +294,7 @@ for k, v in hgsettings.items(): config[k] = v + def invalidate_cache(cache_key, *args): """Puts cache invalidation task into db for further global cache invalidation @@ -296,18 +306,20 @@ name = cache_key.split('get_repo_cached_')[-1] ScmModel().mark_for_invalidation(name) + class EmptyChangeset(BaseChangeset): """ An dummy empty changeset. It's possible to pass hash when creating an EmptyChangeset """ - def __init__(self, cs='0' * 40): + def __init__(self, cs='0' * 40, repo=None): self._empty_cs = cs self.revision = -1 self.message = '' self.author = '' self.date = '' + self.repository = repo @LazyProperty def raw_id(self): @@ -330,6 +342,7 @@ def get_file_size(self, path): return 0 + def map_groups(groups): """Checks for groups existence, and creates groups structures. It returns last group in structure @@ -352,6 +365,7 @@ return group + def repo2db_mapper(initial_repo_list, remove_obsolete=False): """maps all repos given in initial_repo_list, non existing repositories are created, if remove_obsolete is True it also check for db entries @@ -371,13 +385,13 @@ log.info('repository %s not found creating default', name) added.append(name) form_data = { - 'repo_name':name, - 'repo_type':repo.alias, - 'description':repo.description \ + 'repo_name': name, + 'repo_type': repo.alias, + 'description': repo.description \ if repo.description != 'unknown' else \ '%s repository' % name, - 'private':False, - 'group_id':getattr(group, 'group_id', None) + 'private': False, + 'group_id': getattr(group, 'group_id', None) } rm.create(form_data, user, just_db=True) @@ -391,6 +405,8 @@ sa.commit() return added, removed + + class OrderedDict(dict, DictMixin): def __init__(self, *args, **kwds): @@ -493,7 +509,7 @@ #set cache regions for beaker so celery can utilise it def add_cache(settings): - cache_settings = {'regions':None} + cache_settings = {'regions': None} for key in settings.keys(): for prefix in ['beaker.cache.', 'cache.']: if key.startswith(prefix): @@ -518,6 +534,7 @@ 'memory') beaker.cache.cache_regions[region] = region_settings + def get_current_revision(): """Returns tuple of (number, id) from repository containing this package or None if repository could not be found. @@ -537,9 +554,10 @@ "was: %s" % err) return None -#=============================================================================== + +#============================================================================== # TEST FUNCTIONS AND CREATORS -#=============================================================================== +#============================================================================== def create_test_index(repo_location, full_index): """Makes default test index :param repo_location: @@ -562,6 +580,7 @@ except LockHeld: pass + def create_test_env(repos_test_path, config): """Makes a fresh database and install test repository into tmp dir @@ -582,7 +601,8 @@ ch.setLevel(logging.DEBUG) # create formatter - formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + formatter = logging.Formatter("%(asctime)s - %(name)s -" + " %(levelname)s - %(message)s") # add formatter to ch ch.setFormatter(formatter) @@ -619,10 +639,10 @@ tar.extractall(jn(TESTS_TMP_PATH, HG_REPO)) tar.close() + #============================================================================== # PASTER COMMANDS #============================================================================== - class BasePasterCommand(Command): """ Abstract Base Class for paster commands. @@ -649,7 +669,6 @@ if log and isinstance(log, logging): log(msg) - def run(self, args): """ Overrides Command.run diff -r f7b24987d5fb -r e76833cd555a setup.py --- a/setup.py Wed Apr 06 20:35:50 2011 +0200 +++ b/setup.py Thu Apr 07 09:01:11 2011 +0200 @@ -21,6 +21,7 @@ "celery>=2.2.5", "babel", "python-dateutil>=1.5.0,<2.0.0", + "dulwich>=0.7.0" ] classifiers = ['Development Status :: 4 - Beta',