def handle(c):
    next_pick = rebase_target_tag() + '..'

    cmd = [
        'git', 'log', '--abbrev=12', '--format=%ct %h %s', '--no-merges',
        '--reverse', next_pick
    ]
    commits = subprocess.check_output(cmd, encoding='utf-8', errors='ignore')
    for commit in commits.splitlines():
        if commit != '':
            elem = commit.split(' ', 2)
            timestamp = elem[0]
            sha = elem[1]
            subject = elem[2].rstrip()

            ps = subprocess.Popen(['git', 'show', sha], stdout=subprocess.PIPE)
            spid = subprocess.check_output(['git', 'patch-id'],
                                           stdin=ps.stdout,
                                           encoding='utf-8',
                                           errors='ignore')
            patchid = spid.split(' ', 1)[0]

            c.execute(
                "INSERT INTO commits(committed, sha, patchid, subject) VALUES (?, ?, ?, ?)",
                (timestamp, sha, patchid, subject))
            filenames = subprocess.check_output(
                ['git', 'show', '--name-only', '--format=', sha])
            for fn in filenames.splitlines():
                if fn != "":
                    c.execute("INSERT INTO files(sha, filename) VALUES (?, ?)",
                              (sha, fn))
예제 #2
0
def update_upstreamdb():
    start = rebase_baseline()

    try:
        # see if we previously handled anything. If yes, use it.
        # Otherwise re-create database.
        conn = sqlite3.connect(upstreamdb)
        c = conn.cursor()
        c.execute("select sha from tip")
        sha = c.fetchone()
        conn.close()
        if sha and sha[0] != "":
            start = sha[0]
            # In this case, the baseline may have changed. Assume that it only
            # moves forward. Update database to reflect new baseline.
            update_baseline(c, start, rebase_baseline())
        else:
            fail
    except:
        createdb(upstreamdb, mktables)

    os.chdir(upstream_path)

    upstream_drop = start + '..' + rebase_target_tag()
    upstream_pick = rebase_target_tag() + '..'

    conn = sqlite3.connect(upstreamdb)
    c = conn.cursor()

    handle(c, upstream_drop, 1)
    handle(c, upstream_pick, 0)

    conn.commit()
    conn.close()

    os.chdir(workdir)
예제 #3
0
def init_spreadsheet(sheet):
    try:
        with open(rebase_filename, 'r') as file:
	    id = file.read()
	request = sheet.get(spreadsheetId=id, ranges = [ ], includeGridData=False)
	response = request.execute()
	sheets = response.get('sheets')
	delete_sheets(sheet, id, sheets)
    except:
        id = create_spreadsheet(sheet, 'Rebase %s -> %s' %
				(rebase_baseline(), rebase_target_tag()))
	with open(rebase_filename, 'w') as file:
	    file.write(id)

    return id
예제 #4
0
def handle(c):
  next_pick = rebase_target_tag() + '..'
  commits = subprocess.check_output(['git', 'log', '--oneline', '--no-merges',
                                    next_pick])
  for commit in commits.splitlines():
    if commit != "":
      elem = commit.split(" ", 1)
      sha = elem[0]
      subject = elem[1].rstrip('\n')
      subject = subject.decode('latin-1') \
          if isinstance(subject, str) else subject
      c.execute("INSERT INTO commits(sha, subject, in_baseline) VALUES (?, ?, ?)",
                (sha, subject, 0,))
      filenames = subprocess.check_output(['git', 'show', '--name-only',
                                           '--format=', sha])
      for fn in filenames.splitlines():
        if fn != "":
          c.execute("INSERT INTO files(sha, filename) VALUES (?, ?)", (sha, fn))
예제 #5
0
def main():
    sheet = genlib.init_spreadsheet(
        rebase_filename,
        'Rebase %s -> %s' % (rebase_baseline(), rebase_target_tag()))
    get_other_topic_id()

    requests = []
    create_summary(requests)
    add_topics_sheets(requests)
    genlib.doit(sheet, requests)
    requests = []
    add_commits(requests)
    # Now auto-resize columns A, B, C, and G in Summary sheet
    genlib.resize_sheet(requests, 0, 0, 3)
    genlib.resize_sheet(requests, 0, 6, 7)
    # Add description after resizing
    add_description(requests)
    genlib.doit(sheet, requests)
