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
=== modified file 'exporters/darcs/darcs-fast-export'
--- exporters/darcs/darcs-fast-export 2010-03-17 00:14:48 +0000
+++ exporters/darcs/darcs-fast-export 2010-03-27 04:57:19 +0000
@@ -29,6 +29,7 @@
29import sys29import sys
30import gzip30import gzip
31import time31import time
32import calendar
32import shutil33import shutil
33import subprocess34import subprocess
34import optparse35import optparse
@@ -82,22 +83,12 @@
82 author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1]83 author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1]
83 return author.encode('utf-8')84 return author.encode('utf-8')
8485
85 def get_time_info(self, patch):86 def get_date(self, patch):
86 date = time.strptime(patch, "%a %b %d %H:%M:%S %Z %Y")87 try:
87 timestamp = int(time.mktime(date))88 date = time.strptime(patch, "%Y%m%d%H%M%S")
88 # calculate the timezone offset89 except ValueError:
89 fields=re.split('[ ]+', patch)90 date = time.strptime(patch[:19] + patch[-5:], '%a %b %d %H:%M:%S %Y')
90 fields[4]="UTC"91 return calendar.timegm(date)
91 patch_utc=" ".join(fields)
92 date_utc=time.strptime(patch_utc, "%a %b %d %H:%M:%S %Z %Y")
93 offset=int(time.timezone + time.mktime(date) - time.mktime(date_utc))
94 hours, minutes = divmod(abs(offset), 3600)
95 if offset > 0:
96 sign = "-"
97 else:
98 sign = "+"
99 zone = "%s%02d%02d" % (sign, hours, minutes // 60)
100 return timestamp, zone
10192
102 def progress(self, s):93 def progress(self, s):
103 print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s)94 print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s)
@@ -329,8 +320,8 @@
329 print "mark :%s" % markcount320 print "mark :%s" % markcount
330 if self.options.export_marks:321 if self.options.export_marks:
331 self.export_marks.append(":%s %s" % (markcount, hash))322 self.export_marks.append(":%s %s" % (markcount, hash))
332 date, zone = self.get_time_info(i.attributes['local_date'].value)323 date = self.get_date(i.attributes['date'].value)
333 print "committer %s %s %s" % (self.get_author(i), date, zone)324 print "committer %s %s +0000" % (self.get_author(i), date)
334 print "data %d\n%s" % (len(message), message)325 print "data %d\n%s" % (len(message), message)
335 if markcount > 1:326 if markcount > 1:
336 print "from :%s" % (markcount-1)327 print "from :%s" % (markcount-1)
@@ -354,7 +345,7 @@
354 tag = re.sub('[^\xe9-\xf8\w.\-]+', '_', message[4:].strip().split('\n')[0]).strip('_')345 tag = re.sub('[^\xe9-\xf8\w.\-]+', '_', message[4:].strip().split('\n')[0]).strip('_')
355 print "tag %s" % tag346 print "tag %s" % tag
356 print "from :%s" % markcount347 print "from :%s" % markcount
357 print "tagger %s %s %s" % (self.get_author(i), date, zone)348 print "tagger %s %s +0000" % (self.get_author(i), date)
358 print "data %d\n%s" % (len(message), message)349 print "data %d\n%s" % (len(message), message)
359 if count % self.prognum == 0:350 if count % self.prognum == 0:
360 self.progress("%d/%d patches" % (count, patchnum))351 self.progress("%d/%d patches" % (count, patchnum))
361352
=== modified file 'exporters/darcs/git-darcs'
--- exporters/darcs/git-darcs 2010-03-17 00:09:30 +0000
+++ exporters/darcs/git-darcs 2010-03-27 04:57:19 +0000
@@ -32,20 +32,20 @@
32 shift32 shift
33 if ! [ -n "$name" -a -n "$location" ]; then33 if ! [ -n "$name" -a -n "$location" ]; then
34 echo "Usage: git darcs add name location [darcs-fast-export options]"34 echo "Usage: git darcs add name location [darcs-fast-export options]"
35 exit35 return 1
36 fi36 fi
37 if git remote show |grep -q $name; then37 if git remote show |grep -q $name; then
38 echo "There is already a remote with that name"38 echo "There is already a remote with that name"
39 exit39 return 1
40 fi40 fi
41 if [ -n "$(git config git-darcs.$name.location)" ]; then41 if [ -n "$(git config git-darcs.$name.location)" ]; then
42 echo "There is already a darcs repo with that name"42 echo "There is already a darcs repo with that name"
43 exit43 return 1
44 fi44 fi
45 repo=$location/_darcs45 repo=$location/_darcs
46 if [ ! -d $repo ] && ! wget --quiet --spider $repo; then46 if [ ! -d $repo ] && ! wget --quiet --spider $repo; then
47 echo "Remote is not a darcs repository"47 echo "Remote is not a darcs repository"
48 exit48 return 1
49 fi49 fi
50 git config git-darcs.$name.location $location50 git config git-darcs.$name.location $location
51 echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'"51 echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'"
@@ -60,7 +60,7 @@
60 l=$(git config git-darcs.$remote.location)60 l=$(git config git-darcs.$remote.location)
61 if [ -z "$l" ]; then61 if [ -z "$l" ]; then
62 echo "Cannot find darcs remote with name '$remote'." >&262 echo "Cannot find darcs remote with name '$remote'." >&2
63 exit63 return 1
64 fi64 fi
65 echo $l65 echo $l
66}66}
@@ -71,12 +71,12 @@
71 shift71 shift
72 if ! [ -n "$remote" -a -z "$*" ]; then72 if ! [ -n "$remote" -a -z "$*" ]; then
73 echo "Usage: git darcs fetch reponame"73 echo "Usage: git darcs fetch reponame"
74 exit74 return 1
75 fi75 fi
76 location=$(get_location $remote)76 location=$(get_location $remote) || return $?
77 git_map=$git_dir/darcs-git/$remote-git-map77 git_map=$git_dir/darcs-git/$remote-git-map
78 darcs_map=$git_dir/darcs-git/$remote-darcs-map78 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 dfe_opts=$(git config git-darcs.$remote.darcs-fast-export-options)80 dfe_opts=$(git config git-darcs.$remote.darcs-fast-export-options)
81 pre_fetch="$(git config git-darcs.$remote.pre-fetch)"81 pre_fetch="$(git config git-darcs.$remote.pre-fetch)"
82 if [ -n "$pre_fetch" ]; then82 if [ -n "$pre_fetch" ]; then
@@ -90,20 +90,20 @@
90 git fast-import --export-marks=$git_map90 git fast-import --export-marks=$git_map
91 elif [ -f $git_map -a -f $darcs_map ]; then91 elif [ -f $git_map -a -f $darcs_map ]; then
92 echo "Updating remote $remote"92 echo "Updating remote $remote"
93 old_rev=$(git rev-parse darcs/$remote)93 old_rev=$(git rev-parse refs/remotes/darcs/$remote)
94 darcs-fast-export --import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \94 darcs-fast-export --import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \
95 git fast-import --quiet --import-marks=$git_map --export-marks=$git_map95 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 if [ "$old_rev" != "$new_rev" ]; then97 if [ "$old_rev" != "$new_rev" ]; then
98 echo "Fetched the following updates:"98 echo "Fetched the following updates:"
99 git shortlog $old_rev..$new_rev99 git shortlog $old_rev..$new_rev
100 else100 else
101 echo "Nothing fetched."101 echo "Nothing fetched."
102 exit102 return 0
103 fi103 fi
104 else104 else
105 echo "One of the mapfiles is missing! Something went wrong!"105 echo "One of the mapfiles is missing! Something went wrong!"
106 exit106 return 1
107 fi107 fi
108 post_fetch="$(git config git-darcs.$remote.post-fetch)"108 post_fetch="$(git config git-darcs.$remote.post-fetch)"
109 if [ -n "$post_fetch" ]; then109 if [ -n "$post_fetch" ]; then
@@ -117,15 +117,15 @@
117 shift117 shift
118 if ! [ -n "$remote" -a -z "$*" ]; then118 if ! [ -n "$remote" -a -z "$*" ]; then
119 echo "Usage: git darcs pull reponame"119 echo "Usage: git darcs pull reponame"
120 exit120 return 1
121 fi121 fi
122 fetch $remote122 fetch $remote || return $?
123 # see if we need to merge or rebase123 # see if we need to merge or rebase
124 branch=$(git symbolic-ref HEAD|sed 's|.*/||')124 branch=$(git symbolic-ref HEAD|sed 's|.*/||')
125 if [ "$(git config branch.$branch.rebase)" = "true" ]; then125 if [ "$(git config branch.$branch.rebase)" = "true" ]; then
126 git rebase darcs/$remote126 git rebase refs/remotes/darcs/$remote
127 else127 else
128 git merge darcs/$remote128 git merge refs/remotes/darcs/$remote
129 fi129 fi
130}130}
131131
@@ -135,34 +135,34 @@
135 shift135 shift
136 if ! [ -n "$remote" -a -z "$*" ]; then136 if ! [ -n "$remote" -a -z "$*" ]; then
137 echo "Usage: git darcs push reponame"137 echo "Usage: git darcs push reponame"
138 exit138 return 1
139 fi139 fi
140 location=$(get_location $remote)140 location=$(get_location $remote) || return $?
141 if [ -n "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^>/ p')" ]; then141 if [ -n "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^>/ p')" ]; then
142 echo "HEAD is not a strict child of $remote, cannot push. Merge first"142 echo "HEAD is not a strict child of $remote, cannot push. Merge first"
143 exit143 return 1
144 fi144 fi
145 if [ -z "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^</ p')" ]; then145 if [ -z "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^</ p')" ]; then
146 echo "Nothing to push. Commit something first"146 echo "Nothing to push. Commit something first"
147 exit147 return 1
148 fi148 fi
149 git_map=$git_dir/darcs-git/$remote-git-map149 git_map=$git_dir/darcs-git/$remote-git-map
150 darcs_map=$git_dir/darcs-git/$remote-darcs-map150 darcs_map=$git_dir/darcs-git/$remote-darcs-map
151 if [ ! -f $git_map -o ! -f $darcs_map ]; then151 if [ ! -f $git_map -o ! -f $darcs_map ]; then
152 echo "We do not have refmapping yet. Then how can I push?"152 echo "We do not have refmapping yet. Then how can I push?"
153 exit153 return 1
154 fi154 fi
155 pre_push="$(git config git-darcs.$remote.pre-push)"155 pre_push="$(git config git-darcs.$remote.pre-push)"
156 if [ -n "$pre_push" ]; then156 if [ -n "$pre_push" ]; then
157 $pre_push157 $pre_push
158 fi158 fi
159 echo "Pushing the following updates:"159 echo "Pushing the following updates:"
160 git shortlog darcs/$remote..160 git shortlog refs/remotes/darcs/$remote..
161 git fast-export --import-marks=$git_map --export-marks=$git_map HEAD | \161 git fast-export --import-marks=$git_map --export-marks=$git_map HEAD | \
162 (cd $location; darcs-fast-import --import-marks=$darcs_map --export-marks=$darcs_map \162 (cd $location; darcs-fast-import --import-marks=$darcs_map --export-marks=$darcs_map \
163 --logfile $git_dir/darcs-git/push.log)163 --logfile $git_dir/darcs-git/push.log)
164 if [ $? == 0 ]; then164 if [ $? == 0 ]; then
165 git update-ref darcs/$remote HEAD165 git update-ref refs/remotes/darcs/$remote HEAD
166 post_push="$(git config git-darcs.$remote.post-push)"166 post_push="$(git config git-darcs.$remote.post-push)"
167 if [ -n "$post_push" ]; then167 if [ -n "$post_push" ]; then
168 $post_push168 $post_push
@@ -176,18 +176,18 @@
176 if [ -z "$*" ]176 if [ -z "$*" ]
177 then177 then
178 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=.*//p}'178 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=.*//p}'
179 exit179 return 0
180 elif [ "$#" -eq 1 ]180 elif [ "$#" -eq 1 ]
181 then181 then
182 case $1 in182 case $1 in
183 -v|--verbose)183 -v|--verbose)
184 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=/\t/p}'184 git config -l | sed -n -e '/git-darcs\..*/ {s/git-darcs\.//; s/\.location=/\t/p}'
185 exit185 return 0
186 ;;186 ;;
187 esac187 esac
188 fi188 fi
189 echo "Usage: git darcs list [-v|--verbose]"189 echo "Usage: git darcs list [-v|--verbose]"
190 exit 1190 return 1
191}191}
192192
193# Find the darcs commit(s) supporting a git SHA1 prefix193# Find the darcs commit(s) supporting a git SHA1 prefix
@@ -198,9 +198,9 @@
198 if [ -z "$sha1" -o -n "$*" ]198 if [ -z "$sha1" -o -n "$*" ]
199 then199 then
200 echo "Usage: git darcs find-darcs <sha1-prefix>"200 echo "Usage: git darcs find-darcs <sha1-prefix>"
201 exit 1201 return 1
202 fi202 fi
203 for remote in $git_dir/darcs/*203 for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
204 do204 do
205 remote=`basename $remote`205 remote=`basename $remote`
206 git_map=$git_dir/darcs-git/$remote-git-map206 git_map=$git_dir/darcs-git/$remote-git-map
@@ -208,7 +208,7 @@
208 if [ ! -f $git_map -o ! -f $darcs_map ]208 if [ ! -f $git_map -o ! -f $darcs_map ]
209 then209 then
210 echo "Missing mappings for remote $remote"210 echo "Missing mappings for remote $remote"
211 exit 1211 return 1
212 fi212 fi
213 for row in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map`213 for row in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map`
214 do214 do
@@ -225,9 +225,9 @@
225 if [ -z "$patch" -o -n "$*" ]225 if [ -z "$patch" -o -n "$*" ]
226 then226 then
227 echo "Usage: git darcs find-git <patch-prefix>"227 echo "Usage: git darcs find-git <patch-prefix>"
228 exit 1228 return 1
229 fi229 fi
230 for remote in $git_dir/darcs/*230 for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs)
231 do231 do
232 remote=`basename $remote`232 remote=`basename $remote`
233 git_map=$git_dir/darcs-git/$remote-git-map233 git_map=$git_dir/darcs-git/$remote-git-map
@@ -235,7 +235,7 @@
235 if [ ! -f $git_map -o ! -f $darcs_map ]235 if [ ! -f $git_map -o ! -f $darcs_map ]
236 then236 then
237 echo "Missing mappings for remote $remote"237 echo "Missing mappings for remote $remote"
238 exit 1238 return 1
239 fi239 fi
240 for row in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map`240 for row in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map`
241 do241 do
@@ -247,7 +247,7 @@
247git rev-parse 2> /dev/null247git rev-parse 2> /dev/null
248if [ $? != 0 ]; then248if [ $? != 0 ]; then
249 echo "Must be inside a git repository to work"249 echo "Must be inside a git repository to work"
250 exit250 exit 1
251fi251fi
252252
253git_dir=$(git rev-parse --git-dir)253git_dir=$(git rev-parse --git-dir)
@@ -270,7 +270,7 @@
270 *)270 *)
271 echo "Usage: git darcs [COMMAND] [OPTIONS]"271 echo "Usage: git darcs [COMMAND] [OPTIONS]"
272 echo "Commands: add, push, fetch, pull, list, find-darcs, find-git"272 echo "Commands: add, push, fetch, pull, list, find-darcs, find-git"
273 exit273 exit 1
274 ;;274 ;;
275esac275esac
276276

Subscribers

People subscribed via source and target branches