File: optimize_relink.sh

package info (click to toggle)
darcs 2.18.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,960 kB
  • sloc: haskell: 47,748; sh: 13,466; ansic: 447; perl: 134; makefile: 8
file content (59 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#!/usr/bin/env bash

# For issue600, testing optimize --relink 

. ./lib

## We don't support hard links on Windows.

if echo $OS | grep -i windows; then
    echo darcs does not support hard links on Windows
    exit 0
fi

## compare succeeds if there are hard links
compare () {
  echo 'use File::Basename; $res=0; while ($fn=<'$1'/*>) { $fn2="'$2'/" . basename($fn); @fd1=lstat($fn); @fd2=lstat($fn2); $res += ($fd1[1] != $fd2[1]);}; exit($res);' | perl
}

rm -rf temp
mkdir temp
cd temp

mkdir x
darcs init --repodir x
cd x
date > foo
darcs add foo
darcs record -a -A me -m 'addfoo'
cd ..

## Does the filesystem support hard linking at all?
mkdir z1
echo "hi" > z1/foo
mkdir z2
if ! ln z1/foo z2/foo ; then
  echo No ln command for `pwd` - assuming no hard links.
  exit 0
fi
if ! compare z1 z2 ; then
  echo Filesystem for `pwd` does not support hard links.
  exit 0
fi
# workaround for SunOS cp which does not support `-a' option but also
# doesn't fail when it is encountered.
cp -r x y

## Now try relinking using darcs.
rm -rf z
darcs optimize relink --verbose --repodir x --sibling y
rm -rf x/_darcs/patches/pend* y/_darcs/patches/pend*
if compare x/_darcs/patches y/_darcs/patches
then echo darcs optimize relink is working, hard links were done.
else echo darcs optimize relink is not working, it did not make any hard links.
     exit 2
fi

cd ..
rm -rf temp