magit-get-top-dir: fix two issues

* Previously `magit-get-top-dir' didn't do the right thing when passed
  the name of a directory without a trailing slash.  Now it does but
  that comes at the cost of no longer excepting a regular file as
  input.

* Previously `magit-get-top-dir' didn't do the right thing when inside
  the .git directory.  Now it does.
add compatibility function for run-hook-wrapped

This function was introduced in Emacs 24.1
Provide a lisp equivalent.

Tested on Emacs 23.4: allows magit-topgit.el to be used normally

This fixes #1211
magit-{git-dir,get-top-dir}: fix for real

See issues #1201, #1202, #1210, and #1214 - oh boy.

This time around I have actually run some automated tests (but because
they aren't implemented as ert tests I have not yet committed them).
Merge branch 'run-hook-wrapped'
run-hook-wrapped{,-1}: cosmetics
run-hook-wrapped-1: use cl-loop, not loop