[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-devel] Changelog and relative path
From: |
Sebastian Rose |
Subject: |
[Monotone-devel] Changelog and relative path |
Date: |
Sat, 16 Dec 2006 16:51:38 +0100 |
Hallo everyone,
here is the elisp code, that gets add-changelog-entry to use paths
relative to your projects root directory for changelog entries.
Example
There is a project in /PATH/TO/PROJECT/.
I am editing /PATH/TO/PROJECT/www/includes/functions/general.php
Typing M-x add-change-log-entry RET
RET,
the log file entry looks like this:
---8<-------------------------------------
2006-12-16 sebastian <address@hidden>
* www/includes/functions/general.php(functionname):
------------------------------------->8---
The path www/includes/functions/general.php is the same, no matter
if /PATH/TO/PROJECT/_MTN exists AND you choose /PATH/TO/PROJECT/_MTN/log
as logfile,
or your logfile is /PATH/TO/PROJECT/ChangeLog.
I edited http://venge.net/monotone/wiki/ChangeLog and added the new
function to it, but it's also at the bottom of this message.
To use this function type
M-x customize-variable RET add-log-file-name-function RET
and make it point to mtn-add-log-file-name.
Flaws:
1.) It relies on a local variable in add-log.el, so there is no guaranty
it works or will work in the future. Maintainer of add-log.el is the FSF
and maybee there is a solution I'm overlooking (is that english?), so
this could change.
2.) It always uses the path relative to the parent directory of _MTN if
_MTN exists somewhere up the path, the path relative to directory the
user choosen ChangLog lives in. Not customizable. No problem for me,
since I always use this kind of relative paths in my projects (and don't
understand the discussions about paths here BTW). They identify a file
in a project. Not in a directory, and not on a filesystem.
-----------------------------------------------------------------------
;; You need this one to get the other one to work.
;; Was part of sr-monotone.el, so maybee you use it already.
(defun mtn-get-parent-directory (child)
"Retruns the parent directory or nil, if there is no parent.
Parent has always a trailing slash, or what ever is your systems
file separtor.
Improvements and suggestions to address@hidden"
(if (file-regular-p child)
(file-name-as-directory (file-name-directory child))
; this is else:
(let ((child (file-name-as-directory child)))
(let ((dir (file-name-as-directory (expand-file-name child)))
(parent (file-truename
(file-name-as-directory (expand-file-name (concat
child ".."))))))
(if (string= dir parent)
nil
parent)))))
;; This function is the one you need, to make add-change-log-entry
;; print the path of the file you're writing the change log entry for
;; relative to the root of your project directory.
;; If change-log-default-name is "log", this function assumes the
;; file is part of a monotone project and return the files path
;; relative to "/_MTN/..", just like monotone commands would do.
;; Otherwise returns the path of the file relative to the directory,
;; where the log file lives in.
;;
;; No leading slash prepended.
;;
;; To use this function type
;; M-x customize-variable RET add-log-file-name-function RET
;; and make it point to mtn-add-log-file-name.
;; Unfortunately this function relies on log-file, which is an
;; undocumented variable in add-log.el, actually a local variable
;; in function
;; add-log-file-name (buffer-file log-file).
;; But I couldn't find an other way, to get the logfile, the user has
;; choosen at this point.
(defun mtn-add-log-file-name(original-name)
"Return the filename printed in _MTN/log (or ChangeLog) relative to
the projects root. That is the driectory the file ChangeLog lives in,
if not a monotone project, _MTN/../ otherwise.
Improvements and suggestions to address@hidden"
(let ((directory (mtn-get-parent-directory log-file))
(file (file-truename original-name)))
(if (string= change-log-default-name "log")
;; monotone
(let ((directory (mtn-get-parent-directory directory)))
(file-relative-name file directory))
;; else no monotone:
(file-relative-name file directory))))
----------------------------------------------------------------------------------
--
Sebastian Rose <address@hidden>
- [Monotone-devel] Changelog and relative path,
Sebastian Rose <=