~onehundredthirty/bzr-fastimport/mirroring-only-debian-dir

« back to all changes in this revision

Viewing changes to exporters/darcs/git-darcs

  • Committer: Jelmer Vernooij
  • Date: 2010-07-27 23:55:20 UTC
  • mfrom: (276.1.13 trunk)
  • Revision ID: jelmer@samba.org-20100727235520-1a4hrbknf1dbfsge
Merge fixes from Miklos for darcs fast import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        shift
33
33
        if ! [ -n "$name" -a -n "$location" ]; then
34
34
                echo "Usage: git darcs add name location [darcs-fast-export options]"
35
 
                exit
 
35
                return 1
36
36
        fi
37
37
        if git remote show |grep -q $name; then
38
38
                echo "There is already a remote with that name"
39
 
                exit
 
39
                return 1
40
40
        fi
41
41
        if [ -n "$(git config git-darcs.$name.location)" ]; then
42
42
                echo "There is already a darcs repo with that name"
43
 
                exit
 
43
                return 1
44
44
        fi
45
45
        repo=$location/_darcs
46
46
        if [ ! -d $repo ] && ! wget --quiet --spider $repo; then
47
47
                echo "Remote is not a darcs repository"
48
 
                exit
 
48
                return 1
49
49
        fi
50
50
        git config git-darcs.$name.location $location
51
51
        echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'"
60
60
        l=$(git config git-darcs.$remote.location)
61
61
        if [ -z "$l" ]; then
62
62
                echo "Cannot find darcs remote with name '$remote'." >&2
63
 
                exit
 
63
                return 1
64
64
        fi
65
65
        echo $l
66
66
}
71
71
        shift
72
72
        if ! [ -n "$remote" -a -z "$*" ]; then
73
73
                echo "Usage: git darcs fetch reponame"
74
 
                exit
 
74
                return 1
75
75
        fi
76
 
        location=$(get_location $remote)
 
76
        location=$(get_location $remote) || return $?
77
77
        git_map=$git_dir/darcs-git/$remote-git-map
78
78
        darcs_map=$git_dir/darcs-git/$remote-darcs-map
79
 
        common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=darcs/$remote"
 
79
        common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=refs/remotes/darcs/$remote"
80
80
        dfe_opts=$(git config git-darcs.$remote.darcs-fast-export-options)
81
81
        pre_fetch="$(git config git-darcs.$remote.pre-fetch)"
82
82
        if [ -n "$pre_fetch" ]; then
90
90
                        git fast-import --export-marks=$git_map
91
91
        elif [ -f $git_map -a -f $darcs_map ]; then
92
92
                echo "Updating remote $remote"
93
 
                old_rev=$(git rev-parse darcs/$remote)
 
93
                old_rev=$(git rev-parse refs/remotes/darcs/$remote)
94
94
                darcs-fast-export --import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \
95
95
                        git fast-import --quiet --import-marks=$git_map --export-marks=$git_map
96
 
                new_rev=$(git rev-parse darcs/$remote)
 
96
                new_rev=$(git rev-parse refs/remotes/darcs/$remote)
97
97
                if [ "$old_rev" != "$new_rev" ]; then
98
98
                        echo "Fetched the following updates:"
99
99
                        git shortlog $old_rev..$new_rev
100
100
                else
101
101
                        echo "Nothing fetched."
102
 
                        exit
 
102
                        return 0
103
103
                fi
104
104
        else
105
105
                echo "One of the mapfiles is missing! Something went wrong!"
106
 
                exit
 
106
                return 1
107
107
        fi
108
108
        post_fetch="$(git config git-darcs.$remote.post-fetch)"
109
109
        if [ -n "$post_fetch" ]; then
117
117
        shift
118
118
        if ! [ -n "$remote" -a -z "$*" ]; then
119
119
                echo "Usage: git darcs pull reponame"
120
 
                exit
 
120
                return 1
121
121
        fi
122
 
        fetch $remote
 
122
        fetch $remote || return $?
123
123
        # see if we need to merge or rebase
124
124
        branch=$(git symbolic-ref HEAD|sed 's|.*/||')
125
125
        if [ "$(git config branch.$branch.rebase)" = "true" ]; then
126
 
                git rebase darcs/$remote
 
126
                git rebase refs/remotes/darcs/$remote
127
127
        else
128
 
                git merge darcs/$remote
 
128
                git merge refs/remotes/darcs/$remote
129
129
        fi
130
130
}
131
131
 
135
135
        shift
136
136
        if ! [ -n "$remote" -a -z "$*" ]; then
137
137
                echo "Usage: git darcs push reponame"
