diff --git a/CHANGELOG b/CHANGELOG
index f21a9e8a943de516d3d9b51e0ac9d5f780f2a252..139049774c7c820f9cc2228bc040945a4f05231c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,11 @@
+v 5.2.1
+  - Fix dashboard lost if comment on commit
+  - Update gitlab-grack. Fixes issue with --depth option
+  - Fix project events duplicate on project page
+  - Fix postgres error when displaying network graph.
+  - Fix dashboard event filter when navigate via turbolinks
+  - init.d: Ensure socket is removed before starting service
+
 v 5.2.0
   - Turbolinks
   - Git over http with ldap credentials
diff --git a/Gemfile b/Gemfile
index 2bc55bfa1cd06b9782e622f6e0102bb2f76b7733..633fb8be1ace5ad747877def6ca35c9236f304c4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -26,7 +26,7 @@ gem 'omniauth-github'
 gem 'gitlab_git', '~> 1.2.1'
 
 # Ruby/Rack Git Smart-HTTP Server Handler
-gem 'gitlab-grack', '~> 1.0.0', require: 'grack'
+gem 'gitlab-grack', '~> 1.0.1', require: 'grack'
 
 # LDAP Auth
 gem 'gitlab_omniauth-ldap', '1.0.2', require: "omniauth-ldap"
diff --git a/Gemfile.lock b/Gemfile.lock
index 93798439d8c4deabe670caa928f6b7ff06a1a0e2..53f2a2d308f537008874a393c4976181f3e5d826 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -158,7 +158,7 @@ GEM
       pygments.rb (~> 0.4.2)
       sanitize (~> 2.0.3)
       stringex (~> 1.5.1)
-    gitlab-grack (1.0.0)
+    gitlab-grack (1.0.1)
       rack (~> 1.4.1)
     gitlab-grit (2.5.1)
       charlock_holmes (~> 0.6.9)
@@ -510,7 +510,7 @@ DEPENDENCIES
   github-linguist
   github-markup (~> 0.7.4)
   gitlab-gollum-lib (~> 1.0.0)
-  gitlab-grack (~> 1.0.0)
+  gitlab-grack (~> 1.0.1)
   gitlab-pygments.rb (~> 0.3.2)
   gitlab_git (~> 1.2.1)
   gitlab_meta (= 5.0)
diff --git a/VERSION b/VERSION
index 91ff57278e37ef9cecfeaea47f0d77966799af28..26d99a283f21aa125ccd146e50e76a9b643f54f1 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-5.2.0
+5.2.1
diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee
index 9beca261467603b3966fb03ec77190b2938df301..c2fb95ca6353ef9364f6543a96556e6b64329ada 100644
--- a/app/assets/javascripts/dashboard.js.coffee
+++ b/app/assets/javascripts/dashboard.js.coffee
@@ -27,7 +27,7 @@ class Dashboard
     else
       event_filters.splice index, 1
 
-    $.cookie "event_filter", event_filters.join(",")
+    $.cookie "event_filter", event_filters.join(","), { path: '/' }
 
   initSidebarTab: ->
     key = "dashboard_sidebar_filter"
diff --git a/app/assets/javascripts/pager.js.coffee b/app/assets/javascripts/pager.js.coffee
index 5f606acdf9cc523c8f47eb1a03ca0e58e3d9fc6f..5bd11d273a7fed6a6f09112bbece0aacd99c1a31 100644
--- a/app/assets/javascripts/pager.js.coffee
+++ b/app/assets/javascripts/pager.js.coffee
@@ -30,6 +30,7 @@
       @disable = true
 
   initLoadMore: ->
+    $(document).unbind('scroll')
     $(document).endlessScroll
       bottomPixels: 400
       fireDelay: 1000
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index 7155036eeed99350fc5dda8590b14c9babed4c78..80dcc127e7ee2fa2ac36c44c4c02d01051501af9 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -83,4 +83,12 @@ module EventsHelper
       render "events/event_push", event: event
     end
   end
+
+  def event_note_target_path(event)
+    if event.note? && event.note_commit?
+      project_commit_path(event.project, event.note_target)
+    else
+      url_for([event.project, event.note_target])
+    end
+  end
 end
diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb
index ffec4712e457714f7758b73bec3b97dc69849b2b..da815a859242c94f325e36efd282a4f2ab7da212 100644
--- a/app/models/network/graph.rb
+++ b/app/models/network/graph.rb
@@ -25,7 +25,7 @@ module Network
     def collect_notes
       h = Hash.new(0)
       @project.notes.where('noteable_type = ?' ,"Commit").group('notes.commit_id').select('notes.commit_id, count(notes.id) as note_count').each do |item|
-        h[item["commit_id"]] = item["note_count"]
+        h[item.commit_id] = item.note_count.to_i
       end
       h
     end
diff --git a/app/views/events/event/_note.html.haml b/app/views/events/event/_note.html.haml
index 8bcfa95ff62a7db737d7aa221443e72b1a52f6b0..70289b6566311fed32d413788e9b1ccb98477c81 100644
--- a/app/views/events/event/_note.html.haml
+++ b/app/views/events/event/_note.html.haml
@@ -6,7 +6,7 @@
       = event.note_target_type
       = link_to event.note_short_commit_id, project_commit_path(event.project, event.note_commit_id), class: "commit_short_id"
     - else
-      = link_to [event.project, event.note_target] do
+      = link_to event_note_target_path(event) do
         %strong
           #{event.note_target_type} ##{truncate event.note_target_id}
 
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index b2e9fd8431a17c32e70f02a161f4f7c3514cd6bb..f72ef0a99aef1659ac86ca68281ec7c029629098 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -3,7 +3,7 @@
 .row
   .span9
     = render "events/event_last_push", event: @last_push
-    .content_list= render @events
+    .content_list
     .loading.hide
   .span3
     .light-well
diff --git a/config/initializers/smtp_settings.rb.sample b/config/initializers/smtp_settings.rb.sample
index 333c388f5ff652f9a840bba19c67b615ed12392c..e62ad0f4b7140786303f2496461b4064dfcd1ca8 100644
--- a/config/initializers/smtp_settings.rb.sample
+++ b/config/initializers/smtp_settings.rb.sample
@@ -1,7 +1,7 @@
 # To enable smtp email delivery for your GitLab instance do next: 
 # 1. Change config/environments/production.rb to use smtp
 #    config.action_mailer.delivery_method = :smtp
-# 2. Rename this file to smpt_settings.rb
+# 2. Rename this file to smtp_settings.rb
 # 3. Edit settings inside this file
 # 4. Restart GitLab instance
 #
diff --git a/doc/update/5.1-to-5.2.md b/doc/update/5.1-to-5.2.md
index 8f2116837b8d456551d53a0deb179a93bcd0bafd..3f874555f49a298f8ba4759bbcb5a7e2beee2217 100644
--- a/doc/update/5.1-to-5.2.md
+++ b/doc/update/5.1-to-5.2.md
@@ -1,5 +1,15 @@
 # From 5.1 to 5.2
 
+### 0. Backup
+
+It's useful to make a backup just in case things go south:
+(With MySQL, this may require granting "LOCK TABLES" privileges to the GitLab user on the database version)
+
+```bash
+cd /home/git/gitlab
+sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
+```
+
 ### 1. Stop server
 
     sudo service gitlab stop
@@ -20,14 +30,59 @@ sudo -u git -H git fetch
 sudo -u git -H git checkout v1.4.0
 ```
 
-### 4. Install libs, migrations etc
+### 4. Install libs, migrations, etc.
 
 ```bash
 cd /home/git/gitlab
+
+# MySQL
 sudo -u git -H bundle install --without development test postgres --deployment
