summaryrefslogtreecommitdiff
path: root/Git/Remote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-31 15:17:00 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-31 15:26:19 -0400
commita43b7bf71a2369167045ce9ecbddd08276f0e990 (patch)
tree5fe8545a368d7f30837e28dddab083a35310dc29 /Git/Remote.hs
parent8f4726ff9e194d8b5e27b03e45d49de5325b8d1a (diff)
webapp: Generate better git remote names.
Wrote a better git remote name sanitizer. Git blows up on lots of weird stuff, especially if it starts the remote name, but I managed to get some common punctuation working.
Diffstat (limited to 'Git/Remote.hs')
-rw-r--r--Git/Remote.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Git/Remote.hs b/Git/Remote.hs
new file mode 100644
index 000000000..5640e9ff2
--- /dev/null
+++ b/Git/Remote.hs
@@ -0,0 +1,33 @@
+{- git remote stuff
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Git.Remote where
+
+import Common
+import Data.Char
+
+{- Construct a legal git remote name out of an arbitrary input string.
+ -
+ - There seems to be no formal definition of this in the git source,
+ - just some ad-hoc checks, and some other things that fail with certian
+ - types of names (like ones starting with '-').
+ -}
+makeLegalName :: String -> String
+makeLegalName s = case filter legal $ replace "/" "_" s of
+ -- it can't be empty
+ [] -> "unnamed"
+ -- it can't start with / or - or .
+ '.':s' -> makeLegalName s'
+ '/':s' -> makeLegalName s'
+ '-':s' -> makeLegalName s'
+ s' -> s'
+ where
+ {- Only alphanumerics, and a few common bits of punctuation common
+ - in hostnames. -}
+ legal '_' = True
+ legal '.' = True
+ legal c = isAlphaNum c