138
 
                exit
 
138
                return 1
139
139
        fi
140
 
        location=$(get_location $remote)
141
 
        if [ -n "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^>/ p')" ]; then
 
140
        location=$(get_location $remote) || return $?
 
141
        if [ -n "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^>/ p')" ]; then
142
142
                echo "HEAD is not a strict child of $remote, cannot push. Merge first"
143
 
                exit
 
143
                return 1
144
144
        fi
145
 
        if [ -z "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^</ p')" ]; then
 
145
        if [ -z "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^</ p')" ]; then
146
146
                echo "Nothing to push. Commit something first"
147
 
                exit
 
147
                return 1
148
148
        fi
149
149
        git_map=$git_dir/darcs-git/$remote-git-map
150
150
        darcs_map=$git_dir/darcs-git/$remote-darcs-map
151
151
        if [ ! -f $git_map -o ! -f $darcs_map ]; then
152
152
                echo "We do not have refmapping yet. Then how can I push?"
153
 
                exit
 
153
                return 1
154
154
        fi
155
155
        pre_push="$(git config git-darcs.$remote.pre-push)"
156
156
        if [ -n "$pre_push" ]; then
157
157
                $pre_push
158
158
        fi
159
159
        echo "Pushing the following updates:"
160
 
        git shortlog darcs/$remote..
 
160
        git shortlog refs/remotes/darcs/$remote..
161
161
        git fast-export --import-marks=$git_map --export-marks=$git_map HEAD | \
162
162
                (cd $location; darcs-fast-import --import-marks=$darcs_map --export-marks=$darcs_map \
163
163
                --logfile $git_dir/darcs-git/push.log)
164
164
        if [ $? == 0 ]; then
165
 
                git update-ref darcs/$remote HEAD
 
165
                git update-ref refs/remotes/darcs/$remote HEAD
166
166
                post_push="$(git config git-darcs.$remote.post-push)"
167
167
                if [ -n "$post_push" ]; then
168
168
                        $post_push
176
176
        if [ -z "$*" ]
177
177
        then
178
178
                git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=.*//p}'
179
 
                exit
 
179
                return 0
180
180
        elif [ "$#" -eq 1 ]
181
181
        then
182
182
                case $1 in
183
183
                        -v|--verbose)
184
184
                                git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=/\t/p}'
185
 
                                exit
 
185
                                return 0
186
186
                                ;;
187
187
                esac
188
188
        fi
189
189
        echo "Usage: git darcs list [-v|--verbose]"
190
 
        exit 1
 
190
        return 1
191
191
}
192
192
 
193
193
# Find the darcs commit(s) supporting a git SHA1 prefix
198
198
        if [ -z "$sha1" -o -n "$*" ]
199
199
        then
200
200
                echo "Usage: git darcs find-darcs <sha1-prefix>"
201
 
                exit 1
 
201
                return 1
202
202
        fi
203
 
        for remote in $git_dir/darcs/*
 
203
        for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
204
204
        do
205
205
                remote=`basename $remote`
206
206
                git_map=$git_dir/darcs-git/$remote-git-map
208
208
                if [ ! -f $git_map -o ! -f $darcs_map ]
209
209
                then
210
210
                        echo "Missing mappings for remote $remote"
211
 
                        exit 1
 
211
                        return 1
212
212
                fi
213
213
                for row in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map`
214
214
                do
225
225
        if [ -z "$patch" -o -n "$*" ]
226
226
        then
227
227
                echo "Usage: git darcs find-git <patch-prefix>"
228
 
                exit 1
 
228
                return 1
229
229
        fi
230
 
        for remote in $git_dir/darcs/*
 
230
        for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
231
231
        do
232
232
                remote=`basename $remote`
233
233
                git_map=$git_dir/darcs-git/$remote-git-map
235
235
                if [ ! -f $git_map -o ! -f $darcs_map ]
236
236
                then
237
237
                        echo "Missing mappings for remote $remote"
238
 
                        exit 1
 
238
                        return 1
239
239
                fi
240
240
                for row in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map`
241
241
                do
247
247
git rev-parse 2> /dev/null
248
248
if [ $? != 0 ]; then
249
249
        echo "Must be inside a git repository to work"
250
 
        exit
 
250
        exit 1
251
251
fi
252
252
 
253
253
git_dir=$(git rev-parse --git-dir)
270
270
        *)
271
271
                echo "Usage: git darcs [COMMAND] [OPTIONS]"
272
272
                echo "Commands: add, push, fetch, pull, list, find-darcs, find-git"
273
 
                exit
 
273
                exit 1
274
274
                ;;
275
275
esac
276
276