// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.reviewdb.client;


/** Constants and utilities for Gerrit-specific ref names. */
public class RefNames {
  public static final String REFS_CHANGES = "refs/changes/";

  /** Note tree listing commits we refuse {@code refs/meta/reject-commits} */
  public static final String REFS_REJECT_COMMITS = "refs/meta/reject-commits";

  /** Configuration settings for a project {@code refs/meta/config} */
  public static final String REFS_CONFIG = "refs/meta/config";

  /** Preference settings for a user {@code refs/users} */
  public static final String REFS_USER = "refs/users/";

  /** Configurations of project-specific dashboards (canned search queries). */
  public static final String REFS_DASHBOARDS = "refs/meta/dashboards/";

  /**
   * Prefix applied to merge commit base nodes.
   * <p>
   * References in this directory should take the form
   * {@code refs/cache-automerge/xx/yyyy...} where xx is
   * the first two digits of the merge commit's object
   * name, and yyyyy... is the remaining 38. The reference
   * should point to a treeish that is the automatic merge
   * result of the merge commit's parents.
   */
  public static final String REFS_CACHE_AUTOMERGE = "refs/cache-automerge/";

  public static final String REFS_DRAFT_PREFIX = "comments-";

  public static String refsUsers(Account.Id accountId) {
    StringBuilder r = new StringBuilder();
    r.append(REFS_USER);
    int account = accountId.get();
    int m = account % 100;
    if (m < 10) {
      r.append('0');
    }
    r.append(m);
    r.append('/');
    r.append(account);
    return r.toString();
  }

  public static String refsDraftComments(Account.Id accountId,
      Change.Id changeId) {
    StringBuilder r = new StringBuilder();
    r.append(refsUsers(accountId));
    r.append('/');
    r.append(REFS_DRAFT_PREFIX);
    r.append(changeId.get());
    return r.toString();
  }

  private RefNames() {
  }
}

@@ -1353,24 +1353,100 @@
 hboards/%22;%0A%0A
+  public static final String REFS_DRAFT_COMMENTS = %22refs/draft-comments/%22;%0A%0A
   /**%0A   * P
@@ -1912,71 +1912,8 @@
 %22;%0A%0A
-  public static final String REFS_DRAFT_PREFIX = %22comments-%22;%0A%0A
   pu
@@ -2380,28 +2380,124 @@
 end(
-refsUsers(accountId)
+REFS_DRAFT_COMMENTS);%0A    int n = accountId.get() %25 100;%0A    if (n %3C 10) %7B%0A      r.append('0');%0A    %7D%0A    r.append(n
 );%0A 
@@ -2531,25 +2531,42 @@
 end(
-REFS_DRAFT_PREFIX
+accountId.get());%0A    r.append('-'
 );%0A 

Resolve issue with naming of drafts ref