From 2d6af30ebac3d9d9ec31c93d302712303f4b6966 Mon Sep 17 00:00:00 2001 From: D Herring Date: Wed, 17 Mar 2010 23:14:11 -0400 Subject: fix timezones in darcs-fast-export, take 2 The previous patch had a flaw; it assumed that darcs was storing the committer's timezone. Instead, darcs always stores UTC timestamps in an ISO 8601 format. Tools like "darcs changes" convert this into the user's local time as a convenience. I couldn't find an authoritative spec, but here are some relevant references. http://wiki.darcs.net/NamedPatch http://search.cpan.org/~david/Darcs-Inventory-1.4/lib/Darcs/Inventory/Patch.pm http://bugs.darcs.net/issue140 To resolve the issue, this patch always reports that the timezone is UTC. --- exporters/darcs/darcs-fast-export | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/exporters/darcs/darcs-fast-export b/exporters/darcs/darcs-fast-export index 79590a6..fa850de 100755 --- a/exporters/darcs/darcs-fast-export +++ b/exporters/darcs/darcs-fast-export @@ -29,6 +29,7 @@ import os import sys import gzip import time +import calendar import shutil import subprocess import optparse @@ -82,22 +83,12 @@ class Handler: author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1] return author.encode('utf-8') - def get_time_info(self, patch): - date = time.strptime(patch, "%a %b %d %H:%M:%S %Z %Y") - timestamp = int(time.mktime(date)) - # calculate the timezone offset - fields=re.split('[ ]+', patch) - fields[4]="UTC" - patch_utc=" ".join(fields) - date_utc=time.strptime(patch_utc, "%a %b %d %H:%M:%S %Z %Y") - offset=int(time.timezone + time.mktime(date) - time.mktime(date_utc)) - hours, minutes = divmod(abs(offset), 3600) - if offset > 0: - sign = "-" - else: - sign = "+" - zone = "%s%02d%02d" % (sign, hours, minutes // 60) - return timestamp, zone + def get_date(self, patch): + try: + date = time.strptime(patch, "%Y%m%d%H%M%S") + except ValueError: + date = time.strptime(patch[:19] + patch[-5:], '%a %b %d %H:%M:%S %Y') + return calendar.timegm(date) def progress(self, s): print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s) @@ -329,8 +320,8 @@ class Handler: print "mark :%s" % markcount if self.options.export_marks: self.export_marks.append(":%s %s" % (markcount, hash)) - date, zone = self.get_time_info(i.attributes['local_date'].value) - print "committer %s %s %s" % (self.get_author(i), date, zone) + date = self.get_date(i.attributes['date'].value) + print "committer %s %s +0000" % (self.get_author(i), date) print "data %d\n%s" % (len(message), message) if markcount > 1: print "from :%s" % (markcount-1) @@ -354,7 +345,7 @@ class Handler: tag = re.sub('[^\xe9-\xf8\w.\-]+', '_', message[4:].strip().split('\n')[0]).strip('_') print "tag %s" % tag print "from :%s" % markcount - print "tagger %s %s %s" % (self.get_author(i), date, zone) + print "tagger %s %s +0000" % (self.get_author(i), date) print "data %d\n%s" % (len(message), message) if count % self.prognum == 0: self.progress("%d/%d patches" % (count, patchnum)) -- cgit v1.2.1 From d2e9483e26181389d8a862dd5b02217c1f1fbc56 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Mar 2010 00:36:55 -0400 Subject: git-darcs: Import to a real ref (refs/remotes/darcs/$remote). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the imported darcs branch to be seen by tools like ‘git branch -r’ and ‘gitk --all’, and prevents the imported commits from being garbage-collected. --- exporters/darcs/git-darcs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/exporters/darcs/git-darcs b/exporters/darcs/git-darcs index 2272cd3..03c2ec1 100755 --- a/exporters/darcs/git-darcs +++ b/exporters/darcs/git-darcs @@ -76,7 +76,7 @@ fetch() location=$(get_location $remote) git_map=$git_dir/darcs-git/$remote-git-map darcs_map=$git_dir/darcs-git/$remote-darcs-map - common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=darcs/$remote" + common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=refs/remotes/darcs/$remote" dfe_opts=$(git config git-darcs.$remote.darcs-fast-export-options) pre_fetch="$(git config git-darcs.$remote.pre-fetch)" if [ -n "$pre_fetch" ]; then @@ -90,10 +90,10 @@ fetch() git fast-import --export-marks=$git_map elif [ -f $git_map -a -f $darcs_map ]; then echo "Updating remote $remote" - old_rev=$(git rev-parse darcs/$remote) + old_rev=$(git rev-parse refs/remotes/darcs/$remote) darcs-fast-export --import-marks=$darcs_map --export-marks=$darcs_map $common_opts $dfe_opts $location | \ git fast-import --quiet --import-marks=$git_map --export-marks=$git_map - new_rev=$(git rev-parse darcs/$remote) + new_rev=$(git rev-parse refs/remotes/darcs/$remote) if [ "$old_rev" != "$new_rev" ]; then echo "Fetched the following updates:" git shortlog $old_rev..$new_rev @@ -123,9 +123,9 @@ pull() # see if we need to merge or rebase branch=$(git symbolic-ref HEAD|sed 's|.*/||') if [ "$(git config branch.$branch.rebase)" = "true" ]; then - git rebase darcs/$remote + git rebase refs/remotes/darcs/$remote else - git merge darcs/$remote + git merge refs/remotes/darcs/$remote fi } @@ -138,11 +138,11 @@ push() exit fi location=$(get_location $remote) - if [ -n "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^>/ p')" ]; then + if [ -n "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^>/ p')" ]; then echo "HEAD is not a strict child of $remote, cannot push. Merge first" exit fi - if [ -z "$(git rev-list --left-right HEAD...darcs/$remote | sed -n '/^" exit 1 fi - for remote in $git_dir/darcs/* + for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs) do remote=`basename $remote` git_map=$git_dir/darcs-git/$remote-git-map @@ -227,7 +227,7 @@ find_git() echo "Usage: git darcs find-git " exit 1 fi - for remote in $git_dir/darcs/* + for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs) do remote=`basename $remote` git_map=$git_dir/darcs-git/$remote-git-map -- cgit v1.2.1 From 0c1f1fc2151197d0beb7adb15b40007fd564cf99 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Mar 2010 00:47:22 -0400 Subject: git-darcs: Fix exit/return confusion. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shell functions should return instead of exiting the whole script; they should return a nonzero status on error and a zero status on success. Notably, “Nothing fetched” is not an error, and pull should go ahead and do a merge or rebase even if fetch didn’t fetch anything. --- exporters/darcs/git-darcs | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/exporters/darcs/git-darcs b/exporters/darcs/git-darcs index 03c2ec1..18455a2 100755 --- a/exporters/darcs/git-darcs +++ b/exporters/darcs/git-darcs @@ -32,20 +32,20 @@ add() shift if ! [ -n "$name" -a -n "$location" ]; then echo "Usage: git darcs add name location [darcs-fast-export options]" - exit + return 1 fi if git remote show |grep -q $name; then echo "There is already a remote with that name" - exit + return 1 fi if [ -n "$(git config git-darcs.$name.location)" ]; then echo "There is already a darcs repo with that name" - exit + return 1 fi repo=$location/_darcs if [ ! -d $repo ] && ! wget --quiet --spider $repo; then echo "Remote is not a darcs repository" - exit + return 1 fi git config git-darcs.$name.location $location echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'" @@ -60,7 +60,7 @@ get_location() l=$(git config git-darcs.$remote.location) if [ -z "$l" ]; then echo "Cannot find darcs remote with name '$remote'." >&2 - exit + return 1 fi echo $l } @@ -71,9 +71,9 @@ fetch() shift if ! [ -n "$remote" -a -z "$*" ]; then echo "Usage: git darcs fetch reponame" - exit + return 1 fi - location=$(get_location $remote) + location=$(get_location $remote) || return $? git_map=$git_dir/darcs-git/$remote-git-map darcs_map=$git_dir/darcs-git/$remote-darcs-map common_opts="--working $git_dir/darcs-git/repo --logfile $git_dir/darcs-git/fetch.log --git-branch=refs/remotes/darcs/$remote" @@ -99,11 +99,11 @@ fetch() git shortlog $old_rev..$new_rev else echo "Nothing fetched." - exit + return 0 fi else echo "One of the mapfiles is missing! Something went wrong!" - exit + return 1 fi post_fetch="$(git config git-darcs.$remote.post-fetch)" if [ -n "$post_fetch" ]; then @@ -117,9 +117,9 @@ pull() shift if ! [ -n "$remote" -a -z "$*" ]; then echo "Usage: git darcs pull reponame" - exit + return 1 fi - fetch $remote + fetch $remote || return $? # see if we need to merge or rebase branch=$(git symbolic-ref HEAD|sed 's|.*/||') if [ "$(git config branch.$branch.rebase)" = "true" ]; then @@ -135,22 +135,22 @@ push() shift if ! [ -n "$remote" -a -z "$*" ]; then echo "Usage: git darcs push reponame" - exit + return 1 fi - location=$(get_location $remote) + location=$(get_location $remote) || return $? if [ -n "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^>/ p')" ]; then echo "HEAD is not a strict child of $remote, cannot push. Merge first" - exit + return 1 fi if [ -z "$(git rev-list --left-right HEAD...refs/remotes/darcs/$remote | sed -n '/^" - exit 1 + return 1 fi for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs) do @@ -208,7 +208,7 @@ find_darcs() if [ ! -f $git_map -o ! -f $darcs_map ] then echo "Missing mappings for remote $remote" - exit 1 + return 1 fi for row in `sed -n -e "/:.* $sha1.*/ s/[^ ]*/&/p" $git_map` do @@ -225,7 +225,7 @@ find_git() if [ -z "$patch" -o -n "$*" ] then echo "Usage: git darcs find-git " - exit 1 + return 1 fi for remote in $(git for-each-ref --format='%(refname)' refs/remotes/darcs) do @@ -235,7 +235,7 @@ find_git() if [ ! -f $git_map -o ! -f $darcs_map ] then echo "Missing mappings for remote $remote" - exit 1 + return 1 fi for row in `sed -n -e "/:.* $patch.*/ s/[^ ]*/&/p" $darcs_map` do @@ -247,7 +247,7 @@ find_git() git rev-parse 2> /dev/null if [ $? != 0 ]; then echo "Must be inside a git repository to work" - exit + exit 1 fi git_dir=$(git rev-parse --git-dir) @@ -270,7 +270,7 @@ case $command in *) echo "Usage: git darcs [COMMAND] [OPTIONS]" echo "Commands: add, push, fetch, pull, list, find-darcs, find-git" - exit + exit 1 ;; esac -- cgit v1.2.1