diff options
-rwxr-xr-x | exporters/darcs/darcs-fast-import | 27 | ||||
-rw-r--r-- | exporters/darcs/darcs-fast-import.txt | 8 | ||||
-rw-r--r-- | exporters/darcs/t/testimport-gitsymlink.sh | 16 |
3 files changed, 46 insertions, 5 deletions
diff --git a/exporters/darcs/darcs-fast-import b/exporters/darcs/darcs-fast-import index d190204..576c889 100755 --- a/exporters/darcs/darcs-fast-import +++ b/exporters/darcs/darcs-fast-import @@ -4,7 +4,7 @@ darcs-fast-export - darcs backend for fast data exporters - Copyright (c) 2008 Miklos Vajna <vmiklos@frugalware.org> + Copyright (c) 2008, 2009, 2010 Miklos Vajna <vmiklos@frugalware.org> Copyright (c) 2008 Matthias Andree <matthias.andree@gmx.de> This program is free software; you can redistribute it and/or modify @@ -168,6 +168,7 @@ class Handler: self.files.append(path) self.prevfiles = self.files[:] adds = [] + symlinks = [] self.read_next_line() self.handle_mark() @@ -205,13 +206,18 @@ class Handler: self.invoke_add(dest) elif self.line.startswith("M "): items = self.line.split(' ') - if items[1] == "120000": - print "Adding symbolic links (symlinks) is not supported by Darcs." - sys.exit(2) path = items[3][:-1] dir = os.path.split(path)[0] if len(dir) and not os.path.exists(dir): os.makedirs(dir) + if items[1] == "120000": + if not self.options.symhack: + print "Adding symbolic links (symlinks) is not supported by Darcs." + sys.exit(2) + idx = int(items[2][1:]) # TODO: handle inline symlinks + symlinks.append((self.marks[idx], path)) + self.read_next_line() + continue sock = open(path, "w") if items[2] != "inline": idx = int(items[2][1:]) @@ -234,6 +240,16 @@ class Handler: for i in adds: self.invoke_add(i) + for src, path in symlinks: + # symlink does not do what we want if path is + # already there + if os.path.exists(path): + # rmtree() does not work on symlinks + if os.path.islink(path): + os.remove(path) + else: + shutil.rmtree(path) + os.symlink(src, path) sock = subprocess.Popen(["darcs", "record", "--ignore-times", "-a", "--pipe"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) buf = [self.date, self.ident, self.short, self.long] sock.stdin.write("\n".join(buf)) @@ -259,12 +275,15 @@ class Handler: # Option Parser usage="%prog [options]" opp = optparse.OptionParser(usage=usage) + opp.set_defaults(symhack=False) opp.add_option("--import-marks", metavar="IFILE", help="read state for incremental imports from IFILE") opp.add_option("--export-marks", metavar="OFILE", help="write state for incremental imports to OFILE") opp.add_option("--logfile", metavar="L", help="log file which contains the output of external programs invoked during the conversion") + opp.add_option("--symhack", action="store_true", dest="symhack", + help="Do not error out when a symlink would be created, just create it in the workdir") (self.options, args) = opp.parse_args() if self.options.logfile: diff --git a/exporters/darcs/darcs-fast-import.txt b/exporters/darcs/darcs-fast-import.txt index 314b947..9e885bd 100644 --- a/exporters/darcs/darcs-fast-import.txt +++ b/exporters/darcs/darcs-fast-import.txt @@ -34,6 +34,14 @@ as well, via the --import-marks / --export-marks switches. The output of external commands are redirected to a log file. You can specify the path of that file with this parameter. +--symhack:: + Enable hack for symbolic links. darcs add does not handle them + but in case they are just added, we can create them in the working + directory. This can be handy in case for example the symbolic link is in + a subdirectory of the project and you don't even care about that + subdirectory. So the hack can be useful, but be extremely careful when + you use it. + == EXIT CODES The exit code is: diff --git a/exporters/darcs/t/testimport-gitsymlink.sh b/exporters/darcs/t/testimport-gitsymlink.sh index 340a493..100c583 100644 --- a/exporters/darcs/t/testimport-gitsymlink.sh +++ b/exporters/darcs/t/testimport-gitsymlink.sh @@ -27,5 +27,19 @@ cd .. # we *do* want this to fail, but with error code 2. that means that we # detected that symlinks are not supported and the user does not get a # meaningless exception -[ $? = 2 ] +if [ $? != 2 ]; then + exit 1 +fi + +# now try with the symhack option +rm -rf test.darcs +mkdir test.darcs +cd test.darcs +darcs init +cd .. +(cd test; git fast-export --progress=2 HEAD) | (cd test.darcs; darcs-fast-import --symhack) +if [ $? != 0 ]; then + exit 1 +fi +diff_importgit test exit $? |