{"thread":{"id":"3164","subject":"RFC: Running StGIT in subdirectories","startedAt":"2006-01-27T06:33:14Z","lastAt":"2006-01-27T06:33:14Z","messageCount":1,"participants":["Pavel Roskin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"15162","messageId":"1138343594.1801.32.camel@dv","threadId":"3164","inReplyTo":null,"subject":"RFC: Running StGIT in subdirectories","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-01-27T06:33:14Z","receivedAt":"2006-01-27T06:33:14Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello!\n\nThis was intended as a patch, but I feel it needs to be discussed.\nStGIT, as it stands now, is quite unaware of the fact that the current\ndirectory may not match the top-level directory of the repository.\n\nIt works in most cases because git takes care of the issue, or because\nStGIT is operating on repository wide objects (patches).  But in some\ncases, StGIT fails or produces unexpected results.  My first encounter\nwas \"stg refresh\":\n\n[proski@dv doc]$ stg refresh\nRefreshing patch \"docs\"...error: doc/doc/Makefile: does not exist and --remove not passed\nfatal: Unable to process file doc/Makefile\nstg refresh: Failed git-update-index\n\nWhat's worse is \"stg export\" creating patches that only cover changes\nunder the current directory.  I think the patches should be complete\nunless the user requests otherwise.\n\nFortunately, it seems that most commands are doing the right thing, and\nsome commands are actually useful in subdirectories (e.g. add and rm).\nI think it should be possible to fix the remaining commands or (in cases\nwhen user's expectations are unclear) to disable them in subdirectories,\nat least by default.\n\nHere's the patch for \"stg refresh\".  It also introduces a function to\nget the relative patch of the current directory.\n\nSince the output of git-update-index uses path from the top, the path to\nthe current directory needs to be stripped from it.  I wonder if it's a\nbug in git-update-index, by the way.\n\nI'm a Python beginner.  I think there should be a way to avoid creating\na new list fsrel.  Also, I only want to replace the first occurrence of\nrel_path, and only if it's in the beginning of the filename.  Maybe I\nneed regex for that?  Or maybe slicing would work?\nUntil it's done properly, it's not a 100% correct patch, but it's\nworking for me.\n\n---\n[PATCH] Add support for running \"stg refresh\" in subdirectories.\n\ngit-diff-index uses full path from the top of the repository in all\nfilenames it prints.  The path to the current directory needs to be\nstripped.\n\nOnly files under the current directory will be refreshed.\n---\n\n stgit/git.py |   16 ++++++++++++++--\n 1 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/stgit/git.py b/stgit/git.py\nindex 582e803..045866e 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -90,6 +90,17 @@ def get_base_dir():\n     else:\n         return _output_one_line('git-rev-parse --git-dir')\n \n+__rel_path = None\n+\n+def get_rel_path():\n+    \"\"\"Return path of the current directory relative to the top\n+    \"\"\"\n+    global __rel_path\n+\n+    if not __rel_path:\n+        __rel_path = _output_one_line('git-rev-parse --show-prefix')\n+    return __rel_path\n+\n def get_commit(id_hash):\n     \"\"\"Commit objects factory. Save/look-up them in the __commits\n     dictionary\n@@ -207,8 +218,9 @@ def __tree_status(files = None, tree_id \n     # the rest\n     for line in _output_lines(['git-diff-index', tree_id] + files):\n         fs = tuple(line.rstrip().split(' ',4)[-1].split('\\t',1))\n-        if fs[1] not in conflicts:\n-            cache_files.append(fs)\n+        fsrel = (fs[0], fs[1].replace(get_rel_path(), ''))\n+        if fsrel[1] not in conflicts:\n+            cache_files.append(fsrel)\n \n     return cache_files\n \n\n-- \nRegards,\nPavel Roskin\n"}]}