Merge lp:~andersk/bzr-fastimport/git-darcs into lp:bzr-fastimport

Proposed by Anders Kaseorg
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 282
Merged at revision: 283
Proposed branch: lp:~andersk/bzr-fastimport/git-darcs
Merge into: lp:bzr-fastimport
Diff against target: 284 lines (+46/-55)
2 files modified
exporters/darcs/darcs-fast-export (+10/-19)
exporters/darcs/git-darcs (+36/-36)
To merge this branch: bzr merge lp:~andersk/bzr-fastimport/git-darcs
Reviewer Review Type Date Requested Status
Miklos Vajna code Pending
Ian Clatworthy Pending
Review via email: mp+22279@code.launchpad.net

Description of the change

Some fixes for git-darcs, including Daniel Herring’s patch from bug 538933.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

The git-darcs changes are fairly simple and seem ok to me.

Miklos, you are a lot more familiar with the darcs exporter code. Any chance you can do a review of that code?

Revision history for this message
Miklos Vajna (vmiklos) wrote :

On Sat, Oct 09, 2010 at 01:31:38PM -0000, Jelmer Vernooij <email address hidden> wrote:
> Miklos, you are a lot more familiar with the darcs exporter code. Any
> chance you can do a review of that code?

Sure, I'll try to review it in the near future. :)

Revision history for this message
Miklos Vajna (vmiklos) wrote :

On Wed, Oct 13, 2010 at 01:49:57AM +0200, Miklos Vajna <email address hidden> wrote:
> Sure, I'll try to review it in the near future. :)

Sorry for being slow, looks good.

Jelmer, please merge it.

