Tien Jan 19

rbt patch 24

(self, request_id)

(self subclass Command)

{’config’: {u’ALIASES’: {},

            ’BRANCH’: u’master’,

            ’REPOSITORY’: u’testrepo’,

            ’REVIEWBOARD_URL’: u’http://localhost:8080’,

            u’TREES’: {}},

 ’log’: <logging.Logger object at 0x10f503d50>,

 ’options’: Namespace(api_token=None, args=[’24’], commit=False, commit_no_edit=False, debug=False, diff_revision=None, enable_proxy=True, password=None, patch_stdout=False, px=None, repository_name=u’testrepo’, repository_type=None, repository_url=None, server=u’http://localhost:8080’, username=None)}

 

repository_info, tool = self.initialize_scm_tool(client_name=self.options.repository_type)

 

 repository_info: rbtools.clients.RepositoryInfo

 Path: https://github.com/TienSFU25/reviewboard_test.git, Base path: , Supports changesets: False

tool: rbtools.clients.git.GitClient

api_client, api_root = self.get_api(server_url)

api_client: rbtools.api.client.RBClient

api_root: rbtools.api.resource.RootResource (A LOT OF METHODS)

self.setup_tool(tool, api_root=api_root) (not important)

# Check if repository info on reviewboard server match local ones.

repository_info = repository_info.find_server_repository_info(api_root)

(nothing seems to have changed)

diff_body, diff_revision, base_dir = self.get_patch(request_id, api_root, self.options.diff_revision)

self.get_patch(24, api_root, None)

        """Return the diff as a string, the used diff revision and its basedir."""

diffs = api_root.get_diffs(review_request_id=request_id)

DiffListResource

Provides information on a collection of complete diffs.

Each diff contains individual per-file diffs as child resources. A diff is revisioned, and more than one can be associated with any particular review request.

(BASE COMMIT ID IS AT ORIGIN/MASTER. TEST LATER: MOVE ORIGIN/MASTER 1 COMMIT FORWARD - SAME BRANCH/DIFFERENT BRANCH, AND TRY THIS AGAIN)

if diff_revision is None:

            diff_revision = diffs.total_results

(diff_revision = 1)

diff = diffs.get_item(diff_revision)

Provides information on a collection of complete diffs.

Each diff contains individual per-file diffs as child resources. A diff is revisioned, and more than one can be associated with any particular review request.

(THE ONLY DIFF ABOVE)

diff.get_patch() -> ItemResource(?)

diff.get_patch().data

diff --git a/t5 b/t5

new file mode 100644

index 0000000000000000000000000000000000000000..05a0e89f286c36794a17d1c438099807110737b1

--- /dev/null

+++ b/t5

@@ -0,0 +1 @@

+adskf;sajdf;lasdjflkajsdf`

diff --git a/t6 b/t6

new file mode 100644

index 0000000000000000000000000000000000000000..80e4779ea291a7500537ce191ceea506b45b9be4

--- /dev/null

+++ b/t6

@@ -0,0 +1 @@

+random junk

diff --git a/t7 b/t7

new file mode 100644

index 0000000000000000000000000000000000000000..5589fe8ebc0290118156a6f4758a9fee9ca3d48a

--- /dev/null

+++ b/t7

@@ -0,0 +1 @@

+Random text

diff --git a/t8 b/t8

new file mode 100644

index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391

base_dir = getattr(diff, ’basedir’, None) or ’’

getattr(x, ’foobar’) is equivalent to x.foobar

base_dir = ""

tmp_patch_file = make_tempfile(diff_body)

(writes the diff_body to a temp file and store the location in tmp_patch_file)

success = self.apply_patch(repository_info, tool, request_id, diff_revision, tmp_patch_file, base_dir)

self.apply_patch(rbtools.clients.RepositoryInfo, rbtools.clients.git.GitClient, 24, 1, file_location, "")

tool.apply_patch(...)

-> apply_patch(self, patch_file, base_path="", base_dir="", p="")

        """Apply the given patch to index.

        This will take the given patch file and apply it to the index,

        scheduling all changes for commit.

        """

        

cmd = [’git’, ’apply’, ’-3’, (file_location)]

rc, data = self._execute(cmd, with_errors=True, return_error_code=True)      

-> rbtools/rbtools/clients/__init__.py(186)_execute()

-> rbtools/rbtools/utils/process.py(26)execute()

(some other stuff...)

 p = subprocess.Popen(command,.....)

(cool)  

subprocess.call(["ls", "-a"])  

[’git’, ’apply’, ’-3’, ’/var/folders/tk/kjczrb_15wz__jtddz1jfd7r0000gn/T/tmp5wra8T’]

->

data = 

Falling back to three-way merge...

error: t5: does not exist in index

error: cannot read the current contents of ’t5’

error: t5: patch does not apply

Falling back to three-way merge...

Applied patch to ’t6’ cleanly.

Falling back to three-way merge...

Applied patch to ’t7’ cleanly.

Falling back to three-way merge...

Applied patch to ’t8’ cleanly.

return PatchResult(...)

                

(some object that stores the result of the patch command)

(BACK IN PATCH.PY)

        if result.patch_output:

            print()

            print(result.patch_output.strip())

            print()

            

Falling back to three-way merge...

error: t5: does not exist in index

error: cannot read the current contents of ’t5’

error: t5: patch does not apply

Falling back to three-way merge...

Applied patch to ’t6’ cleanly.

(.....)

result:

{’applied’: False,

 ’conflicting_files’: [],

 ’has_conflicts’: False,

 ’patch_output’: u"Falling back to three-way merge...\nerror: t5: does not exist in index\nerror: cannot read the current contents of ’t5’\nerror: t5: patch does not apply\nFalling back to three-way merge...\nApplied patch to ’t6’ cleanly.\nFalling back to three-way merge...\nApplied patch to ’t7’ cleanly.\nFalling back to three-way merge...\nApplied patch to ’t8’ cleanly.\n"}

 

 (LOOK INTO COMMAND ERROR) - pass :|

 

(in review_board_2/rbtools/rbtools/commands/__init__.py, why is self.options a namespace?)

(self.options = parser.parse_args(argv[2:])

(IF -c or -C, commit using the patch and print out some other stuff)

message = extract_commit_message(review_request)

review_request = ReviewRequestResource

review_board_2/rbtools/rbtools/utils/commands.py(58)extract_commit_message() is where the string is being created. land + patch use this

def create_commit(self, message, author, run_editor,

                      files=[], all_files=False):