예제 #6
0
def update_commits():
  '''
  Get complete list of commits from rebase baseline.
  Assume that the baseline branch exists and has been checked out.
  '''

  conn = sqlite3.connect(rebasedb)
  c = conn.cursor()

  os.chdir(chromeos_path)
  commits = subprocess.check_output(['git', 'log', '--no-merges', '--abbrev=12', '--reverse',
                                     '--format=%at%x01%ct%x01%h%x01%an%x01%ae%x01%s',
                                     rebase_baseline() + '..'])

  prevdate = 0
  mprevdate = 0
  for commit in commits.splitlines():
    if commit != "":
      elem = commit.split("\001", 5)
      authored=elem[0]
      committed=elem[1]
      sha = elem[2]
      contact = elem[3]
      email = elem[4]

      if '@google.com' not in email and '@chromium.org' not in email and '@collabora.com' not in email:
          ncontact, nemail = get_contact(sha)
          if ncontact:
              contact = ncontact
              email = nemail

      contact = contact.decode('latin-1') \
                  if isinstance(contact, str) else contact
      email = email.decode('latin-1') \
                  if isinstance(email, str) else email

      subject = elem[5].rstrip('\n')
      subject = subject.decode('latin-1') \
                  if isinstance(subject, str) else subject

      ps = subprocess.Popen(['git', 'show', sha], stdout=subprocess.PIPE)
      spid = subprocess.check_output(['git', 'patch-id'], stdin=ps.stdout)
      patchid = spid.split(" ", 1)[0]

      # Make sure date is unique and in ascending order.
      date = int(committed)
      if date == prevdate:
        date = mprevdate + 1
      else:
        prevdate = date
        date = date * 1000
      mprevdate = date

      # Do nothing if the sha is already in the commit table.
      c.execute("select sha from commits where sha='%s'" % sha)
      found = c.fetchone()
      if found:
        continue

      # check for cherry pick lines. If so, record the upstream SHA associated
      # with this commit. Only look for commits which may be upstream or may
      # have been merged from a stable release.
      usha=""
      if not chromium.match(subject):
        u = upstream.match(subject)
        desc = subprocess.check_output(['git', 'show', '-s', sha])
        for d in desc.splitlines():
          m=None
          if u:
            m = cherrypick.search(d)
          else:
            m = stable.search(d)
            if not m:
              m = stable2.search(d)
          if m:
            usha=m.group(2)[:12]
            # The patch may have been picked multiple times; only record
            # the first entry.
            break

      # Search for embedded Change-Id string.
      # If found, add it to database.
      desc = subprocess.check_output(['git', 'show', '-s', sha])
      for d in desc.decode('latin-1').splitlines():
        chid = changeid.match(d)
        if chid:
          chid = chid.group(1)
          break

      # Initially assume we'll drop everything because it is not listed when
      # running "rebase -i". Before doing that, check if the commit is a
      # stable release commit. If so, mark it accordingly.
      reason = 'upstream'
      c.execute("select sha from stable where sha is '%s'" % sha)
      if c.fetchone():
        reason = 'stable'

      c.execute("INSERT INTO commits(date, created, updated, authored, committed, contact, email, sha, usha, patchid, changeid, subject, disposition, reason) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                (date, NOW(), NOW(), authored, committed, contact, email, sha, usha, patchid, chid, subject, "drop", reason,))
      filenames = subprocess.check_output(['git', 'show', '--name-only',
                                           '--format=', sha])
      for fn in filenames.splitlines():
        if fn != "":
          c.execute("INSERT INTO files(sha, filename) VALUES (?, ?)", (sha, fn,))

  conn.commit()

  # "git cherry -v <target>" on branch rebase_baseline gives us a list
  # of patches to apply.
  patches = subprocess.check_output(['git', 'cherry', '-v', rebase_target_tag()])
  for patch in patches.splitlines():
    elem = patch.split(" ", 2)
    # print "patch: " + patch
    # print "elem[0]: '%s' elem[1]: '%s' elem[2]: '%s'" % (elem[0], elem[1], elem[2])
    if elem[0] == "+":
      # patch not found upstream
      sha = elem[1][:12]
      # Try to find patch in stable branch. If it is there, drop it after all.
      # If not, we may need to apply it.
      c.execute("select sha, origin from stable where sha is '%s'" % sha)
      found = c.fetchone()
      if found:
        c.execute("UPDATE commits SET disposition=('drop') where sha='%s'" % sha)
        c.execute("UPDATE commits SET reason=('%s') where sha='%s'" %
                  (found[1], sha))
        c.execute("UPDATE commits SET updated=('%d') where sha='%s'" % (NOW(), sha))
      else:
        # We need to check if the commit is already marked as drop
        # with a reason other than "upstream". If so, don't update it.
        c.execute("select disposition, reason from commits where sha='%s'" % sha)
        found = c.fetchone()
        if found and found[0] == "drop" and found[1] == "upstream":
          c.execute("UPDATE commits SET disposition=('pick') where sha='%s'" % sha)
          c.execute("UPDATE commits SET reason=('') where sha='%s'" % sha)
          c.execute("UPDATE commits SET updated=('%d') where sha='%s'" % (NOW(), sha))

  os.chdir(workdir)
  conn.commit()
  conn.close()