+
+#PostgreSQL
+sudo -u git -H bundle install --without development test mysql --deployment
+
 sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
 ```
 
-### 5. Start application
+### 5. Update config files
+
+* Make `/home/git/gitlab/config/gitlab.yml` same as https://github.com/gitlabhq/gitlabhq/blob/5-2-stable/config/gitlab.yml.example but with your settings.
+* Make `/home/git/gitlab/config/puma.rb` same as https://github.com/gitlabhq/gitlabhq/blob/5-2-stable/config/puma.rb.example but with your settings.
+
+### 6. Update Init script
+
+```bash
+sudo rm /etc/init.d/gitlab
+sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/init.d/gitlab
+sudo chmod +x /etc/init.d/gitlab
+```
+
+### 6. Start application
 
     sudo service gitlab start
+    sudo service nginx restart
+
+### 7. Check application status
+
+Check if GitLab and its environment are configured correctly:
+
+    sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
+
+To make sure you didn't miss anything run a more thorough check with:
+
+    sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
+
+If all items are green, then congratulations upgrade complete!
+
+## Things went south? Revert to previous version (5.1)
+
+### 1. Revert the code to the previous version
+Follow the [`upgrade guide from 5.0 to 5.1`](5.0-to-5.1.md), except for the database migration 
+(The backup is already migrated to the previous version)
+
+### 2. Restore from the backup:
+
+```bash
+cd /home/git/gitlab
+sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
+```
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb
index 4f2c86e2d413dcf094ed30b660aef1711b06e9d4..318adbf1894280d934533ce38b095de4a2909e52 100644
--- a/lib/redcarpet/render/gitlab_html.rb
+++ b/lib/redcarpet/render/gitlab_html.rb
@@ -11,7 +11,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
 
   def block_code(code, language)
     options = { options: {encoding: 'utf-8'} }
-    options.merge!(lexer: language.downcase) if Pygments::Lexer.find(language)
+    lexer = Pygments::Lexer.find(language) # language can be an alias
+    options.merge!(lexer: lexer.name.downcase) if lexer # downcase is required
 
     # New lines are placed to fix an rendering issue
     # with code wrapped inside <h1> tag for next case:
diff --git a/lib/support/init.d/gitlab b/lib/support/init.d/gitlab
index 4c5499bbf23a547e8b9931bc935d9616989c8992..f4ca07b36765700583c9a3a58ebb0ea005adc4c3 100644
--- a/lib/support/init.d/gitlab
+++ b/lib/support/init.d/gitlab
@@ -2,7 +2,7 @@
 
 # GITLAB
 # Maintainer: @randx
-# App Version: 5.1
+# App Version: 5.2
 
 ### BEGIN INIT INFO
 # Provides:          gitlab
@@ -19,6 +19,7 @@ APP_ROOT="/home/git/gitlab"
 APP_USER="git"
 DAEMON_OPTS="-C $APP_ROOT/config/puma.rb"
 PID_PATH="$APP_ROOT/tmp/pids"
+SOCKET_PATH="$APP_ROOT/tmp/sockets"
 WEB_SERVER_PID="$PID_PATH/puma.pid"
 SIDEKIQ_PID="$PID_PATH/sidekiq.pid"
 STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop"
@@ -50,6 +51,7 @@ start() {
     exit 1
   else
     if [ `whoami` = root ]; then
+      execute "rm $SOCKET_PATH/gitlab.socket"
       execute "RAILS_ENV=production bundle exec puma $DAEMON_OPTS"
       execute "mkdir -p $PID_PATH && $START_SIDEKIQ  > /dev/null  2>&1 &"
       echo "$DESC started"
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 5e4a74b6260ad9f9a1fa68e89269c9581fd25014..4c3a607a7131dd9d4b322f34688cdf803c7db557 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -144,7 +144,7 @@ namespace :gitlab do
         return
       end
 
-      recipe_content = `curl https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab 2>/dev/null`
+      recipe_content = `curl https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/init.d/gitlab 2>/dev/null`
       script_content = File.read(script_path)
 
       if recipe_content == script_content
@@ -588,7 +588,7 @@ namespace :gitlab do
     def check_sidekiq_running
       print "Running? ... "
 
-      if run_and_match("ps aux | grep -i sidekiq", /sidekiq \d\.\d\.\d.+$/)
+      if run_and_match("ps aux | grep -i sidekiq", /sidekiq \d+\.\d+\.\d+.+$/)
         puts "yes".green
       else
         puts "no".red