Thanks.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks for the review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'exporters/darcs/darcs-fast-export'
2--- exporters/darcs/darcs-fast-export 2010-03-17 00:14:48 +0000
3+++ exporters/darcs/darcs-fast-export 2010-03-27 04:57:19 +0000
4@@ -29,6 +29,7 @@
5 import sys
6 import gzip
7 import time
8+import calendar
9 import shutil
10 import subprocess
11 import optparse
12@@ -82,22 +83,12 @@
13 author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1]
14 return author.encode('utf-8')
15
16- def get_time_info(self, patch):
17- date = time.strptime(patch, "%a %b %d %H:%M:%S %Z %Y")
18- timestamp = int(time.mktime(date))
19- # calculate the timezone offset
20- fields=re.split('[ ]+', patch)
21- fields[4]="UTC"
22- patch_utc=" ".join(fields)
23- date_utc=time.strptime(patch_utc, "%a %b %d %H:%M:%S %Z %Y")
24- offset=int(time.timezone + time.mktime(date) - time.mktime(date_utc))
25- hours, minutes = divmod(abs(offset), 3600)
26- if offset > 0:
27- sign = "-"
28- else:
29- sign = "+"
30- zone = "%s%02d%02d" % (sign, hours, minutes // 60)
31- return timestamp, zone
32+ def get_date(self, patch):
33+ try:
34+ date = time.strptime(patch, "%Y%m%d%H%M%S")
35+ except ValueError:
36+ date = time.strptime(patch[:19] + patch[-5:], '%a %b %d %H:%M:%S %Y')
37+ return calendar.timegm(date)
38
39 def progress(self, s):
40 print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s)
41@@ -329,8 +320,8 @@
42 print "mark :%s" % markcount
43 if self.options.export_marks:
44 self.export_marks.append(":%s %s" % (markcount, hash))
45- date, zone = self.get_time_info(i.attributes['local_date'].value)
46- print "committer %s %s %s" % (self.get_author(i), date, zone)
47+ date = self.get_date(i.attributes['date'].value)
48+ print "committer %s %s +0000" % (self.get_author(i), date)
49 print "data %d\n%s" % (len(message), message)
50 if markcount > 1:
51 print "from :%s" % (markcount-1)
52@@ -354,7 +345,7 @@
53 tag = re.sub('[^\xe9-\xf8\w.\-]+', '_', message[4:].strip().split('\n')[0]).strip('_')
54 print "tag %s" % tag
55 print "from :%s" % markcount
56- print "tagger %s %s %s" % (self.get_author(i), date, zone)
57+ print "tagger %s %s +0000" % (self.get_author(i), date)
58 print "data %d\n%s" % (len(message), message)
59 if count % self.prognum == 0:
60 self.progress("%d/%d patches" % (count, patchnum))
61
62=== modified file 'exporters/darcs/git-darcs'
63--- exporters/darcs/git-darcs 2010-03-17 00:09:30 +0000
64+++ exporters/darcs/git-darcs 2010-03-27 04:57:19 +0000
65@@ -32,20 +32,20 @@
66 shift
67 if ! [ -n "$name" -a -n "$location" ]; then
68 echo "Usage: git darcs add name location [darcs-fast-export options]"
69- exit
70+ return 1
71 fi
72 if git remote show |grep -q $name; then
73 echo "There is already a remote with that name"
74- exit
75+ return 1
76 fi
77 if [ -n "$(git config git-darcs.$name.location)" ]; then
78 echo "There is already a darcs repo with that name"
79- exit
80+ return 1
81 fi
82 repo=$location/_darcs
83 if [ ! -d $repo ] && ! wget --quiet --spider $repo; then
84 echo "Remote is not a darcs repository"
85- exit
86+ return 1
87 fi
88 git config git-darcs.$name.location $location
89 echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'"
90@@ -60,7 +60,7 @@
91 l=$(git config git-darcs.$remote.location)
92 if [ -z "$l" ]; then
93 echo "Cannot find darcs remote with name '$remote'." >&2
94- exit
95+ return 1
96 fi
97 echo $l
98 }
99@@ -71,12 +71,12 @@
100 shift
101 if ! [ -n "$remote" -a -z "$*" ]; then
102 echo "Usage: git darcs fetch reponame"
103- exit
104+ return 1
105 fi
106- location=$(get_location $remote)
107+ location=$(get_location $remote) || return $?
108 git_map=$git_dir/darcs-git/$remote-git-map
109 darcs_map=$git_dir/darcs-git/$remote-darcs-map
110- common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=darcs/$remote"
111+ common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=refs/remotes/darcs/$remote"
112 dfe_opts=$(git config git-darcs.$remote.darcs-fast-export-options)
113 pre_fetch="$(git config git-darcs.$remote.pre-fetch)"
114 if [ -n "$pre_fetch" ]; then
115@@ -90,20 +90,20 @@
116 git fast-import --export-marks=$git_map
117 elif [ -f $git_map -a -f $darcs_map ]; then
118 echo "Updating remote $remote"
119- old_rev=$(git rev-parse darcs/$remote)
120+ old_rev=$(git rev-parse refs/remotes/darcs/$remote)
121 darcs-fast-export --import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \
122 git fast-import --quiet --import-marks=$git_map --export-marks=$git_map
123- new_rev=$(git rev-parse darcs/$remote)
124+ new_rev=$(git rev-parse refs/remotes/darcs/$remote)
125 if [ "$old_rev" != "$new_rev" ]; then
126 echo "Fetched the following updates:"
127 git shortlog $old_rev..$new_rev
128 else
129 echo "Nothing fetched."
130- exit
131+ return 0
132 fi
133 else
134 echo "One of the mapfiles is missing! Something went wrong!"
135- exit
136+ return 1
137 fi
138 post_fetch="$(git config git-darcs.$remote.post-fetch)"
139 if [ -n "$post_fetch" ]; then
140@@ -117,15 +117,15 @@
141 shift
142 if ! [ -n "$remote" -a -z "$*" ]; then
143 echo "Usage: git darcs pull reponame"
144- exit
145+ return 1
146 fi
147- fetch $remote
148+ fetch $remote || return $?
149 # see if we need to merge or rebase
150 branch=$(git symbolic-ref HEAD|sed 's|.*/||')
151 if [ "$(git config branch.$branch.rebase)" = "true" ]; then
152- git rebase darcs/$remote
153+ git rebase refs/remotes/darcs/$remote
154 else
155- git merge darcs/$remote
156+ git merge refs/remotes/darcs/$remote
157 fi
158 }
159
160@@ -135,34 +135,34 @@
161 shift
162 if ! [ -n "$remote" -a -z "$*" ]; then
163 echo "Usage: git darcs push reponame"
164- exit
165+ return 1
166 fi
167- location=$(get_location $remote)
168- if [ -n "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^>/ p')" ]; then
169+ location=$(get_location $remote) || return $?
170+ if [ -n "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^>/ p')" ]; then
171 echo "HEAD is not a strict child of $remote, cannot push. Merge first"
172- exit
173+ return 1
174 fi
175- if [ -z "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^</ p')" ]; then
176+ if [ -z "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^</ p')" ]; then
177 echo "Nothing to push. Commit something first"
178- exit
179+ return 1
180 fi
181 git_map=$git_dir/darcs-git/$remote-git-map
182 darcs_map=$git_dir/darcs-git/$remote-darcs-map
183 if [ ! -f $git_map -o ! -f $darcs_map ]; then
184 echo "We do not have refmapping yet. Then how can I push?"
185- exit
186+ return 1
187 fi
188 pre_push="$(git config git-darcs.$remote.pre-push)"
189 if [ -n "$pre_push" ]; then
190 $pre_push
191 fi
192 echo "Pushing the following updates:"
193- git shortlog darcs/$remote..
194+ git shortlog refs/remotes/darcs/$remote..
195 git fast-export --import-marks=$git_map --export-marks=$git_map HEAD | \
196 (cd $location; darcs-fast-import --import-marks=$darcs_map --export-marks=$darcs_map \
197 --logfile $git_dir/darcs-git/push.log)
198 if [ $? == 0 ]; then
199- git update-ref darcs/$remote HEAD
200+ git update-ref refs/remotes/darcs/$remote HEAD
201 post_push="$(git config git-darcs.$remote.post-push)"
202 if [ -n "$post_push" ]; then
203 $post_push
204@@ -176,18 +176,18 @@
205 if [ -z "$*" ]
206 then
207 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=.*//p}'
208- exit
209+ return 0
210 elif [ "$#" -eq 1 ]
211 then
212 case $1 in
213 -v|--verbose)
214 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=/\t/p}'
215- exit
216+ return 0
217 ;;
218 esac
219 fi
220 echo "Usage: git darcs list [-v|--verbose]"
221- exit 1
222+ return 1
223 }
224
225 # Find the darcs commit(s) supporting a git SHA1 prefix
226@@ -198,9 +198,9 @@
227 if [ -z "$sha1" -o -n "$*" ]
228 then
229 echo "Usage: git darcs find-darcs <sha1-prefix>"
230- exit 1
231+ return 1
232 fi
233- for remote in $git_dir/darcs/*
234+ for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
235 do
236 remote=`basename $remote`
237 git_map=$git_dir/darcs-git/$remote-git-map
238@@ -208,7 +208,7 @@
239 if [ ! -f $git_map -o ! -f $darcs_map ]
240 then
241 echo "Missing mappings for remote $remote"
242- exit 1
243+ return 1
244 fi
245 for row in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map`
246 do
247@@ -225,9 +225,9 @@
248 if [ -z "$patch" -o -n "$*" ]
249 then
250 echo "Usage: git darcs find-git <patch-prefix>"
251- exit 1
252+ return 1
253 fi
254- for remote in $git_dir/darcs/*
255+ for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
256 do
257 remote=`basename $remote`
258 git_map=$git_dir/darcs-git/$remote-git-map
259@@ -235,7 +235,7 @@
260 if [ ! -f $git_map -o ! -f $darcs_map ]
261 then
262 echo "Missing mappings for remote $remote"
263- exit 1
264+ return 1
265 fi
266 for row in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map`
267 do
268@@ -247,7 +247,7 @@
269 git rev-parse 2> /dev/null
270 if [ $? != 0 ]; then
271 echo "Must be inside a git repository to work"
272- exit
273+ exit 1
274 fi
275
276 git_dir=$(git rev-parse --git-dir)
277@@ -270,7 +270,7 @@
278 *)
279 echo "Usage: git darcs [COMMAND] [OPTIONS]"
280 echo "Commands: add, push, fetch, pull, list, find-darcs, find-git"
281- exit
282+ exit 1
283 ;;
284 esac
285

Subscribers

People subscribed via source and target branches