[git-log] escape backslashes (otherwise git doesn't like it)

(cherry picked from commit 7eea76acd45f7000c8948ab8c8223b382f2525b9)
[log] IDEA-120178 Check if branch exists before querying Git or Hg

Otherwise both Git and Hg fail with an error "such branch doesn't exist"

(cherry picked from commit 802a696ad7ecb185a2e7fb35491f08481ab6b506)
[hg log] Fix after cherry-pick: use older HgRepository API not moved to 133 yet.