Problem was that I generated an invalid diff. Should instead be using
something like:

        cmd = 'git diff-tree -p --full-index'.split()

On Fri, Aug 6, 2010 at 7:39 PM, Yang Zhang <yanghates...@gmail.com> wrote:
> I'm trying to hack up the below script as a post-receive git hook, but
> the upload step fails with:
>
> ~~~
> $ echo b422f33c8d3a7694ec9f3d4fa88fe5fde7de53f6
> 55e4817884263aa0ce292ebeca2a344a64ef20fa refs/head/master | python
> /tmp/pr.py
> ==> Review Board Login Required
> Enter username and password for Review Board at http://localhost/review/
>>>> Attempting to create review request on /var/git/web.git for None
>>>> Submitting the review request as joe
>>>> HTTP POSTing to http://localhost/review/api/json/reviewrequests/new/: 
>>>> {'repository_path': '/var/git/web.git', 'submit_as': 'joe'}
>>>> Review request created
>>>> Attempting to set field 'target_people' to 'yang' for review request '31'
>>>> HTTP POSTing to 
>>>> http://localhost/review/api/json/reviewrequests/31/draft/set/: 
>>>> {'target_people': 'yang'}
>>>> Uploading diff, size: 1238
>>>> HTTP POSTing to 
>>>> http://localhost/review/api/json/reviewrequests/31/diff/new/: {}
>>>> Got API Error 105 (HTTP code 200): One or more fields had errors
>>>> Error data: {u'fields': {u'path': [u'The diff file is empty']}, u'stat': 
>>>> u'fail', u'err': {u'msg': u'One or more fields had errors', u'code': 105}}
>
> Error uploading diff
>
> The generated diff file was empty. This usually means no files were
> modified in this change.
>
> Try running with --output-diff and --debug for more information.
>
> Your review request still exists, but the diff is not attached.
> ~~~
>
> Adding a print diff shows that it's non-empty (as does the "Uploading
> diff, size: 1238" line above). Any hints? Thanks advance. Below are
> the script and the diff I'm seeing.
>
> ~~~
> #!/usr/bin/env python
>
> from rbtools.postreview import *
> import git, cookielib, urllib2
>
> def get_commits(old_rev, new_rev):
>    p = subprocess.Popen(['git', 'log', '--pretty=format:%H', '--reverse',
>                          '%s..%s' % (old_rev, new_rev)],
>                         stdout=subprocess.PIPE)
>    return p.stdout.read().split('\n')
>
> parse_options(['--username=admin','--password=PASSWORD'])
> info = RepositoryInfo('/var/git/web.git')
> server = ReviewBoardServer('http://localhost/review/', info,
> '/opt/git-helpers/share/cookies')
> server.login()
> repo = git.Repo('.')
>
> for line in sys.stdin:
>    old_rev, new_rev, ref_name = line.split()
>    for chash in get_commits(old_rev, new_rev):
>        c = repo.commit(chash)
>
>        cmd = 'git diff-tree --no-commit-id -p --no-color -c'.split()
>        diff = execute(cmd + [chash])
>
>        author = c.author.email.split('@')[0]
>        target = 'yang' if author == 'joe' else 'joe'
>
>        if author != 'vik' and diff.strip() != '':
>            parse_options([
>                           '--debug',
>                           '--submit-as='+author,
>                           '--target-people='+target])
>
>            review_url = tempt_fate(server, None, None, diff_content=diff,
>                                    parent_diff_content=None, submit_as=author)
> ~~~
>
> The diff:
>
> ~~~
> diff --combined pod/model/__init__.py
> index 4d6a447,eac9c73..01eac8d
> --- a/pod/model/__init__.py
> +++ b/pod/model/__init__.py
> @@@ -291,7 -291,6 +291,7 @@@ mkindexes(TopicUserStats.user_id,  Topi
>  class TopicStats(Base):
>    __tablename__ = 'topic_stats'
>    topic_id = Column(UUID, ForeignKey(Topic.id), primary_key = True)
>  +  domain = Column(String, nullable = False)
>    count = Column(Integer, nullable = False)
>    views = Column(Integer, nullable = False)
>    visitors = Column(Integer, nullable = False)
> @@@ -303,7 -302,6 +303,7 @@@
>  class UserStats(Base):
>    __tablename__ = 'user_stats'
>    user_id = Column(UUID, ForeignKey(User.id), primary_key = True)
>  +  domain = Column(String, nullable = False)
>    count = Column(Integer, nullable = False)
>    views = Column(Integer, nullable = False)
>    visitors = Column(Integer, nullable = False)
> @@@ -337,6 -335,6 +337,8 @@@
>      self.received = self.responses = self.forwarded = self.last_received = 0
>      self.received_auto = self.responses_auto = self.forwarded_auto =
> self.last_received_auto = 0
>      Base.__init__(self, **kwargs)
> ++Index('most_active_by_domain', UserStats.domain, UserStats.count)
> ++
>
>  class CorrespondenceStats(Base):
>    __tablename__ = 'corr_stats'
> ~~~
>
> --
> Yang Zhang
> http://yz.mit.edu/
>



-- 
Yang Zhang
http://yz.mit.edu/

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~----------~----~----~----~------~----~------~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en

Reply via email to