diff options
author | Ian Clatworthy <ian.clatworthy@canonical.com> | 2010-03-17 11:33:49 +1000 |
---|---|---|
committer | Ian Clatworthy <ian.clatworthy@canonical.com> | 2010-03-17 11:33:49 +1000 |
commit | 514ae4f3b64dba6c98b9337b99bc3a37a0c17c81 (patch) | |
tree | 7b00e96ecfd441a6a6e2165db104fdc25081ed5b | |
parent | 2c3635302c93b77eee34c173f67a338f5f4fd491 (diff) | |
parent | 092724ee5e3091977f84d9f255c8c8ed62082560 (diff) | |
download | bzr-fastimport-514ae4f3b64dba6c98b9337b99bc3a37a0c17c81.tar.gz |
Merge patches from Miklos for darcs-fast-export
-rwxr-xr-x | exporters/darcs/darcs-fast-export | 52 | ||||
-rwxr-xr-x | exporters/darcs/git-darcs | 20 | ||||
-rw-r--r-- | exporters/darcs/git-darcs.txt | 22 |
3 files changed, 58 insertions, 36 deletions
diff --git a/exporters/darcs/darcs-fast-export b/exporters/darcs/darcs-fast-export index 4417bd4..79590a6 100755 --- a/exporters/darcs/darcs-fast-export +++ b/exporters/darcs/darcs-fast-export @@ -47,30 +47,6 @@ class Handler: self.export_marks = [] self.import_marks = [] - def __get_zone(self): - now = time.localtime() - if time.daylight and now[-1]: - offset = time.altzone - else: - offset = time.timezone - hours, minutes = divmod(abs(offset), 3600) - if offset > 0: - sign = "-" - else: - sign = "+" - return sign, hours, minutes - - def get_zone_str(self): - sign, hours, minutes = self.__get_zone() - return "%s%02d%02d" % (sign, hours, minutes // 60) - - def get_zone_int(self): - sign, hours, minutes = self.__get_zone() - ret = hours*3600+minutes*60 - if sign == "-": - ret *= -1 - return ret - def get_patchname(self, patch): ret = [] s = "" @@ -106,12 +82,22 @@ class Handler: author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1] return author.encode('utf-8') - 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 int(time.mktime(date)) + self.get_zone_int() + 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 progress(self, s): print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s) @@ -343,8 +329,8 @@ class Handler: print "mark :%s" % markcount if self.options.export_marks: self.export_marks.append(":%s %s" % (markcount, hash)) - date = self.get_date(i.attributes['date'].value) - print "committer %s %s %s" % (self.get_author(i), date, self.get_zone_str()) + date, zone = self.get_time_info(i.attributes['local_date'].value) + print "committer %s %s %s" % (self.get_author(i), date, zone) print "data %d\n%s" % (len(message), message) if markcount > 1: print "from :%s" % (markcount-1) @@ -368,7 +354,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, self.get_zone_str()) + print "tagger %s %s %s" % (self.get_author(i), date, zone) print "data %d\n%s" % (len(message), message) if count % self.prognum == 0: self.progress("%d/%d patches" % (count, patchnum)) diff --git a/exporters/darcs/git-darcs b/exporters/darcs/git-darcs index 3e7c157..2272cd3 100755 --- a/exporters/darcs/git-darcs +++ b/exporters/darcs/git-darcs @@ -2,7 +2,7 @@ # # git-darcs - bidirectional operation between a darcs repo and git # -# Copyright (c) 2008 by Miklos Vajna <vmiklos@frugalware.org> +# Copyright (c) 2008, 2010 by Miklos Vajna <vmiklos@frugalware.org> # # Based on git-bzr, which is # @@ -48,9 +48,9 @@ add() exit fi git config git-darcs.$name.location $location - git config git-darcs.$name.darcs-fast-export-options "$*" echo "Darcs repo $name added. You can fetch it with 'git darcs fetch $name'" if ! [ -z "$*" ]; then + git config git-darcs.$name.darcs-fast-export-options "$*" echo "darcs-fast-export will get options: $*" fi } @@ -78,6 +78,10 @@ fetch() 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" 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 + $pre_fetch + fi if [ ! -f $git_map -a ! -f $darcs_map ]; then echo "There doesn't seem to be an existing refmap." echo "Doing an initial import" @@ -101,6 +105,10 @@ fetch() echo "One of the mapfiles is missing! Something went wrong!" exit fi + post_fetch="$(git config git-darcs.$remote.post-fetch)" + if [ -n "$post_fetch" ]; then + $post_fetch + fi } pull() @@ -144,6 +152,10 @@ push() echo "We do not have refmapping yet. Then how can I push?" exit fi + pre_push="$(git config git-darcs.$remote.pre-push)" + if [ -n "$pre_push" ]; then + $pre_push + fi echo "Pushing the following updates:" git shortlog darcs/$remote.. git fast-export --import-marks=$git_map --export-marks=$git_map HEAD | \ @@ -151,6 +163,10 @@ push() --logfile $git_dir/darcs-git/push.log) if [ $? == 0 ]; then git update-ref darcs/$remote HEAD + post_push="$(git config git-darcs.$remote.post-push)" + if [ -n "$post_push" ]; then + $post_push + fi fi } diff --git a/exporters/darcs/git-darcs.txt b/exporters/darcs/git-darcs.txt index 7558329..8bf5b33 100644 --- a/exporters/darcs/git-darcs.txt +++ b/exporters/darcs/git-darcs.txt @@ -20,7 +20,7 @@ A typical workflow is: $ mkdir git-repo $ cd git-repo $ git init -$ git darcs add upstream ../darcs-repo +$ git darcs add upstream /path/to/darcs-repo $ git darcs pull upstream ... hack, hack, hack ... @@ -70,3 +70,23 @@ find-darcs:: find-git:: Searches for git commits matching a darcs patch prefix. The syntax is `find-git <patch-prefix>`. + +== HOOKS + +It's possible to automatically run before and after the fetch and the +push subcommand. For example if you want to automatically run `darcs +pull -a` before a `git darcs fetch upstream`: + +---- +git config git-darcs.upstream.pre-fetch "darcs pull -a --repodir=/path/to/darcs-repo" +---- + +Or in case you want to automatically `darcs send` all patches after a +`git darcs push upstream`: + +---- +git config git-darcs.upstream.post-push "darcs send -a --repodir=/path/to/darcs-repo" +---- + +== SEE-ALSO +*git*(1), *darcs*(1) |